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:
6 * http://www.collectionspace.org
7 * http://wiki.collectionspace.org
9 * Copyright © 2009 Regents of the University of California
11 * Licensed under the Educational Community License (ECL), Version 2.0.
12 * You may not use this file except in compliance with this License.
14 * You may obtain a copy of the ECL 2.0 License at
15 * https://source.collectionspace.org/collection-space/LICENSE.txt
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.
23 package org.collectionspace.services.client.test;
25 import java.util.List;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
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;
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;
42 import org.jboss.resteasy.client.ClientResponse;
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service. <p/>
52 * $LastChangedRevision: $
55 public class WorkflowServiceTest extends AbstractServiceTestImpl {
57 private final String CLASS_NAME = WorkflowServiceTest.class.getName();
58 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
59 private String knownResourceId = null;
62 public String getServicePathComponent() {
63 return WorkflowClient.SERVICE_PATH_COMPONENT;
67 protected String getServiceName() {
68 return WorkflowClient.SERVICE_NAME;
72 protected CollectionSpaceClient getClientInstance() {
73 return new DimensionClient();
77 protected AbstractCommonList getAbstractCommonList(ClientResponse<AbstractCommonList> response) {
78 return response.getEntity(AbstractCommonList.class);
82 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
83 // public void create(String testName) throws Exception {
84 // logger.debug(testBanner(testName, CLASS_NAME));
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);
94 // allResourceIdsCreated.add(extractId(res)); // Store the IDs from every resource created by tests so they can be deleted after tests have been run.
99 * Create a Dimension instance to use as our test target.
102 protected String createWorkflowTarget(String testName) throws Exception {
103 String result = null;
105 result = createTestObject(testName);
111 * Create a Dimension instance to use as our test target.
113 protected String createTestObject(String testName) throws Exception {
114 String result = null;
116 logger.debug(testBanner(testName, CLASS_NAME));
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);
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.
133 public void createList(String testName) throws Exception {
138 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
139 public void read(String testName) throws Exception {
140 logger.debug(testBanner(testName, CLASS_NAME));
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());
150 Assert.assertNotNull(workflowsCommon);
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));
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();
166 // for(AbstractCommonList.ListItem item : items){
167 // logger.debug(testName + ": list-item[" + i + "] " +
175 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
176 public void update(String testName) throws Exception {
177 logger.debug(testBanner(testName, CLASS_NAME));
179 updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWSTATE_APPROVED);
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);
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));
202 WorkflowClient client = new WorkflowClient();
203 ClientResponse<Response> res = client.delete(knownResourceId);
204 assertStatusCode(res, testName);
207 // ---------------------------------------------------------------
208 // Failure outcome tests : means we expect response to fail, but test to succeed
209 // ---------------------------------------------------------------
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);
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);
234 // Placeholders until the tests below can be implemented. See Issue CSPACE-401.
237 public void createWithEmptyEntityBody(String testName) throws Exception {
241 public void createWithMalformedXml(String testName) throws Exception {
245 public void createWithWrongXmlSchema(String testName) throws Exception {
249 public void updateWithEmptyEntityBody(String testName) throws Exception {
253 public void updateWithMalformedXml(String testName) throws Exception {
257 public void updateWithWrongXmlSchema(String testName) throws Exception {
260 // ---------------------------------------------------------------
261 // Utility tests : tests of code used in tests above
262 // ---------------------------------------------------------------
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);
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();
282 dimensionsCommon.setValue(value);
283 PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
284 PayloadOutputPart commonPart = multipart.addPart(dimensionsCommonPartName, dimensionsCommon);
286 if (logger.isDebugEnabled()) {
287 logger.debug("To be created, Dimensions common: " + commonPart.asXML());
288 logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
295 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
296 public void create(String testName) throws Exception {
297 this.createTestObject(testName);
302 public void readList(String testName) throws Exception {
306 public void readPaginatedList(String testName) throws Exception {