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