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;
26 import javax.ws.rs.core.Response;
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;
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;
39 import org.jboss.resteasy.client.ClientResponse;
41 import org.testng.Assert;
42 import org.testng.annotations.Test;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
48 * ObjectExitServiceTest, carries out tests against a deployed and running ObjectExit Service. <p/>
49 * $LastChangedRevision: $
52 public class WorkflowServiceTest extends AbstractServiceTestImpl {
54 private final String CLASS_NAME = WorkflowServiceTest.class.getName();
55 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
56 private String knownResourceId = null;
59 public String getServicePathComponent() {
60 return WorkflowClient.SERVICE_PATH_COMPONENT;
64 protected String getServiceName() {
65 return WorkflowClient.SERVICE_NAME;
69 protected CollectionSpaceClient getClientInstance() {
70 return new DimensionClient();
74 protected AbstractCommonList getAbstractCommonList(ClientResponse<AbstractCommonList> response) {
75 return response.getEntity(AbstractCommonList.class);
79 public void createList(String testName) throws Exception {
84 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
85 public void read(String testName) throws Exception {
86 logger.debug(testBanner(testName, CLASS_NAME));
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());
96 Assert.assertNotNull(workflowsCommon);
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));
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();
112 // for(AbstractCommonList.ListItem item : items){
113 // logger.debug(testName + ": list-item[" + i + "] " +
121 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
122 public void update(String testName) throws Exception {
123 logger.debug(testBanner(testName, CLASS_NAME));
125 updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWSTATE_APPROVED);
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);
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));
148 WorkflowClient client = new WorkflowClient();
149 ClientResponse<Response> res = client.delete(knownResourceId);
150 assertStatusCode(res, testName);
153 // ---------------------------------------------------------------
154 // Failure outcome tests : means we expect response to fail, but test to succeed
155 // ---------------------------------------------------------------
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);
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);
180 // Placeholders until the tests below can be implemented. See Issue CSPACE-401.
183 public void createWithEmptyEntityBody(String testName) throws Exception {
187 public void createWithMalformedXml(String testName) throws Exception {
191 public void createWithWrongXmlSchema(String testName) throws Exception {
195 public void updateWithEmptyEntityBody(String testName) throws Exception {
199 public void updateWithMalformedXml(String testName) throws Exception {
203 public void updateWithWrongXmlSchema(String testName) throws Exception {
206 // ---------------------------------------------------------------
208 // ---------------------------------------------------------------
210 public void searchWorkflowDeleted(String testName) throws Exception {
213 // ---------------------------------------------------------------
214 // Utility tests : tests of code used in tests above
215 // ---------------------------------------------------------------
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);
227 // ---------------------------------------------------------------
228 // Utility methods used by tests above
229 // ---------------------------------------------------------------
232 protected PoxPayloadOut createInstance(String identifier) {
233 return createDimensionInstance(identifier);
236 private PoxPayloadOut createDimensionInstance(String dimensionValue) {
237 String measurementUnit = "measurementUnit-" + dimensionValue;
238 String dimensionsCommonPartName = new DimensionClient().getCommonPartName();
239 DimensionsCommon dimensionsCommon = new DimensionsCommon();
241 dimensionsCommon.setMeasurementUnit(measurementUnit);
242 PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
243 PayloadOutputPart commonPart = multipart.addPart(dimensionsCommonPartName, dimensionsCommon);
245 if (logger.isDebugEnabled()) {
246 logger.debug("To be created, Dimensions common: " + commonPart.asXML());
247 logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
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;
264 public void readList(String testName) throws Exception {
268 public void readPaginatedList(String testName) throws Exception {