]> git.aero2k.de Git - tmp/jakarta-migration.git/blob
63e4967f78e6757eda19131e9687b6d4ddd3aa7a
[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 import java.util.List;
26
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.PayloadOutputPart;
32 import org.collectionspace.services.client.PoxPayloadIn;
33 import org.collectionspace.services.client.PoxPayloadOut;
34
35 import org.collectionspace.services.jaxb.AbstractCommonList;
36 import org.collectionspace.services.workflow.WorkflowCommon;
37 import org.collectionspace.services.client.DimensionClient;
38 import org.collectionspace.services.client.workflow.WorkflowClient;
39 import org.collectionspace.services.dimension.DimensionsCommon;
40 import org.collectionspace.services.dimension.DimensionsCommonList;
41
42 import org.jboss.resteasy.client.ClientResponse;
43
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
46
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50 /**
51  * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service. <p/>
52  * $LastChangedRevision:  $
53  * $LastChangedDate:  $
54  */
55 public class WorkflowServiceTest extends AbstractServiceTestImpl {
56
57     private final String CLASS_NAME = WorkflowServiceTest.class.getName();
58     private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
59     private String knownResourceId = null;
60
61     @Override
62         public String getServicePathComponent() {
63                 return WorkflowClient.SERVICE_PATH_COMPONENT;
64         }
65
66         @Override
67         protected String getServiceName() {
68                 return WorkflowClient.SERVICE_NAME;
69         }
70     
71     @Override
72     protected CollectionSpaceClient getClientInstance() {
73         return new DimensionClient();
74     }
75
76     @Override
77     protected AbstractCommonList getAbstractCommonList(ClientResponse<AbstractCommonList> response) {
78         return response.getEntity(AbstractCommonList.class);
79     }
80
81 //    @Override
82 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
83 //    public void create(String testName) throws Exception {
84 //        logger.debug(testBanner(testName, CLASS_NAME));
85 //        setupCreate();
86 //        WorkflowClient client = new WorkflowClient();
87 //        PoxPayloadOut multipart = createObjectExitInstance(createIdentifier());
88 //        ClientResponse<Response> res = client.create(multipart);
89 //        assertStatusCode(res, testName);
90 //        if (knownResourceId == null) {
91 //            knownResourceId = extractId(res);  // Store the ID returned from the first resource created for additional tests below.
92 //            logger.debug(testName + ": knownResourceId=" + knownResourceId);
93 //        }
94 //        allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run.
95 //    }
96     
97     
98     /*
99      * Create a Dimension instance to use as our test target.
100      */
101     @Override
102     protected String createWorkflowTarget(String testName) throws Exception {
103         String result = null;
104         
105         result = createTestObject(testName);
106         
107         return result;
108     }
109     
110     /*
111      * Create a Dimension instance to use as our test target.
112      */
113     protected String createTestObject(String testName) throws Exception {
114         String result = null;
115         
116         logger.debug(testBanner(testName, CLASS_NAME));
117         setupCreate();
118         DimensionClient client = new DimensionClient();
119         PoxPayloadOut multipart = createDimensionInstance(createIdentifier());
120         ClientResponse<Response> res = client.create(multipart);
121         assertStatusCode(res, testName);
122         if (knownResourceId == null) {
123                 knownResourceId = extractId(res);  // Store the ID returned from the first resource created for additional tests below.
124                 logger.debug(testName + ": knownResourceId=" + knownResourceId);
125         }
126         result = extractId(res);
127         allResourceIdsCreated.add(result); // Store the IDs from every resource created by tests so they can be deleted after tests have been run.
128         
129         return result;
130     }
131
132     @Override
133     public void createList(String testName) throws Exception {
134         //empty N/A
135     }
136
137     @Override
138     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
139     public void read(String testName) throws Exception {
140         logger.debug(testBanner(testName, CLASS_NAME));
141         setupRead();
142         DimensionClient client = new DimensionClient();
143         ClientResponse<String> res = client.getWorkflow(knownResourceId);
144         assertStatusCode(res, testName);
145         PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
146         WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
147         if (logger.isDebugEnabled() == true) {
148                 logger.debug("Workflow payload is: " + input.getXmlPayload());
149         }
150         Assert.assertNotNull(workflowsCommon);
151     }
152
153 //    @Override
154 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"})
155 //    public void readList(String testName) throws Exception {
156 //        logger.debug(testBanner(testName, CLASS_NAME));
157 //        setupReadList();
158 //        WorkflowClient client = new WorkflowClient();
159 //        ClientResponse<AbstractCommonList> res = client.readList();
160 //        AbstractCommonList list = res.getEntity();
161 //        assertStatusCode(res, testName);
162 //        if (logger.isDebugEnabled()) {
163 //            List<AbstractCommonList.ListItem> items =
164 //                list.getListItem();
165 //            int i = 0;
166 //            for(AbstractCommonList.ListItem item : items){
167 //                logger.debug(testName + ": list-item[" + i + "] " +
168 //                        item.toString());
169 //                i++;
170 //            }
171 //        }
172 //    }
173     
174     @Override
175     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
176     public void update(String testName) throws Exception {
177         logger.debug(testBanner(testName, CLASS_NAME));
178         setupUpdate();
179         updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWSTATE_APPROVED);
180     }    
181
182
183     @Override
184 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"})
185     public void updateNonExistent(String testName) throws Exception {
186         logger.debug(testBanner(testName, CLASS_NAME));
187         setupUpdateNonExistent();
188         // Submit the request to the service and store the response.
189         // Note: The ID used in this 'create' call may be arbitrary.
190         // The only relevant ID may be the one used in update(), below.
191         WorkflowClient client = new WorkflowClient();
192         PoxPayloadOut multipart = createDimensionInstance(NON_EXISTENT_ID);
193         ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
194         assertStatusCode(res, testName);
195     }
196
197     @Override
198 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
199     public void delete(String testName) throws Exception {
200         logger.debug(testBanner(testName, CLASS_NAME));
201         setupDelete();
202         WorkflowClient client = new WorkflowClient();
203         ClientResponse<Response> res = client.delete(knownResourceId);
204         assertStatusCode(res, testName);
205     }
206
207     // ---------------------------------------------------------------
208     // Failure outcome tests : means we expect response to fail, but test to succeed
209     // ---------------------------------------------------------------
210
211     // Failure outcome
212     @Override
213 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
214     public void readNonExistent(String testName) throws Exception {
215         logger.debug(testBanner(testName, CLASS_NAME));
216         setupReadNonExistent();
217         WorkflowClient client = new WorkflowClient();
218         ClientResponse<String> res = client.read(NON_EXISTENT_ID);
219         assertStatusCode(res, testName);
220     }
221
222     // Failure outcome
223     @Override
224 //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"})
225     public void deleteNonExistent(String testName) throws Exception {
226         logger.debug(testBanner(testName, CLASS_NAME));
227         setupDeleteNonExistent();
228         WorkflowClient client = new WorkflowClient();
229         ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
230         assertStatusCode(res, testName);
231     }
232
233     // Failure outcomes
234     // Placeholders until the tests below can be implemented. See Issue CSPACE-401.
235
236     @Override
237     public void createWithEmptyEntityBody(String testName) throws Exception {
238     }
239
240     @Override
241     public void createWithMalformedXml(String testName) throws Exception {
242     }
243
244     @Override
245     public void createWithWrongXmlSchema(String testName) throws Exception {
246     }
247
248     @Override
249     public void updateWithEmptyEntityBody(String testName) throws Exception {
250     }
251
252     @Override
253     public void updateWithMalformedXml(String testName) throws Exception {
254     }
255
256     @Override
257     public void updateWithWrongXmlSchema(String testName) throws Exception {
258     }
259
260     // ---------------------------------------------------------------
261     // Utility tests : tests of code used in tests above
262     // ---------------------------------------------------------------
263
264 //    @Test(dependsOnMethods = {"create", "read"})
265     public void testSubmitRequest() {
266         final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK
267         String method = ServiceRequestType.READ.httpMethodName();
268         String url = getResourceURL(knownResourceId);
269         int statusCode = submitRequest(method, url);
270         logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode);
271         Assert.assertEquals(statusCode, EXPECTED_STATUS);
272     }
273
274     // ---------------------------------------------------------------
275     // Utility methods used by tests above
276     // ---------------------------------------------------------------
277     private PoxPayloadOut createDimensionInstance(String dimensionValue) {
278         String value = "dimensionValue-" + dimensionValue;
279         String dimensionsCommonPartName = new DimensionClient().getCommonPartName();
280         DimensionsCommon dimensionsCommon = new DimensionsCommon();
281         
282         dimensionsCommon.setValue(value);
283         PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
284         PayloadOutputPart commonPart = multipart.addPart(dimensionsCommonPartName, dimensionsCommon);
285
286         if (logger.isDebugEnabled()) {
287             logger.debug("To be created, Dimensions common: " + commonPart.asXML());
288             logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
289         }
290
291         return multipart;
292     }
293
294         @Override
295     @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
296         public void create(String testName) throws Exception {
297                 this.createTestObject(testName);
298         }
299
300         
301         @Override
302         public void readList(String testName) throws Exception {
303         }       
304                 
305         @Override
306     public void readPaginatedList(String testName) throws Exception {
307                 //empty N/A
308         }
309         
310 }