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.ArrayList;
26 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.DimensionClient;
32 import org.collectionspace.services.client.DimensionFactory;
33 import org.collectionspace.services.client.PayloadInputPart;
34 import org.collectionspace.services.client.PayloadOutputPart;
35 import org.collectionspace.services.client.PoxPayloadIn;
36 import org.collectionspace.services.client.PoxPayloadOut;
37 import org.collectionspace.services.client.workflow.WorkflowClient;
38 import org.collectionspace.services.dimension.DimensionsCommon;
39 import org.collectionspace.services.dimension.DimensionsCommonList;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.workflow.WorkflowCommon;
43 import org.jboss.resteasy.client.ClientResponse;
45 import org.testng.Assert;
46 //import org.testng.annotations.AfterClass;
47 import org.testng.annotations.Test;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
53 * DimensionServiceTest, carries out tests against a
54 * deployed and running Dimension Service.
56 * $LastChangedRevision: 917 $
57 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
59 public class DimensionServiceTest extends AbstractServiceTestImpl {
62 private final String CLASS_NAME = DimensionServiceTest.class.getName();
63 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
65 // Instance variables specific to this test.
66 /** The SERVIC e_ pat h_ component. */
67 /** The known resource id. */
68 private String knownResourceId = null;
71 protected String getServiceName() {
72 return DimensionClient.SERVICE_NAME;
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
79 protected CollectionSpaceClient getClientInstance() {
80 return new DimensionClient();
84 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
87 protected AbstractCommonList getAbstractCommonList(
88 ClientResponse<AbstractCommonList> response) {
89 return response.getEntity(DimensionsCommonList.class);
92 // ---------------------------------------------------------------
93 // CRUD tests : CREATE tests
94 // ---------------------------------------------------------------
97 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
100 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
101 public void create(String testName) throws Exception {
103 if (logger.isDebugEnabled()) {
104 logger.debug(testBanner(testName, CLASS_NAME));
106 // Perform setup, such as initializing the type of service request
107 // (e.g. CREATE, DELETE), its valid and expected status codes, and
108 // its associated HTTP method name (e.g. POST, DELETE).
111 // Submit the request to the service and store the response.
112 DimensionClient client = new DimensionClient();
113 String identifier = createIdentifier();
114 PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
116 ClientResponse<Response> res = client.create(multipart);
118 int statusCode = res.getStatus();
120 // Check the status code of the response: does it match
121 // the expected response(s)?
124 // Does it fall within the set of valid status codes?
125 // Does it exactly match the expected status code?
126 if (logger.isDebugEnabled()) {
127 logger.debug(testName + ": status = " + statusCode);
129 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
130 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
131 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
133 // Store the ID returned from the first resource created
134 // for additional tests below.
135 if (knownResourceId == null) {
136 knownResourceId = extractId(res);
137 if (logger.isDebugEnabled()) {
138 logger.debug(testName + ": knownResourceId=" + knownResourceId);
142 // Store the IDs from every resource created by tests,
143 // so they can be deleted after tests have been run.
144 allResourceIdsCreated.add(extractId(res));
148 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
151 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
152 dependsOnMethods = {"create"})
153 public void createList(String testName) throws Exception {
154 for (int i = 0; i < 3; i++) {
160 // Placeholders until the three tests below can be uncommented.
161 // See Issue CSPACE-401.
163 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
166 public void createWithEmptyEntityBody(String testName) throws Exception {
167 //Should this really be empty?
171 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
174 public void createWithMalformedXml(String testName) throws Exception {
175 //Should this really be empty?
179 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
182 public void createWithWrongXmlSchema(String testName) throws Exception {
183 //Should this really be empty?
188 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
189 dependsOnMethods = {"create", "testSubmitRequest"})
190 public void createWithEmptyEntityBody(String testName) throws Exception {
192 if (logger.isDebugEnabled()) {
193 logger.debug(testBanner(testName, CLASS_NAME));
196 setupCreateWithEmptyEntityBody(testName, logger);
198 // Submit the request to the service and store the response.
199 String method = REQUEST_TYPE.httpMethodName();
200 String url = getServiceRootURL();
201 String mediaType = MediaType.APPLICATION_XML;
202 final String entity = "";
203 int statusCode = submitRequest(method, url, mediaType, entity);
205 // Check the status code of the response: does it match
206 // the expected response(s)?
207 if(logger.isDebugEnabled()){
208 logger.debug("createWithEmptyEntityBody url=" + url +
209 " status=" + statusCode);
211 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
212 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
213 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
217 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
218 dependsOnMethods = {"create", "testSubmitRequest"})
219 public void createWithMalformedXml(String testName) throws Exception {
221 if (logger.isDebugEnabled()) {
222 logger.debug(testBanner(testName, CLASS_NAME));
225 setupCreateWithMalformedXml();
227 // Submit the request to the service and store the response.
228 String method = REQUEST_TYPE.httpMethodName();
229 String url = getServiceRootURL();
230 String mediaType = MediaType.APPLICATION_XML;
231 final String entity = MALFORMED_XML_DATA; // Constant from base class.
232 int statusCode = submitRequest(method, url, mediaType, entity);
234 // Check the status code of the response: does it match
235 // the expected response(s)?
236 if(logger.isDebugEnabled()){
237 logger.debug(testName + ": url=" + url +
238 " status=" + statusCode);
240 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
241 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
242 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
246 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
247 dependsOnMethods = {"create", "testSubmitRequest"})
248 public void createWithWrongXmlSchema(String testName) throws Exception {
250 if (logger.isDebugEnabled()) {
251 logger.debug(testBanner(testName, CLASS_NAME));
254 setupCreateWithWrongXmlSchema();
256 // Submit the request to the service and store the response.
257 String method = REQUEST_TYPE.httpMethodName();
258 String url = getServiceRootURL();
259 String mediaType = MediaType.APPLICATION_XML;
260 final String entity = WRONG_XML_SCHEMA_DATA;
261 int statusCode = submitRequest(method, url, mediaType, entity);
263 // Check the status code of the response: does it match
264 // the expected response(s)?
265 if(logger.isDebugEnabled()){
266 logger.debug(testName + ": url=" + url +
267 " status=" + statusCode);
269 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
270 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
271 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
274 // ---------------------------------------------------------------
275 // CRUD tests : READ tests
276 // ---------------------------------------------------------------
279 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
282 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
283 dependsOnMethods = {"create"})
284 public void read(String testName) throws Exception {
286 if (logger.isDebugEnabled()) {
287 logger.debug(testBanner(testName, CLASS_NAME));
292 // Submit the request to the service and store the response.
293 DimensionClient client = new DimensionClient();
294 ClientResponse<String> res = client.read(knownResourceId);
295 int statusCode = res.getStatus();
297 // Check the status code of the response: does it match
298 // the expected response(s)?
299 if (logger.isDebugEnabled()) {
300 logger.debug(testName + ": status = " + statusCode);
302 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
303 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
304 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
306 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
307 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
308 DimensionsCommon dimensionsCommon = null;
309 if (payloadInputPart != null) {
310 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
312 Assert.assertNotNull(dimensionsCommon);
317 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
320 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
321 dependsOnMethods = {"read"})
322 public void readNonExistent(String testName) throws Exception {
324 if (logger.isDebugEnabled()) {
325 logger.debug(testBanner(testName, CLASS_NAME));
328 setupReadNonExistent();
330 // Submit the request to the service and store the response.
331 DimensionClient client = new DimensionClient();
332 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
333 int statusCode = res.getStatus();
335 // Check the status code of the response: does it match
336 // the expected response(s)?
337 if (logger.isDebugEnabled()) {
338 logger.debug(testName + ": status = " + statusCode);
340 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
341 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
342 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
345 // ---------------------------------------------------------------
346 // CRUD tests : READ_LIST tests
347 // ---------------------------------------------------------------
350 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
353 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
354 dependsOnMethods = {"read"})
355 public void readList(String testName) throws Exception {
357 if (logger.isDebugEnabled()) {
358 logger.debug(testBanner(testName, CLASS_NAME));
363 // Submit the request to the service and store the response.
364 DimensionClient client = new DimensionClient();
365 ClientResponse<DimensionsCommonList> res = client.readList();
366 DimensionsCommonList list = res.getEntity();
367 int statusCode = res.getStatus();
369 // Check the status code of the response: does it match
370 // the expected response(s)?
371 if (logger.isDebugEnabled()) {
372 logger.debug(testName + ": status = " + statusCode);
374 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
375 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
376 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
378 // Optionally output additional data about list members for debugging.
379 boolean iterateThroughList = false;
380 if (iterateThroughList && logger.isDebugEnabled()) {
381 List<DimensionsCommonList.DimensionListItem> items =
382 list.getDimensionListItem();
384 for (DimensionsCommonList.DimensionListItem item : items) {
385 logger.debug(testName + ": list-item[" + i + "] csid="
387 logger.debug(testName + ": list-item[" + i + "] objectNumber="
388 + item.getDimension());
389 logger.debug(testName + ": list-item[" + i + "] URI="
399 // ---------------------------------------------------------------
400 // CRUD tests : UPDATE tests
401 // ---------------------------------------------------------------
404 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
407 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
408 dependsOnMethods = {"read"})
409 public void update(String testName) throws Exception {
411 if (logger.isDebugEnabled()) {
412 logger.debug(testBanner(testName, CLASS_NAME));
417 // Retrieve the contents of a resource to update.
418 DimensionClient client = new DimensionClient();
419 ClientResponse<String> res =
420 client.read(knownResourceId);
421 if (logger.isDebugEnabled()) {
422 logger.debug(testName + ": read status = " + res.getStatus());
424 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
426 if (logger.isDebugEnabled()) {
427 logger.debug("got object to update with ID: " + knownResourceId);
429 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
430 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
431 DimensionsCommon dimensionsCommon = null;
432 if (payloadInputPart != null) {
433 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
435 Assert.assertNotNull(dimensionsCommon);
437 // Update the content of this resource.
438 dimensionsCommon.setValue("updated-" + dimensionsCommon.getValue());
439 dimensionsCommon.setValueDate("updated-" + dimensionsCommon.getValueDate());
440 if (logger.isDebugEnabled()) {
441 logger.debug("to be updated object");
442 logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
444 // Submit the request to the service and store the response.
445 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
446 PayloadOutputPart commonPart = output.addPart(dimensionsCommon, MediaType.APPLICATION_XML_TYPE);
447 commonPart.setLabel(client.getCommonPartName());
449 res = client.update(knownResourceId, output);
450 int statusCode = res.getStatus();
451 // Check the status code of the response: does it match the expected response(s)?
452 if (logger.isDebugEnabled()) {
453 logger.debug(testName + ": status = " + statusCode);
455 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
456 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
457 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
459 input = new PoxPayloadIn(res.getEntity());
460 DimensionsCommon updatedDimensionsCommon =
461 (DimensionsCommon) extractPart(input,
462 client.getCommonPartName(), DimensionsCommon.class);
463 Assert.assertNotNull(updatedDimensionsCommon);
465 Assert.assertEquals(updatedDimensionsCommon.getValueDate(),
466 dimensionsCommon.getValueDate(),
467 "Data in updated object did not match submitted data.");
472 // Placeholders until the three tests below can be uncommented.
473 // See Issue CSPACE-401.
475 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
478 public void updateWithEmptyEntityBody(String testName) throws Exception {
479 //Should this really be empty?
483 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
486 public void updateWithMalformedXml(String testName) throws Exception {
487 //Should this really be empty?
491 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
494 public void updateWithWrongXmlSchema(String testName) throws Exception {
495 //Should this really be empty?
500 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
501 dependsOnMethods = {"create", "update", "testSubmitRequest"})
502 public void updateWithEmptyEntityBody(String testName) throws Exception {
504 if (logger.isDebugEnabled()) {
505 logger.debug(testBanner(testName, CLASS_NAME));
508 setupUpdateWithEmptyEntityBody();
510 // Submit the request to the service and store the response.
511 String method = REQUEST_TYPE.httpMethodName();
512 String url = getResourceURL(knownResourceId);
513 String mediaType = MediaType.APPLICATION_XML;
514 final String entity = "";
515 int statusCode = submitRequest(method, url, mediaType, entity);
517 // Check the status code of the response: does it match
518 // the expected response(s)?
519 if(logger.isDebugEnabled()){
520 logger.debug(testName + ": url=" + url +
521 " status=" + statusCode);
523 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
524 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
525 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
529 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
530 dependsOnMethods = {"create", "update", "testSubmitRequest"})
531 public void updateWithMalformedXml(String testName) throws Exception {
533 if (logger.isDebugEnabled()) {
534 logger.debug(testBanner(testName, CLASS_NAME));
537 setupUpdateWithMalformedXml(testName, logger);
539 // Submit the request to the service and store the response.
540 String method = REQUEST_TYPE.httpMethodName();
541 String url = getResourceURL(knownResourceId);
542 String mediaType = MediaType.APPLICATION_XML;
543 final String entity = MALFORMED_XML_DATA;
544 int statusCode = submitRequest(method, url, mediaType, entity);
546 // Check the status code of the response: does it match
547 // the expected response(s)?
548 if(logger.isDebugEnabled()){
549 logger.debug(testName + ": url=" + url +
550 " status=" + statusCode);
552 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
553 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
554 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
558 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
559 dependsOnMethods = {"create", "update", "testSubmitRequest"})
560 public void updateWithWrongXmlSchema(String testName) throws Exception {
562 if (logger.isDebugEnabled()) {
563 logger.debug(testBanner(testName, CLASS_NAME));
566 setupUpdateWithWrongXmlSchema(testName, logger);
568 // Submit the request to the service and store the response.
569 String method = REQUEST_TYPE.httpMethodName();
570 String url = getResourceURL(knownResourceId);
571 String mediaType = MediaType.APPLICATION_XML;
572 final String entity = WRONG_XML_SCHEMA_DATA;
573 int statusCode = submitRequest(method, url, mediaType, entity);
575 // Check the status code of the response: does it match
576 // the expected response(s)?
577 if(logger.isDebugEnabled()){
578 logger.debug(testName + ": url=" + url +
579 " status=" + statusCode);
581 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
582 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
583 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
591 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
592 dependsOnMethods = {"update", "testSubmitRequest"})
593 public void updateNonExistent(String testName) throws Exception {
595 if (logger.isDebugEnabled()) {
596 logger.debug(testBanner(testName, CLASS_NAME));
599 setupUpdateNonExistent();
601 // Submit the request to the service and store the response.
602 // Note: The ID used in this 'create' call may be arbitrary.
603 // The only relevant ID may be the one used in update(), below.
604 DimensionClient client = new DimensionClient();
605 PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
607 ClientResponse<String> res =
608 client.update(NON_EXISTENT_ID, multipart);
609 int statusCode = res.getStatus();
611 // Check the status code of the response: does it match
612 // the expected response(s)?
613 if (logger.isDebugEnabled()) {
614 logger.debug(testName + ": status = " + statusCode);
616 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
617 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
618 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
621 // ---------------------------------------------------------------
622 // CRUD tests : DELETE tests
623 // ---------------------------------------------------------------
626 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
629 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
630 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"})
631 public void delete(String testName) throws Exception {
633 if (logger.isDebugEnabled()) {
634 logger.debug(testBanner(testName, CLASS_NAME));
639 // Submit the request to the service and store the response.
640 DimensionClient client = new DimensionClient();
641 ClientResponse<Response> res = client.delete(knownResourceId);
642 int statusCode = res.getStatus();
644 // Check the status code of the response: does it match
645 // the expected response(s)?
646 if (logger.isDebugEnabled()) {
647 logger.debug(testName + ": status = " + statusCode);
649 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
650 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
651 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
656 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
659 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
660 dependsOnMethods = {"delete"})
661 public void deleteNonExistent(String testName) throws Exception {
663 if (logger.isDebugEnabled()) {
664 logger.debug(testBanner(testName, CLASS_NAME));
667 setupDeleteNonExistent();
669 // Submit the request to the service and store the response.
670 DimensionClient client = new DimensionClient();
671 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
672 int statusCode = res.getStatus();
674 // Check the status code of the response: does it match
675 // the expected response(s)?
676 if (logger.isDebugEnabled()) {
677 logger.debug(testName + ": status = " + statusCode);
679 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
680 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
681 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
684 // ---------------------------------------------------------------
685 // Utility tests : tests of code used in tests above
686 // ---------------------------------------------------------------
688 * Tests the code for manually submitting data that is used by several
689 * of the methods above.
691 @Test(dependsOnMethods = {"create", "read"})
692 public void testSubmitRequest() {
694 // Expected status code: 200 OK
695 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
697 // Submit the request to the service and store the response.
698 String method = ServiceRequestType.READ.httpMethodName();
699 String url = getResourceURL(knownResourceId);
700 int statusCode = submitRequest(method, url);
702 // Check the status code of the response: does it match
703 // the expected response(s)?
704 if (logger.isDebugEnabled()) {
705 logger.debug("testSubmitRequest: url=" + url
706 + " status=" + statusCode);
708 Assert.assertEquals(statusCode, EXPECTED_STATUS);
712 // ---------------------------------------------------------------
713 // Utility methods used by tests above
714 // ---------------------------------------------------------------
716 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
719 public String getServicePathComponent() {
720 return DimensionClient.SERVICE_PATH_COMPONENT;
724 * Creates the dimension instance.
726 * @param identifier the identifier
727 * @return the multipart output
729 private PoxPayloadOut createDimensionInstance(String commonPartName, String identifier) {
730 return createDimensionInstance(commonPartName,
731 "dimensionType-" + identifier,
732 "entryNumber-" + identifier,
733 "entryDate-" + identifier);
737 * Creates the dimension instance.
739 * @param dimensionType the dimension type
740 * @param entryNumber the entry number
741 * @param entryDate the entry date
742 * @return the multipart output
744 private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String entryNumber, String entryDate) {
745 DimensionsCommon dimensionsCommon = new DimensionsCommon();
746 dimensionsCommon.setDimension(dimensionType);
747 dimensionsCommon.setValue(entryNumber);
748 dimensionsCommon.setValueDate(entryDate);
749 PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
750 commonPartName, dimensionsCommon);
752 if (logger.isDebugEnabled()) {
753 logger.debug("to be created, dimension common");
754 logger.debug(objectAsXmlString(dimensionsCommon,
755 DimensionsCommon.class));
762 protected String createTestObject(String testName) throws Exception {
763 String result = null;
765 DimensionClient client = new DimensionClient();
766 String identifier = createIdentifier();
767 PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
769 ClientResponse<Response> res = client.create(multipart);
771 int statusCode = res.getStatus();
772 Assert.assertEquals(statusCode, STATUS_CREATED);
774 result = extractId(res);
775 allResourceIdsCreated.add(result);
781 * This test assumes that no objects exist yet.
783 * http://localhost:8180/cspace-services/intakes?wf_deleted=false
785 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"})
786 public void readWorkflowList(String testName) throws Exception {
788 // Create 3 new objects
790 final int OBJECTS_TOTAL = 3;
791 for (int i = 0; i < OBJECTS_TOTAL; i++) {
792 this.createWorkflowTarget(testName);
795 // Mark one as soft deleted
797 int currentTotal = allResourceIdsCreated.size();
798 String csid = allResourceIdsCreated.get(currentTotal - 1); //0-based index to get the last one added
800 this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED);
802 // Read the list back. The deleted item should not be in the list
804 // int updatedTotal = readIncludeDeleted(testName, Boolean.FALSE);
805 // Assert.assertEquals(updatedTotal, currentTotal - 1, "Deleted items seem to be returned in list results.");
808 protected void updateLifeCycleState(String testName, String resourceId, String lifeCycleState) throws Exception {
810 // Read the existing object
812 DimensionClient client = new DimensionClient();
813 ClientResponse<String> res = client.getWorkflow(resourceId);
814 assertStatusCode(res, testName);
815 logger.debug("Got object to update life cycle state with ID: " + resourceId);
816 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
817 WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
818 Assert.assertNotNull(workflowCommons);
820 // Mark it for a soft delete.
822 logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class));
823 workflowCommons.setCurrentLifeCycleState(lifeCycleState);
824 PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);
825 PayloadOutputPart commonPart = output.addPart(workflowCommons, MediaType.APPLICATION_XML_TYPE);
826 commonPart.setLabel(WorkflowClient.SERVICE_COMMONPART_NAME);
828 // Perform the update
830 res = client.updateWorkflow(resourceId, output);
831 assertStatusCode(res, testName);
832 input = new PoxPayloadIn(res.getEntity());
833 WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
834 Assert.assertNotNull(updatedWorkflowCommons);
836 // Read the updated object and make sure it was updated correctly.
838 res = client.getWorkflow(resourceId);
839 assertStatusCode(res, testName);
840 logger.debug("Got workflow state of updated object with ID: " + resourceId);
841 input = new PoxPayloadIn(res.getEntity());
842 updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
843 Assert.assertNotNull(workflowCommons);
844 Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);