]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
acc25f13c5b6938ba72326eaa8ebd83bb292f5a8
[tmp/jakarta-migration.git] /
1 /**
2  * This document is a part of the source code and related artifacts
3  * for CollectionSpace, an open source collections management system
4  * for museums and related institutions:
5  *
6  * http://www.collectionspace.org
7  * http://wiki.collectionspace.org
8  *
9  * Copyright © 2009 Regents of the University of California
10  *
11  * Licensed under the Educational Community License (ECL), Version 2.0.
12  * You may not use this file except in compliance with this License.
13  *
14  * You may obtain a copy of the ECL 2.0 License at
15  * https://source.collectionspace.org/collection-space/LICENSE.txt
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 package org.collectionspace.services.client.test;
24
25
26 import javax.ws.rs.core.Response;
27
28 import org.collectionspace.services.client.CollectionSpaceClient;
29 import org.collectionspace.services.client.PayloadOutputPart;
30 import org.collectionspace.services.client.PoxPayloadIn;
31 import org.collectionspace.services.client.PoxPayloadOut;
32
33 import org.collectionspace.services.jaxb.AbstractCommonList;
34 import org.collectionspace.services.workflow.WorkflowCommon;
35 import org.collectionspace.services.client.DimensionClient;
36 import org.collectionspace.services.client.workflow.WorkflowClient;
37 import org.collectionspace.services.dimension.DimensionsCommon;
38
39 import org.jboss.resteasy.client.ClientResponse;
40
41 import org.testng.Assert;
42 import org.testng.annotations.Test;
43
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47 /**
48  * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service. <p/>
49  * $LastChangedRevision:  $
50  * $LastChangedDate:  $
51  */
52 public class WorkflowServiceTest extends AbstractServiceTestImpl {
53
54     private final String CLASS_NAME = WorkflowServiceTest.class.getName();
55     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
56     private String knownResourceId = null;
57
58     @Override
59         public String getServicePathComponent() {
60                 return WorkflowClient.SERVICE_PATH_COMPONENT;
61         }
62
63         @Override
64         protected String getServiceName() {
65                 return WorkflowClient.SERVICE_NAME;
66         }
67     
68     @Override
69     protected CollectionSpaceClient getClientInstance() {
70         return new DimensionClient();
71     }
72
73     @Override
74     protected AbstractCommonList getAbstractCommonList(ClientResponse<AbstractCommonList> response) {
75         return response.getEntity(AbstractCommonList.class);
76     }
77
78     @Override
79     public void createList(String testName) throws Exception {
80         //empty N/A
81     }
82
83     @Override
84     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
85     public void read(String testName) throws Exception {
86         logger.debug(testBanner(testName, CLASS_NAME));
87         setupRead();
88         DimensionClient client = new DimensionClient();
89         ClientResponse<String> res = client.getWorkflow(knownResourceId);
90         assertStatusCode(res, testName);
91         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
92         WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
93         if (logger.isDebugEnabled() == true) {
94                 logger.debug("Workflow payload is: " + input.getXmlPayload());
95         }
96         Assert.assertNotNull(workflowsCommon);
97     }
98
99 //    @Override
100 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"})
101 //    public void readList(String testName) throws Exception {
102 //        logger.debug(testBanner(testName, CLASS_NAME));
103 //        setupReadList();
104 //        WorkflowClient client = new WorkflowClient();
105 //        ClientResponse<AbstractCommonList> res = client.readList();
106 //        AbstractCommonList list = res.getEntity();
107 //        assertStatusCode(res, testName);
108 //        if (logger.isDebugEnabled()) {
109 //            List<AbstractCommonList.ListItem> items =
110 //                list.getListItem();
111 //            int i = 0;
112 //            for(AbstractCommonList.ListItem item : items){
113 //                logger.debug(testName + ": list-item[" + i + "] " +
114 //                        item.toString());
115 //                i++;
116 //            }
117 //        }
118 //    }
119     
120     @Override
121     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
122     public void update(String testName) throws Exception {
123         logger.debug(testBanner(testName, CLASS_NAME));
124         setupUpdate();
125         updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWSTATE_APPROVED);
126     }    
127
128
129     @Override
130 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"})
131     public void updateNonExistent(String testName) throws Exception {
132         logger.debug(testBanner(testName, CLASS_NAME));
133         setupUpdateNonExistent();
134         // Submit the request to the service and store the response.
135         // Note: The ID used in this 'create' call may be arbitrary.
136         // The only relevant ID may be the one used in update(), below.
137         WorkflowClient client = new WorkflowClient();
138         PoxPayloadOut multipart = createDimensionInstance(NON_EXISTENT_ID);
139         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
140         assertStatusCode(res, testName);
141     }
142
143     @Override
144 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
145     public void delete(String testName) throws Exception {
146         logger.debug(testBanner(testName, CLASS_NAME));
147         setupDelete();
148         WorkflowClient client = new WorkflowClient();
149         ClientResponse<Response> res = client.delete(knownResourceId);
150         assertStatusCode(res, testName);
151     }
152
153     // ---------------------------------------------------------------
154     // Failure outcome tests : means we expect response to fail, but test to succeed
155     // ---------------------------------------------------------------
156
157     // Failure outcome
158     @Override
159 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
160     public void readNonExistent(String testName) throws Exception {
161         logger.debug(testBanner(testName, CLASS_NAME));
162         setupReadNonExistent();
163         WorkflowClient client = new WorkflowClient();
164         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
165         assertStatusCode(res, testName);
166     }
167
168     // Failure outcome
169     @Override
170 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"})
171     public void deleteNonExistent(String testName) throws Exception {
172         logger.debug(testBanner(testName, CLASS_NAME));
173         setupDeleteNonExistent();
174         WorkflowClient client = new WorkflowClient();
175         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
176         assertStatusCode(res, testName);
177     }
178
179     // Failure outcomes
180     // Placeholders until the tests below can be implemented. See Issue CSPACE-401.
181
182     @Override
183     public void createWithEmptyEntityBody(String testName) throws Exception {
184     }
185
186     @Override
187     public void createWithMalformedXml(String testName) throws Exception {
188     }
189
190     @Override
191     public void createWithWrongXmlSchema(String testName) throws Exception {
192     }
193
194     @Override
195     public void updateWithEmptyEntityBody(String testName) throws Exception {
196     }
197
198     @Override
199     public void updateWithMalformedXml(String testName) throws Exception {
200     }
201
202     @Override
203     public void updateWithWrongXmlSchema(String testName) throws Exception {
204     }
205     
206     // ---------------------------------------------------------------
207     // Search tests
208     // ---------------------------------------------------------------
209     
210     public void searchWorkflowDeleted(String testName) throws Exception {
211     }    
212
213     // ---------------------------------------------------------------
214     // Utility tests : tests of code used in tests above
215     // ---------------------------------------------------------------
216
217 //    @Test(dependsOnMethods = {"create", "read"})
218     public void testSubmitRequest() {
219         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK
220         String method = ServiceRequestType.READ.httpMethodName();
221         String url = getResourceURL(knownResourceId);
222         int statusCode = submitRequest(method, url);
223         logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode);
224         Assert.assertEquals(statusCode, EXPECTED_STATUS);
225     }
226
227     // ---------------------------------------------------------------
228     // Utility methods used by tests above
229     // ---------------------------------------------------------------
230     
231     @Override
232     protected PoxPayloadOut createInstance(String identifier) {
233         return createDimensionInstance(identifier);
234     }    
235     
236     private PoxPayloadOut createDimensionInstance(String dimensionValue) {
237         String measurementUnit = "measurementUnit-" + dimensionValue;
238         String dimensionsCommonPartName = new DimensionClient().getCommonPartName();
239         DimensionsCommon dimensionsCommon = new DimensionsCommon();
240         
241         dimensionsCommon.setMeasurementUnit(measurementUnit);
242         PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
243         PayloadOutputPart commonPart = multipart.addPart(dimensionsCommonPartName, dimensionsCommon);
244
245         if (logger.isDebugEnabled()) {
246             logger.debug("To be created, Dimensions common: " + commonPart.asXML());
247             logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
248         }
249
250         return multipart;
251     }
252
253         @Override
254     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
255         public void create(String testName) throws Exception {
256                 String csid = this.createTestObject(testName);
257                 if (this.knownResourceId == null) {
258                         this.knownResourceId = csid;
259                 }
260         }
261
262         
263         @Override
264         public void readList(String testName) throws Exception {
265         }       
266                 
267         @Override
268     public void readPaginatedList(String testName) throws Exception {
269                 //empty N/A
270         }
271         
272 }