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 public void createList(String testName) throws Exception {
87 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create"})
88 public void read(String testName) throws Exception {
89 logger.debug(testBanner(testName, CLASS_NAME));
91 DimensionClient client = new DimensionClient();
92 ClientResponse<String> res = client.getWorkflow(knownResourceId);
93 assertStatusCode(res, testName);
94 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
95 WorkflowCommon workflowsCommon = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
96 if (logger.isDebugEnabled() == true) {
97 logger.debug("Workflow payload is: " + input.getXmlPayload());
99 Assert.assertNotNull(workflowsCommon);
103 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"createList", "read"})
104 // public void readList(String testName) throws Exception {
105 // logger.debug(testBanner(testName, CLASS_NAME));
107 // WorkflowClient client = new WorkflowClient();
108 // ClientResponse<AbstractCommonList> res = client.readList();
109 // AbstractCommonList list = res.getEntity();
110 // assertStatusCode(res, testName);
111 // if (logger.isDebugEnabled()) {
112 // List<AbstractCommonList.ListItem> items =
113 // list.getListItem();
115 // for(AbstractCommonList.ListItem item : items){
116 // logger.debug(testName + ": list-item[" + i + "] " +
124 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
125 public void update(String testName) throws Exception {
126 logger.debug(testBanner(testName, CLASS_NAME));
128 updateLifeCycleState(testName, knownResourceId, WorkflowClient.WORKFLOWSTATE_APPROVED);
133 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update", "testSubmitRequest"})
134 public void updateNonExistent(String testName) throws Exception {
135 logger.debug(testBanner(testName, CLASS_NAME));
136 setupUpdateNonExistent();
137 // Submit the request to the service and store the response.
138 // Note: The ID used in this 'create' call may be arbitrary.
139 // The only relevant ID may be the one used in update(), below.
140 WorkflowClient client = new WorkflowClient();
141 PoxPayloadOut multipart = createDimensionInstance(NON_EXISTENT_ID);
142 ClientResponse<String> res = client.update(NON_EXISTENT_ID, multipart);
143 assertStatusCode(res, testName);
147 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
148 public void delete(String testName) throws Exception {
149 logger.debug(testBanner(testName, CLASS_NAME));
151 WorkflowClient client = new WorkflowClient();
152 ClientResponse<Response> res = client.delete(knownResourceId);
153 assertStatusCode(res, testName);
156 // ---------------------------------------------------------------
157 // Failure outcome tests : means we expect response to fail, but test to succeed
158 // ---------------------------------------------------------------
162 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"read"})
163 public void readNonExistent(String testName) throws Exception {
164 logger.debug(testBanner(testName, CLASS_NAME));
165 setupReadNonExistent();
166 WorkflowClient client = new WorkflowClient();
167 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
168 assertStatusCode(res, testName);
173 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"delete"})
174 public void deleteNonExistent(String testName) throws Exception {
175 logger.debug(testBanner(testName, CLASS_NAME));
176 setupDeleteNonExistent();
177 WorkflowClient client = new WorkflowClient();
178 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
179 assertStatusCode(res, testName);
183 // Placeholders until the tests below can be implemented. See Issue CSPACE-401.
186 public void createWithEmptyEntityBody(String testName) throws Exception {
190 public void createWithMalformedXml(String testName) throws Exception {
194 public void createWithWrongXmlSchema(String testName) throws Exception {
198 public void updateWithEmptyEntityBody(String testName) throws Exception {
202 public void updateWithMalformedXml(String testName) throws Exception {
206 public void updateWithWrongXmlSchema(String testName) throws Exception {
209 // ---------------------------------------------------------------
211 // ---------------------------------------------------------------
213 public void searchWorkflowDeleted(String testName) throws Exception {
216 // ---------------------------------------------------------------
217 // Utility tests : tests of code used in tests above
218 // ---------------------------------------------------------------
220 // @Test(dependsOnMethods = {"create", "read"})
221 public void testSubmitRequest() {
222 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); // Expected status code: 200 OK
223 String method = ServiceRequestType.READ.httpMethodName();
224 String url = getResourceURL(knownResourceId);
225 int statusCode = submitRequest(method, url);
226 logger.debug("testSubmitRequest: url=" + url + " status=" + statusCode);
227 Assert.assertEquals(statusCode, EXPECTED_STATUS);
230 // ---------------------------------------------------------------
231 // Utility methods used by tests above
232 // ---------------------------------------------------------------
235 protected PoxPayloadOut createInstance(String identifier) {
236 return createDimensionInstance(identifier);
239 private PoxPayloadOut createDimensionInstance(String dimensionValue) {
240 String value = "dimensionValue-" + dimensionValue;
241 String dimensionsCommonPartName = new DimensionClient().getCommonPartName();
242 DimensionsCommon dimensionsCommon = new DimensionsCommon();
244 dimensionsCommon.setValue(value);
245 PoxPayloadOut multipart = new PoxPayloadOut(DimensionClient.SERVICE_PAYLOAD_NAME);
246 PayloadOutputPart commonPart = multipart.addPart(dimensionsCommonPartName, dimensionsCommon);
248 if (logger.isDebugEnabled()) {
249 logger.debug("To be created, Dimensions common: " + commonPart.asXML());
250 logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
257 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
258 public void create(String testName) throws Exception {
259 String csid = this.createTestObject(testName);
260 if (this.knownResourceId == null) {
261 this.knownResourceId = csid;
267 public void readList(String testName) throws Exception {
271 public void readPaginatedList(String testName) throws Exception {