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 int statusCode = res.getStatus();
299 // Check the status code of the response: does it match
300 // the expected response(s)?
301 if (logger.isDebugEnabled()) {
302 logger.debug(testName + ": status = " + statusCode);
304 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
305 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
306 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
308 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
309 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
310 DimensionsCommon dimensionsCommon = null;
311 if (payloadInputPart != null) {
312 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
314 Assert.assertNotNull(dimensionsCommon);
319 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
322 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
323 dependsOnMethods = {"read"})
324 public void readNonExistent(String testName) throws Exception {
326 if (logger.isDebugEnabled()) {
327 logger.debug(testBanner(testName, CLASS_NAME));
330 setupReadNonExistent();
332 // Submit the request to the service and store the response.
333 DimensionClient client = new DimensionClient();
334 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
335 int statusCode = res.getStatus();
337 // Check the status code of the response: does it match
338 // the expected response(s)?
339 if (logger.isDebugEnabled()) {
340 logger.debug(testName + ": status = " + statusCode);
342 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
343 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
344 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
347 // ---------------------------------------------------------------
348 // CRUD tests : READ_LIST tests
349 // ---------------------------------------------------------------
352 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
355 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
356 dependsOnMethods = {"read"})
357 public void readList(String testName) throws Exception {
359 if (logger.isDebugEnabled()) {
360 logger.debug(testBanner(testName, CLASS_NAME));
365 // Submit the request to the service and store the response.
366 DimensionClient client = new DimensionClient();
367 ClientResponse<DimensionsCommonList> res = client.readList();
368 DimensionsCommonList list = res.getEntity();
369 int statusCode = res.getStatus();
371 // Check the status code of the response: does it match
372 // the expected response(s)?
373 if (logger.isDebugEnabled()) {
374 logger.debug(testName + ": status = " + statusCode);
376 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
377 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
378 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
380 // Optionally output additional data about list members for debugging.
381 boolean iterateThroughList = false;
382 if (iterateThroughList && logger.isDebugEnabled()) {
383 List<DimensionsCommonList.DimensionListItem> items =
384 list.getDimensionListItem();
386 for (DimensionsCommonList.DimensionListItem item : items) {
387 logger.debug(testName + ": list-item[" + i + "] csid="
389 logger.debug(testName + ": list-item[" + i + "] objectNumber="
390 + item.getDimension());
391 logger.debug(testName + ": list-item[" + i + "] URI="
401 // ---------------------------------------------------------------
402 // CRUD tests : UPDATE tests
403 // ---------------------------------------------------------------
406 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
409 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
410 dependsOnMethods = {"read"})
411 public void update(String testName) throws Exception {
413 if (logger.isDebugEnabled()) {
414 logger.debug(testBanner(testName, CLASS_NAME));
419 // Retrieve the contents of a resource to update.
420 DimensionClient client = new DimensionClient();
421 ClientResponse<String> res =
422 client.read(knownResourceId);
423 if (logger.isDebugEnabled()) {
424 logger.debug(testName + ": read status = " + res.getStatus());
426 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
428 if (logger.isDebugEnabled()) {
429 logger.debug("got object to update with ID: " + knownResourceId);
431 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
432 PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
433 DimensionsCommon dimensionsCommon = null;
434 if (payloadInputPart != null) {
435 dimensionsCommon = (DimensionsCommon) payloadInputPart.getBody();
437 Assert.assertNotNull(dimensionsCommon);
439 // Update the content of this resource.
440 dimensionsCommon.setValue(dimensionsCommon.getValue().multiply(new BigDecimal("2.0")));
441 dimensionsCommon.setValueDate("updated-" + dimensionsCommon.getValueDate());
442 if (logger.isDebugEnabled()) {
443 logger.debug("to be updated object");
444 logger.debug(objectAsXmlString(dimensionsCommon, DimensionsCommon.class));
446 // Submit the request to the service and store the response.
447 PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
448 PayloadOutputPart commonPart = output.addPart(dimensionsCommon, MediaType.APPLICATION_XML_TYPE);
449 commonPart.setLabel(client.getCommonPartName());
451 res = client.update(knownResourceId, output);
452 int statusCode = res.getStatus();
453 // Check the status code of the response: does it match the expected response(s)?
454 if (logger.isDebugEnabled()) {
455 logger.debug(testName + ": status = " + statusCode);
457 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
458 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
459 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
461 input = new PoxPayloadIn(res.getEntity());
462 DimensionsCommon updatedDimensionsCommon =
463 (DimensionsCommon) extractPart(input,
464 client.getCommonPartName(), DimensionsCommon.class);
465 Assert.assertNotNull(updatedDimensionsCommon);
467 Assert.assertEquals(updatedDimensionsCommon.getValueDate(),
468 dimensionsCommon.getValueDate(),
469 "Data in updated object did not match submitted data.");
474 // Placeholders until the three tests below can be uncommented.
475 // See Issue CSPACE-401.
477 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
480 public void updateWithEmptyEntityBody(String testName) throws Exception {
481 //Should this really be empty?
485 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
488 public void updateWithMalformedXml(String testName) throws Exception {
489 //Should this really be empty?
493 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
496 public void updateWithWrongXmlSchema(String testName) throws Exception {
497 //Should this really be empty?
502 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
503 dependsOnMethods = {"create", "update", "testSubmitRequest"})
504 public void updateWithEmptyEntityBody(String testName) throws Exception {
506 if (logger.isDebugEnabled()) {
507 logger.debug(testBanner(testName, CLASS_NAME));
510 setupUpdateWithEmptyEntityBody();
512 // Submit the request to the service and store the response.
513 String method = REQUEST_TYPE.httpMethodName();
514 String url = getResourceURL(knownResourceId);
515 String mediaType = MediaType.APPLICATION_XML;
516 final String entity = "";
517 int statusCode = submitRequest(method, url, mediaType, entity);
519 // Check the status code of the response: does it match
520 // the expected response(s)?
521 if(logger.isDebugEnabled()){
522 logger.debug(testName + ": url=" + url +
523 " status=" + statusCode);
525 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
526 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
527 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
531 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
532 dependsOnMethods = {"create", "update", "testSubmitRequest"})
533 public void updateWithMalformedXml(String testName) throws Exception {
535 if (logger.isDebugEnabled()) {
536 logger.debug(testBanner(testName, CLASS_NAME));
539 setupUpdateWithMalformedXml(testName, logger);
541 // Submit the request to the service and store the response.
542 String method = REQUEST_TYPE.httpMethodName();
543 String url = getResourceURL(knownResourceId);
544 String mediaType = MediaType.APPLICATION_XML;
545 final String entity = MALFORMED_XML_DATA;
546 int statusCode = submitRequest(method, url, mediaType, entity);
548 // Check the status code of the response: does it match
549 // the expected response(s)?
550 if(logger.isDebugEnabled()){
551 logger.debug(testName + ": url=" + url +
552 " status=" + statusCode);
554 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
555 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
556 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
560 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
561 dependsOnMethods = {"create", "update", "testSubmitRequest"})
562 public void updateWithWrongXmlSchema(String testName) throws Exception {
564 if (logger.isDebugEnabled()) {
565 logger.debug(testBanner(testName, CLASS_NAME));
568 setupUpdateWithWrongXmlSchema(testName, logger);
570 // Submit the request to the service and store the response.
571 String method = REQUEST_TYPE.httpMethodName();
572 String url = getResourceURL(knownResourceId);
573 String mediaType = MediaType.APPLICATION_XML;
574 final String entity = WRONG_XML_SCHEMA_DATA;
575 int statusCode = submitRequest(method, url, mediaType, entity);
577 // Check the status code of the response: does it match
578 // the expected response(s)?
579 if(logger.isDebugEnabled()){
580 logger.debug(testName + ": url=" + url +
581 " status=" + statusCode);
583 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
584 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
585 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
590 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
593 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
594 dependsOnMethods = {"update", "testSubmitRequest"})
595 public void updateNonExistent(String testName) throws Exception {
597 if (logger.isDebugEnabled()) {
598 logger.debug(testBanner(testName, CLASS_NAME));
601 setupUpdateNonExistent();
603 // Submit the request to the service and store the response.
604 // Note: The ID used in this 'create' call may be arbitrary.
605 // The only relevant ID may be the one used in update(), below.
606 DimensionClient client = new DimensionClient();
607 PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
609 ClientResponse<String> res =
610 client.update(NON_EXISTENT_ID, multipart);
611 int statusCode = res.getStatus();
613 // Check the status code of the response: does it match
614 // the expected response(s)?
615 if (logger.isDebugEnabled()) {
616 logger.debug(testName + ": status = " + statusCode);
618 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
619 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
620 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
623 // ---------------------------------------------------------------
624 // CRUD tests : DELETE tests
625 // ---------------------------------------------------------------
628 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
631 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
632 dependsOnMethods = {"create", "readList", "testSubmitRequest", "update", "readWorkflow"})
633 public void delete(String testName) throws Exception {
635 if (logger.isDebugEnabled()) {
636 logger.debug(testBanner(testName, CLASS_NAME));
641 // Submit the request to the service and store the response.
642 DimensionClient client = new DimensionClient();
643 ClientResponse<Response> res = client.delete(knownResourceId);
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);
658 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
661 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
662 dependsOnMethods = {"delete"})
663 public void deleteNonExistent(String testName) throws Exception {
665 if (logger.isDebugEnabled()) {
666 logger.debug(testBanner(testName, CLASS_NAME));
669 setupDeleteNonExistent();
671 // Submit the request to the service and store the response.
672 DimensionClient client = new DimensionClient();
673 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
674 int statusCode = res.getStatus();
676 // Check the status code of the response: does it match
677 // the expected response(s)?
678 if (logger.isDebugEnabled()) {
679 logger.debug(testName + ": status = " + statusCode);
681 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
682 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
683 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
686 // ---------------------------------------------------------------
688 // ---------------------------------------------------------------
691 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
692 public void searchWorkflowDeleted(String testName) throws Exception {
693 // Fixme: null test for now, overriding test in base class
696 // ---------------------------------------------------------------
697 // Utility tests : tests of code used in tests above
698 // ---------------------------------------------------------------
700 * Tests the code for manually submitting data that is used by several
701 * of the methods above.
703 @Test(dependsOnMethods = {"create", "read"})
704 public void testSubmitRequest() {
706 // Expected status code: 200 OK
707 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
709 // Submit the request to the service and store the response.
710 String method = ServiceRequestType.READ.httpMethodName();
711 String url = getResourceURL(knownResourceId);
712 int statusCode = submitRequest(method, url);
714 // Check the status code of the response: does it match
715 // the expected response(s)?
716 if (logger.isDebugEnabled()) {
717 logger.debug("testSubmitRequest: url=" + url
718 + " status=" + statusCode);
720 Assert.assertEquals(statusCode, EXPECTED_STATUS);
724 // ---------------------------------------------------------------
725 // Utility methods used by tests above
726 // ---------------------------------------------------------------
728 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
731 public String getServicePathComponent() {
732 return DimensionClient.SERVICE_PATH_COMPONENT;
736 protected PoxPayloadOut createInstance(String identifier) {
737 DimensionClient client = new DimensionClient();
738 return createDimensionInstance(client.getCommonPartName(), identifier);
742 * Creates the dimension instance.
744 * @param identifier the identifier
745 * @return the multipart output
747 private PoxPayloadOut createDimensionInstance(String commonPartName, String identifier) {
748 return createDimensionInstance(commonPartName,
749 "dimensionType-" + identifier,
751 "entryDate-" + identifier);
755 * Creates the dimension instance.
757 * @param dimensionType the dimension type
758 * @param entryNumber the entry number
759 * @param entryDate the entry date
760 * @return the multipart output
762 private PoxPayloadOut createDimensionInstance(String commonPartName, String dimensionType, String dimensionValue, String entryDate) {
763 DimensionsCommon dimensionsCommon = new DimensionsCommon();
764 dimensionsCommon.setDimension(dimensionType);
765 dimensionsCommon.setValue(new BigDecimal(dimensionValue));
766 dimensionsCommon.setValueDate(entryDate);
767 PoxPayloadOut multipart = DimensionFactory.createDimensionInstance(
768 commonPartName, dimensionsCommon);
770 if (logger.isDebugEnabled()) {
771 logger.debug("to be created, dimension common");
772 logger.debug(objectAsXmlString(dimensionsCommon,
773 DimensionsCommon.class));
780 // protected String createTestObject(String testName) throws Exception {
781 // String result = null;
783 // DimensionClient client = new DimensionClient();
784 // String identifier = createIdentifier();
785 // PoxPayloadOut multipart = createDimensionInstance(client.getCommonPartName(),
787 // ClientResponse<Response> res = client.create(multipart);
789 // int statusCode = res.getStatus();
790 // Assert.assertEquals(statusCode, STATUS_CREATED);
792 // result = extractId(res);
793 // allResourceIdsCreated.add(result);
799 // * This test assumes that no objects exist yet.
801 // * http://localhost:8180/cspace-services/intakes?wf_deleted=false
803 // @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, dependsOnMethods = {"update"})
804 // public void readWorkflowList(String testName) throws Exception {
806 // // Create 3 new objects
808 // final int OBJECTS_TOTAL = 3;
809 // for (int i = 0; i < OBJECTS_TOTAL; i++) {
810 // this.createWorkflowTarget(testName);
813 // // Mark one as soft deleted
815 // int currentTotal = allResourceIdsCreated.size();
816 // String csid = allResourceIdsCreated.get(currentTotal - 1); //0-based index to get the last one added
817 // this.setupUpdate();
818 // this.updateLifeCycleState(testName, csid, WorkflowClient.WORKFLOWSTATE_DELETED);
820 // // Read the list back. The deleted item should not be in the list
822 //// int updatedTotal = readIncludeDeleted(testName, Boolean.FALSE);
823 //// Assert.assertEquals(updatedTotal, currentTotal - 1, "Deleted items seem to be returned in list results.");
826 protected void updateLifeCycleState(String testName, String resourceId, String lifeCycleState) throws Exception {
828 // Read the existing object
830 DimensionClient client = new DimensionClient();
831 ClientResponse<String> res = client.getWorkflow(resourceId);
832 assertStatusCode(res, testName);
833 logger.debug("Got object to update life cycle state with ID: " + resourceId);
834 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
835 WorkflowCommon workflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
836 Assert.assertNotNull(workflowCommons);
838 // Mark it for a soft delete.
840 logger.debug("Current workflow state:" + objectAsXmlString(workflowCommons, WorkflowCommon.class));
841 workflowCommons.setCurrentLifeCycleState(lifeCycleState);
842 PoxPayloadOut output = new PoxPayloadOut(WorkflowClient.SERVICE_PAYLOAD_NAME);
843 PayloadOutputPart commonPart = output.addPart(workflowCommons, MediaType.APPLICATION_XML_TYPE);
844 commonPart.setLabel(WorkflowClient.SERVICE_COMMONPART_NAME);
846 // Perform the update
848 res = client.updateWorkflow(resourceId, output);
849 assertStatusCode(res, testName);
850 input = new PoxPayloadIn(res.getEntity());
851 WorkflowCommon updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
852 Assert.assertNotNull(updatedWorkflowCommons);
854 // Read the updated object and make sure it was updated correctly.
856 res = client.getWorkflow(resourceId);
857 assertStatusCode(res, testName);
858 logger.debug("Got workflow state of updated object with ID: " + resourceId);
859 input = new PoxPayloadIn(res.getEntity());
860 updatedWorkflowCommons = (WorkflowCommon) extractPart(input, WorkflowClient.SERVICE_COMMONPART_NAME, WorkflowCommon.class);
861 Assert.assertNotNull(workflowCommons);
862 Assert.assertEquals(updatedWorkflowCommons.getCurrentLifeCycleState(), lifeCycleState);