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.math.BigDecimal;
27 import java.util.List;
28 import javax.ws.rs.core.MediaType;
29 import javax.ws.rs.core.Response;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.DimensionClient;
33 import org.collectionspace.services.client.DimensionFactory;
34 import org.collectionspace.services.client.PayloadInputPart;
35 import org.collectionspace.services.client.PayloadOutputPart;
36 import org.collectionspace.services.client.PoxPayloadIn;
37 import org.collectionspace.services.client.PoxPayloadOut;
38 import org.collectionspace.services.client.workflow.WorkflowClient;
39 import org.collectionspace.services.dimension.DimensionsCommon;
40 import org.collectionspace.services.dimension.DimensionsCommonList;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.collectionspace.services.workflow.WorkflowCommon;
44 import org.jboss.resteasy.client.ClientResponse;
46 import org.testng.Assert;
47 //import org.testng.annotations.AfterClass;
48 import org.testng.annotations.Test;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
54 * DimensionServiceTest, carries out tests against a
55 * deployed and running Dimension Service.
57 * $LastChangedRevision: 917 $
58 * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $
60 public class DimensionServiceTest extends AbstractServiceTestImpl {
63 private final String CLASS_NAME = DimensionServiceTest.class.getName();
64 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
66 // Instance variables specific to this test.
67 /** The SERVIC e_ pat h_ component. */
68 /** The known resource id. */
69 private String knownResourceId = null;
70 private final String DIMENSION_VALUE = "78.306";
73 protected String getServiceName() {
74 return DimensionClient.SERVICE_NAME;
78 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
81 protected CollectionSpaceClient getClientInstance() {
82 return new DimensionClient();
86 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
89 protected AbstractCommonList getAbstractCommonList(
90 ClientResponse<AbstractCommonList> response) {
91 return response.getEntity(DimensionsCommonList.class);
94 // ---------------------------------------------------------------
95 // CRUD tests : CREATE tests
96 // ---------------------------------------------------------------
99 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
102 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
103 public void create(String testName) throws Exception {
105 if (logger.isDebugEnabled()) {
106 logger.debug(testBanner(testName, CLASS_NAME));
108 // Perform setup, such as initializing the type of service request
109 // (e.g. CREATE, DELETE), its valid and expected status codes, and
110 // its associated HTTP method name (e.g. POST, DELETE).
113 // Submit the request to the service and store the response.
114 DimensionClient client = new DimensionClient();
115 String identifier = createIdentifier();
116 PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
118 ClientResponse<Response> res = client.create(multipart);
120 int statusCode = res.getStatus();
122 // Check the status code of the response: does it match
123 // the expected response(s)?
126 // Does it fall within the set of valid status codes?
127 // Does it exactly match the expected status code?
128 if (logger.isDebugEnabled()) {
129 logger.debug(testName + ": status = " + statusCode);
131 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
132 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
133 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
135 // Store the ID returned from the first resource created
136 // for additional tests below.
137 if (knownResourceId == null) {
138 knownResourceId = extractId(res);
139 if (logger.isDebugEnabled()) {
140 logger.debug(testName + ": knownResourceId=" + knownResourceId);
144 // Store the IDs from every resource created by tests,
145 // so they can be deleted after tests have been run.
146 allResourceIdsCreated.add(extractId(res));
150 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
153 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
154 dependsOnMethods = {"create"})
155 public void createList(String testName) throws Exception {
156 for (int i = 0; i < 3; i++) {
162 // Placeholders until the three tests below can be uncommented.
163 // See Issue CSPACE-401.
165 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
168 public void createWithEmptyEntityBody(String testName) throws Exception {
169 //Should this really be empty?
173 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
176 public void createWithMalformedXml(String testName) throws Exception {
177 //Should this really be empty?
181 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
184 public void createWithWrongXmlSchema(String testName) throws Exception {
185 //Should this really be empty?
190 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
191 dependsOnMethods = {"create", "testSubmitRequest"})
192 public void createWithEmptyEntityBody(String testName) throws Exception {
194 if (logger.isDebugEnabled()) {
195 logger.debug(testBanner(testName, CLASS_NAME));
198 setupCreateWithEmptyEntityBody(testName, logger);
200 // Submit the request to the service and store the response.
201 String method = REQUEST_TYPE.httpMethodName();
202 String url = getServiceRootURL();
203 String mediaType = MediaType.APPLICATION_XML;
204 final String entity = "";
205 int statusCode = submitRequest(method, url, mediaType, entity);
207 // Check the status code of the response: does it match
208 // the expected response(s)?
209 if(logger.isDebugEnabled()){
210 logger.debug("createWithEmptyEntityBody url=" + url +
211 " status=" + statusCode);
213 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
214 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
215 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
219 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
220 dependsOnMethods = {"create", "testSubmitRequest"})
221 public void createWithMalformedXml(String testName) throws Exception {
223 if (logger.isDebugEnabled()) {
224 logger.debug(testBanner(testName, CLASS_NAME));
227 setupCreateWithMalformedXml();
229 // Submit the request to the service and store the response.
230 String method = REQUEST_TYPE.httpMethodName();
231 String url = getServiceRootURL();
232 String mediaType = MediaType.APPLICATION_XML;
233 final String entity = MALFORMED_XML_DATA; // Constant from base class.
234 int statusCode = submitRequest(method, url, mediaType, entity);
236 // Check the status code of the response: does it match
237 // the expected response(s)?
238 if(logger.isDebugEnabled()){
239 logger.debug(testName + ": url=" + url +
240 " status=" + statusCode);
242 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
243 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
244 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
248 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
249 dependsOnMethods = {"create", "testSubmitRequest"})
250 public void createWithWrongXmlSchema(String testName) throws Exception {
252 if (logger.isDebugEnabled()) {
253 logger.debug(testBanner(testName, CLASS_NAME));
256 setupCreateWithWrongXmlSchema();
258 // Submit the request to the service and store the response.
259 String method = REQUEST_TYPE.httpMethodName();
260 String url = getServiceRootURL();
261 String mediaType = MediaType.APPLICATION_XML;
262 final String entity = WRONG_XML_SCHEMA_DATA;
263 int statusCode = submitRequest(method, url, mediaType, entity);
265 // Check the status code of the response: does it match
266 // the expected response(s)?
267 if(logger.isDebugEnabled()){
268 logger.debug(testName + ": url=" + url +
269 " status=" + statusCode);
271 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
272 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
273 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
276 // ---------------------------------------------------------------
277 // CRUD tests : READ tests
278 // ---------------------------------------------------------------
281 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
284 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
285 dependsOnMethods = {"create"})
286 public void read(String testName) throws Exception {
288 if (logger.isDebugEnabled()) {
289 logger.debug(testBanner(testName, CLASS_NAME));
294 // Submit the request to the service and store the response.
295 DimensionClient client = new DimensionClient();
296 ClientResponse<String> res = client.read(knownResourceId);
297 assertStatusCode(res, testName);
298 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
299 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
300 DimensionsCommon dimensionsCommon = null;
301 if (payloadInputPart != null) {
302 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
304 Assert.assertNotNull(dimensionsCommon);
309 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
312 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
313 dependsOnMethods = {"read"})
314 public void readNonExistent(String testName) throws Exception {
316 if (logger.isDebugEnabled()) {
317 logger.debug(testBanner(testName, CLASS_NAME));
320 setupReadNonExistent();
322 // Submit the request to the service and store the response.
323 DimensionClient client = new DimensionClient();
324 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
325 int statusCode = res.getStatus();
327 // Check the status code of the response: does it match
328 // the expected response(s)?
329 if (logger.isDebugEnabled()) {
330 logger.debug(testName + ": status = " + statusCode);
332 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
333 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
334 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
337 // ---------------------------------------------------------------
338 // CRUD tests : READ_LIST tests
339 // ---------------------------------------------------------------
342 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
345 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
346 dependsOnMethods = {"read"})
347 public void readList(String testName) throws Exception {
349 if (logger.isDebugEnabled()) {
350 logger.debug(testBanner(testName, CLASS_NAME));
355 // Submit the request to the service and store the response.
356 DimensionClient client = new DimensionClient();
357 ClientResponse<DimensionsCommonList> res = client.readList();
358 assertStatusCode(res, testName);
359 DimensionsCommonList list = res.getEntity();
361 // Optionally output additional data about list members for debugging.
362 boolean iterateThroughList = false;
363 if (iterateThroughList && logger.isDebugEnabled()) {
364 List<DimensionsCommonList.DimensionListItem> items =
365 list.getDimensionListItem();
367 for (DimensionsCommonList.DimensionListItem item : items) {
368 logger.debug(testName + ": list-item[" + i + "] csid="
370 logger.debug(testName + ": list-item[" + i + "] objectNumber="
371 + item.getDimension());
372 logger.debug(testName + ": list-item[" + i + "] URI="
382 // ---------------------------------------------------------------
383 // CRUD tests : UPDATE tests
384 // ---------------------------------------------------------------
387 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
390 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
391 dependsOnMethods = {"read"})
392 public void update(String testName) throws Exception {
394 if (logger.isDebugEnabled()) {
395 logger.debug(testBanner(testName, CLASS_NAME));
400 // Retrieve the contents of a resource to update.
401 DimensionClient client = new DimensionClient();
402 ClientResponse<String> res =
403 client.read(knownResourceId);
404 assertStatusCode(res, testName);
405 if (logger.isDebugEnabled()) {
406 logger.debug("got object to update with ID: " + knownResourceId);
408 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
409 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
410 DimensionsCommon dimensionsCommon = null;
411 if (payloadInputPart != null) {
412 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
414 Assert.assertNotNull(dimensionsCommon);
416 // Update the content of this resource.
417 dimensionsCommon.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0")));
418 dimensionsCommon.setValueDate("updated-" + dimensionsCommon.getValueDate());
419 if (logger.isDebugEnabled()) {
420 logger.debug("to be updated object");
421 logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
423 // Submit the request to the service and store the response.
424 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
425 PayloadOutputPart commonPart = output.addPart(dimensionsCommon, MediaType.APPLICATION_XML_TYPE);
426 commonPart.setLabel(client.getCommonPartName());
428 res = client.update(knownResourceId, output);
429 int statusCode = res.getStatus();
430 assertStatusCode(res, testName);
431 input = new PoxPayloadIn(res.getEntity());
432 DimensionsCommon updatedDimensionsCommon =
433 (DimensionsCommon) extractPart(input,
434 client.getCommonPartName(), DimensionsCommon.class);
435 Assert.assertNotNull(updatedDimensionsCommon);
437 Assert.assertEquals(updatedDimensionsCommon.getValueDate(),
438 dimensionsCommon.getValueDate(),
439 "Data in updated object did not match submitted data.");
444 // Placeholders until the three tests below can be uncommented.
445 // See Issue CSPACE-401.
447 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
450 public void updateWithEmptyEntityBody(String testName) throws Exception {
451 //Should this really be empty?
455 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
458 public void updateWithMalformedXml(String testName) throws Exception {
459 //Should this really be empty?
463 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
466 public void updateWithWrongXmlSchema(String testName) throws Exception {
467 //Should this really be empty?
472 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
473 dependsOnMethods = {"create", "update", "testSubmitRequest"})
474 public void updateWithEmptyEntityBody(String testName) throws Exception {
476 if (logger.isDebugEnabled()) {
477 logger.debug(testBanner(testName, CLASS_NAME));
480 setupUpdateWithEmptyEntityBody();
482 // Submit the request to the service and store the response.
483 String method = REQUEST_TYPE.httpMethodName();
484 String url = getResourceURL(knownResourceId);
485 String mediaType = MediaType.APPLICATION_XML;
486 final String entity = "";
487 int statusCode = submitRequest(method, url, mediaType, entity);
489 // Check the status code of the response: does it match
490 // the expected response(s)?
491 if(logger.isDebugEnabled()){
492 logger.debug(testName + ": url=" + url +
493 " status=" + statusCode);
495 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
496 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
497 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
501 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
502 dependsOnMethods = {"create", "update", "testSubmitRequest"})
503 public void updateWithMalformedXml(String testName) throws Exception {
505 if (logger.isDebugEnabled()) {
506 logger.debug(testBanner(testName, CLASS_NAME));
509 setupUpdateWithMalformedXml(testName, logger);
511 // Submit the request to the service and store the response.
512 String method = REQUEST_TYPE.httpMethodName();
513 String url = getResourceURL(knownResourceId);
514 String mediaType = MediaType.APPLICATION_XML;
515 final String entity = MALFORMED_XML_DATA;
516 int statusCode = submitRequest(method, url, mediaType, entity);
518 // Check the status code of the response: does it match
519 // the expected response(s)?
520 if(logger.isDebugEnabled()){
521 logger.debug(testName + ": url=" + url +
522 " status=" + statusCode);
524 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
525 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
526 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
530 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
531 dependsOnMethods = {"create", "update", "testSubmitRequest"})
532 public void updateWithWrongXmlSchema(String testName) throws Exception {
534 if (logger.isDebugEnabled()) {
535 logger.debug(testBanner(testName, CLASS_NAME));
538 setupUpdateWithWrongXmlSchema(testName, logger);
540 // Submit the request to the service and store the response.
541 String method = REQUEST_TYPE.httpMethodName();
542 String url = getResourceURL(knownResourceId);
543 String mediaType = MediaType.APPLICATION_XML;
544 final String entity = WRONG_XML_SCHEMA_DATA;
545 int statusCode = submitRequest(method, url, mediaType, entity);
547 // Check the status code of the response: does it match
548 // the expected response(s)?
549 if(logger.isDebugEnabled()){
550 logger.debug(testName + ": url=" + url +
551 " status=" + statusCode);
553 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
554 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
555 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
560 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
563 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
564 dependsOnMethods = {"update", "testSubmitRequest"})
565 public void updateNonExistent(String testName) throws Exception {
567 if (logger.isDebugEnabled()) {
568 logger.debug(testBanner(testName, CLASS_NAME));
571 setupUpdateNonExistent();
573 // Submit the request to the service and store the response.
574 // Note: The ID used in this 'create' call may be arbitrary.
575 // The only relevant ID may be the one used in update(), below.
576 DimensionClient client = new DimensionClient();
577 PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
579 ClientResponse<String> res =
580 client.update(NON_EXISTENT_ID, multipart);
581 int statusCode = res.getStatus();
583 // Check the status code of the response: does it match
584 // the expected response(s)?
585 if (logger.isDebugEnabled()) {
586 logger.debug(testName + ": status = " + statusCode);
588 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
589 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
590 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
593 // ---------------------------------------------------------------
594 // CRUD tests : DELETE tests
595 // ---------------------------------------------------------------
598 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
601 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
602 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "readWorkflow"})
603 public void delete(String testName) throws Exception {
605 if (logger.isDebugEnabled()) {
606 logger.debug(testBanner(testName, CLASS_NAME));
611 // Submit the request to the service and store the response.
612 DimensionClient client = new DimensionClient();
613 ClientResponse<Response> res = client.delete(knownResourceId);
614 int statusCode = res.getStatus();
616 // Check the status code of the response: does it match
617 // the expected response(s)?
618 if (logger.isDebugEnabled()) {
619 logger.debug(testName + ": status = " + statusCode);
621 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
628 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
631 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
632 dependsOnMethods = {"delete"})
633 public void deleteNonExistent(String testName) throws Exception {
635 if (logger.isDebugEnabled()) {
636 logger.debug(testBanner(testName, CLASS_NAME));
639 setupDeleteNonExistent();
641 // Submit the request to the service and store the response.
642 DimensionClient client = new DimensionClient();
643 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
644 int statusCode = res.getStatus();
646 // Check the status code of the response: does it match
647 // the expected response(s)?
648 if (logger.isDebugEnabled()) {
649 logger.debug(testName + ": status = " + statusCode);
651 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
652 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
653 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
656 // ---------------------------------------------------------------
658 // ---------------------------------------------------------------
661 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
662 public void searchWorkflowDeleted(String testName) throws Exception {
663 // Fixme: null test for now, overriding test in base class
666 // ---------------------------------------------------------------
667 // Utility tests : tests of code used in tests above
668 // ---------------------------------------------------------------
670 * Tests the code for manually submitting data that is used by several
671 * of the methods above.
673 @Test(dependsOnMethods = {"create", "read"})
674 public void testSubmitRequest() {
676 // Expected status code: 200 OK
677 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
679 // Submit the request to the service and store the response.
680 String method = ServiceRequestType.READ.httpMethodName();
681 String url = getResourceURL(knownResourceId);
682 int statusCode = submitRequest(method, url);
684 // Check the status code of the response: does it match
685 // the expected response(s)?
686 if (logger.isDebugEnabled()) {
687 logger.debug("testSubmitRequest: url=" + url
688 + " status=" + statusCode);
690 Assert.assertEquals(statusCode, EXPECTED_STATUS);
694 // ---------------------------------------------------------------
695 // Utility methods used by tests above
696 // ---------------------------------------------------------------
698 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
701 public String getServicePathComponent() {
702 return DimensionClient.SERVICE_PATH_COMPONENT;
706 protected PoxPayloadOut createInstance(String identifier) {
707 DimensionClient client = new DimensionClient();
708 return createDimensionInstance(client.getCommonPartName(), identifier);
712 * Creates the dimension instance.
714 * @param identifier the identifier
715 * @return the multipart output
717 private PoxPayloadOut createDimensionInstance(String commonPartName, String identifier) {
718 return createDimensionInstance(commonPartName,
719 "dimensionType-" + identifier,
721 "entryDate-" + identifier);
725 * Creates the dimension instance.
727 * @param dimensionType the dimension type
728 * @param entryNumber the entry number
729 * @param entryDate the entry date
730 * @return the multipart output
732 private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) {
733 DimensionsCommon dimensionsCommon = new DimensionsCommon();
734 dimensionsCommon.setDimension(dimensionType);
735 dimensionsCommon.setValue(new BigDecimal(dimensionValue));
736 dimensionsCommon.setValueDate(entryDate);
737 PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
738 commonPartName, dimensionsCommon);
740 if (logger.isDebugEnabled()) {
741 logger.debug("to be created, dimension common");
742 logger.debug(objectAsXmlString(dimensionsCommon,
743 DimensionsCommon.class));
750 // protected String createTestObject(String testName) throws Exception {
751 // String result = null;
753 // DimensionClient client = new DimensionClient();
754 // String identifier = createIdentifier();
755 // PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
757 // ClientResponse<Response> res = client.create(multipart);
759 // int statusCode = res.getStatus();
760 // Assert.assertEquals(statusCode, STATUS_CREATED);
762 // result = extractId(res);
763 // allResourceIdsCreated.add(result);
769 // * This test assumes that no objects exist yet.
771 // * http://localhost:8180/cspace-services/intakes?wf_deleted=false
773 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"})
774 // public void readWorkflowList(String testName) throws Exception {
776 // // Create 3 new objects
778 // final int OBJECTS_TOTAL = 3;
779 // for (int i = 0; i < OBJECTS_TOTAL; i++) {
780 // this.createWorkflowTarget(testName);
783 // // Mark one as soft deleted
785 // int currentTotal = allResourceIdsCreated.size();
786 // String csid = allResourceIdsCreated.get(currentTotal - 1); //0-based index to get the last one added
787 // this.setupUpdate();
788 // this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED);
790 // // Read the list back. The deleted item should not be in the list
792 //// int updatedTotal = readIncludeDeleted(testName, Boolean.FALSE);
793 //// Assert.assertEquals(updatedTotal, currentTotal - 1, "Deleted items seem to be returned in list results.");
796 protected void updateLifeCycleState(String testName, String resourceId, String lifeCycleState) throws Exception {
798 // Read the existing object
800 DimensionClient client = new DimensionClient();
801 ClientResponse<String> res = client.getWorkflow(resourceId);
802 assertStatusCode(res, testName);
803 logger.debug("Got object to update life cycle state with ID: " + resourceId);
804 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
805 WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
806 Assert.assertNotNull(workflowCommons);
808 // Mark it for a soft delete.
810 logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class));
811 workflowCommons.setCurrentLifeCycleState(lifeCycleState);
812 PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);
813 PayloadOutputPart commonPart = output.addPart(workflowCommons, MediaType.APPLICATION_XML_TYPE);
814 commonPart.setLabel(WorkflowClient.SERVICE_COMMONPART_NAME);
816 // Perform the update
818 res = client.updateWorkflow(resourceId, output);
819 assertStatusCode(res, testName);
820 input = new PoxPayloadIn(res.getEntity());
821 WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
822 Assert.assertNotNull(updatedWorkflowCommons);
824 // Read the updated object and make sure it was updated correctly.
826 res = client.getWorkflow(resourceId);
827 assertStatusCode(res, testName);
828 logger.debug("Got workflow state of updated object with ID: " + resourceId);
829 input = new PoxPayloadIn(res.getEntity());
830 updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
831 Assert.assertNotNull(workflowCommons);
832 Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);