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 (c) 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.AbstractCommonListUtils;
31 import org.collectionspace.services.client.AcquisitionClient;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.PayloadOutputPart;
34 import org.collectionspace.services.client.PoxPayloadIn;
35 import org.collectionspace.services.client.PoxPayloadOut;
36 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
37 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.acquisition.AcquisitionsCommon;
39 import org.collectionspace.services.acquisition.AcquisitionDateGroupList;
40 import org.collectionspace.services.acquisition.AcquisitionSourceList;
41 import org.collectionspace.services.acquisition.OwnerList;
42 import org.collectionspace.services.acquisition.StructuredDateGroup;
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
50 * AcquisitionServiceTest, carries out tests against a
51 * deployed and running Acquisition Service.
53 * $LastChangedRevision: 621 $
54 * $LastChangedDate: 2009-09-02 16:49:01 -0700 (Wed, 02 Sep 2009) $
56 public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, AcquisitionsCommon> {
59 private final String CLASS_NAME = AcquisitionServiceTest.class.getName();
60 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
62 // Instance variables specific to this test.
63 private final static String CURRENT_DATE_UTC =
64 GregorianCalendarDateTimeUtils.timestampUTC();
67 public String getServicePathComponent() {
68 return AcquisitionClient.SERVICE_PATH_COMPONENT;
72 protected String getServiceName() {
73 return AcquisitionClient.SERVICE_NAME;
77 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
80 protected CollectionSpaceClient getClientInstance() {
81 return new AcquisitionClient();
85 protected CollectionSpaceClient getClientInstance(String clientPropertiesFilename) {
86 return new AcquisitionClient(clientPropertiesFilename);
89 // ---------------------------------------------------------------
90 // CRUD tests : CREATE tests
91 // ---------------------------------------------------------------
94 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
97 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
98 public void create(String testName) throws Exception {
99 // Perform setup, such as initializing the type of service request
100 // (e.g. CREATE, DELETE), its valid and expected status codes, and
101 // its associated HTTP method name (e.g. POST, DELETE).
104 // Submit the request to the service and store the response.
105 String identifier = createIdentifier();
107 AcquisitionClient client = new AcquisitionClient();
108 PoxPayloadOut multipart = createAcquisitionInstance(identifier);
109 Response res = client.create(multipart);
111 int statusCode = res.getStatus();
113 // Check the status code of the response: does it match
114 // the expected response(s)?
117 // Does it fall within the set of valid status codes?
118 // Does it exactly match the expected status code?
119 if(logger.isDebugEnabled()){
120 logger.debug(testName + ": status = " + statusCode);
122 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
123 invalidStatusCodeMessage(testRequestType, statusCode));
124 Assert.assertEquals(statusCode, testExpectedStatusCode);
126 // Store the ID returned from the first resource created
127 // for additional tests below.
128 if (knownResourceId == null){
129 knownResourceId = extractId(res);
130 if (logger.isDebugEnabled()) {
131 logger.debug(testName + ": knownResourceId=" + knownResourceId);
135 // Store the IDs from every resource created by tests,
136 // so they can be deleted after tests have been run.
137 allResourceIdsCreated.add(extractId(res));
141 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
144 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
145 // dependsOnMethods = {"create"})
146 public void createList(String testName) throws Exception {
147 for(int i = 0; i < 3; i++){
153 * Tests to diagnose and fix CSPACE-2578.
155 * This is a bug identified in release 1.0 alpha, after first implementing an
156 * Acquisition Funding repeatable group of fields, in which record creation
157 * fails if there is whitespace (or more generally, a text node) between
158 * the acquisitionFunding container element and its first child field.
161 // Verify that record creation occurs successfully when there is NO whitespace
162 // between the acquisitionFunding tag and its first child element tag
163 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
164 dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"})
165 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
166 String testDataDir = System.getProperty("test-data.fileName");
168 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
169 testSubmitRequest(newId);
172 // Verify that record creation occurs successfully when there is whitespace
173 // between the acquisitionFunding tag and its first child element tag
175 // FIXME: This test currently fails. @Test annotation is currently commented
176 // out for check-in, to prevent service tests from failing. Can uncomment to test
177 // fixes, and also after the issue is resolved, to help detect any regressions.
179 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
180 dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"})
181 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
182 String testDataDir = System.getProperty("test-data.fileName");
184 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
185 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
186 testSubmitRequest(newId);
191 // Placeholders until the three tests below can be uncommented.
192 // See Issue CSPACE-401.
194 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
197 public void createWithEmptyEntityBody(String testName) throws Exception {
198 //Should this really be empty?
202 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
205 public void createWithMalformedXml(String testName) throws Exception {
206 //Should this really be empty?
210 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
213 public void createWithWrongXmlSchema(String testName) throws Exception {
214 //Should this really be empty?
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));
228 setupCreateWithMalformedXml();
230 // Submit the request to the service and store the response.
231 String method = REQUEST_TYPE.httpMethodName();
232 String url = getServiceRootURL();
233 final String entity = MALFORMED_XML_DATA; // Constant from base class.
234 int statusCode = submitRequest(method, url, 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));
257 setupCreateWithWrongXmlSchema();
259 // Submit the request to the service and store the response.
260 String method = REQUEST_TYPE.httpMethodName();
261 String url = getServiceRootURL();
262 final String entity = WRONG_XML_SCHEMA_DATA;
263 int statusCode = submitRequest(method, url, 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);
277 // ---------------------------------------------------------------
278 // CRUD tests : READ tests
279 // ---------------------------------------------------------------
282 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
285 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
286 // dependsOnMethods = {"create"})
287 public void read(String testName) throws Exception {
291 AcquisitionClient client = new AcquisitionClient();
293 // Submit the request to the service and store the response.
294 Response res = client.read(knownResourceId);
295 PoxPayloadIn input = null;
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(testRequestType.isValidStatusCode(statusCode),
305 invalidStatusCodeMessage(testRequestType, statusCode));
306 Assert.assertEquals(statusCode, testExpectedStatusCode);
308 input = new PoxPayloadIn(res.readEntity(String.class));
313 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
314 client.getCommonPartName(), AcquisitionsCommon.class);
315 Assert.assertNotNull(acquisitionObject);
317 // Verify the number and contents of values in repeatable fields,
318 // as created in the instance record used for testing.
319 List<String> acqSources = acquisitionObject.getAcquisitionSources().getAcquisitionSource();
320 Assert.assertTrue(acqSources.size() > 0);
321 Assert.assertNotNull(acqSources.get(0));
323 List<StructuredDateGroup> acqDates = acquisitionObject.getAcquisitionDateGroupList().getAcquisitionDateGroup();
324 Assert.assertTrue(acqDates.size() > 0);
325 Assert.assertNotNull(acqDates.get(0));
327 List<String> owners =
328 acquisitionObject.getOwners().getOwner();
329 Assert.assertTrue(owners.size() > 0);
330 Assert.assertNotNull(owners.get(0));
335 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
338 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
339 // dependsOnMethods = {"read"})
340 public void readNonExistent(String testName) throws Exception {
342 setupReadNonExistent();
344 // Submit the request to the service and store the response.
345 AcquisitionClient client = new AcquisitionClient();
346 Response res = client.read(NON_EXISTENT_ID);
347 int statusCode = res.getStatus();
349 // Check the status code of the response: does it match
350 // the expected response(s)?
351 if(logger.isDebugEnabled()){
352 logger.debug(testName + ": status = " + statusCode);
354 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
355 invalidStatusCodeMessage(testRequestType, statusCode));
356 Assert.assertEquals(statusCode, testExpectedStatusCode);
359 // ---------------------------------------------------------------
360 // CRUD tests : READ_LIST tests
361 // ---------------------------------------------------------------
364 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
367 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
368 // dependsOnMethods = {"createList", "read"})
369 public void readList(String testName) throws Exception {
373 // Submit the request to the service and store the response.
374 AcquisitionClient client = new AcquisitionClient();
375 Response res = client.readList();
377 // Check the status code of the response: does it match
378 // the expected response(s)?
379 assertStatusCode(res, testName);
380 AbstractCommonList list = res.readEntity(this.getCommonListType());
382 // Optionally output additional data about list members for debugging.
383 if (logger.isTraceEnabled() == true){
384 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
396 // ---------------------------------------------------------------
397 // CRUD tests : UPDATE tests
398 // ---------------------------------------------------------------
402 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
405 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
406 // dependsOnMethods = {"read"})
407 public void update(String testName) throws Exception {
411 // Retrieve the contents of a resource to update.
412 AcquisitionClient client = new AcquisitionClient();
413 Response res = client.read(knownResourceId);
414 PoxPayloadIn input = null;
416 if(logger.isDebugEnabled()){
417 logger.debug(testName + ": read status = " + res.getStatus());
419 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
421 input = new PoxPayloadIn(res.readEntity(String.class));
426 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
427 client.getCommonPartName(), AcquisitionsCommon.class);
428 Assert.assertNotNull(acquisition);
430 // Update the content of this resource.
431 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
432 if(logger.isDebugEnabled()){
433 logger.debug("updated object");
434 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
436 // Submit the request to the service and store the response.
437 PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
438 PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
439 commonPart.setLabel(client.getCommonPartName());
441 res = client.update(knownResourceId, output);
443 int statusCode = res.getStatus();
444 // Check the status code of the response: does it match the expected response(s)?
445 if(logger.isDebugEnabled()){
446 logger.debug(testName + ": status = " + statusCode);
448 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
449 invalidStatusCodeMessage(testRequestType, statusCode));
450 Assert.assertEquals(statusCode, testExpectedStatusCode);
452 input = new PoxPayloadIn(res.readEntity(String.class));
453 AcquisitionsCommon updatedAcquisition =
454 (AcquisitionsCommon) extractPart(input,
455 client.getCommonPartName(), AcquisitionsCommon.class);
456 Assert.assertNotNull(updatedAcquisition);
458 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
459 acquisition.getAcquisitionReferenceNumber(),
460 "Data in updated object did not match submitted data.");
468 // Placeholders until the three tests below can be uncommented.
469 // See Issue CSPACE-401.
471 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
474 public void updateWithEmptyEntityBody(String testName) throws Exception {
475 //Should this really be empty?
479 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
482 public void updateWithMalformedXml(String testName) throws Exception {
483 //Should this really be empty?
487 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
490 public void updateWithWrongXmlSchema(String testName) throws Exception {
491 //Should this really be empty?
496 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
497 dependsOnMethods = {"create", "update", "testSubmitRequest"})
498 public void updateWithEmptyEntityBody(String testName) throws Exception {
500 if (logger.isDebugEnabled()) {
501 logger.debug(testBanner(testName, CLASS_NAME));
505 setupUpdateWithEmptyEntityBody();
507 // Submit the request to the service and store the response.
508 String method = REQUEST_TYPE.httpMethodName();
509 String url = getResourceURL(knownResourceId);
510 String mediaType = MediaType.APPLICATION_XML;
511 final String entity = "";
512 int statusCode = submitRequest(method, url, mediaType, entity);
514 // Check the status code of the response: does it match
515 // the expected response(s)?
516 if(logger.isDebugEnabled()){
517 (testName + ": url=" + url + " status=" + statusCode);
519 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
520 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
521 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
525 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
526 dependsOnMethods = {"create", "testSubmitRequest"})
527 public void createWithEmptyEntityBody(String testName) throws Exception {
529 if (logger.isDebugEnabled()) {
530 logger.debug(testBanner(testName, CLASS_NAME));
534 setupCreateWithEmptyEntityBody();
536 // Submit the request to the service and store the response.
537 String method = REQUEST_TYPE.httpMethodName();
538 String url = getServiceRootURL();
539 String mediaType = MediaType.APPLICATION_XML;
540 final String entity = "";
541 int statusCode = submitRequest(method, url, mediaType, entity);
543 // Check the status code of the response: does it match
544 // the expected response(s)?
545 if(logger.isDebugEnabled()){
546 logger.debug(testName + ": url=" + url +
547 " status=" + statusCode);
549 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
550 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
551 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
555 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
556 dependsOnMethods = {"create", "update", "testSubmitRequest"})
557 public void updateWithMalformedXml(String testName) throws Exception {
559 if (logger.isDebugEnabled()) {
560 logger.debug(testBanner(testName, CLASS_NAME));
564 setupUpdateWithMalformedXml();
566 // Submit the request to the service and store the response.
567 String method = REQUEST_TYPE.httpMethodName();
568 String url = getResourceURL(knownResourceId);
569 final String entity = MALFORMED_XML_DATA;
570 int statusCode = submitRequest(method, url, entity);
572 // Check the status code of the response: does it match
573 // the expected response(s)?
574 if(logger.isDebugEnabled()){
575 logger.debug(testName + ": url=" + url +
576 " status=" + statusCode);
578 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
579 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
580 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
584 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
585 public void updateWithWrongXmlSchema(String testName) {
587 if (logger.isDebugEnabled()) {
588 logger.debug(testBanner(testName, CLASS_NAME));
592 setupUpdateWithWrongXmlSchema();
594 // Submit the request to the service and store the response.
595 String method = REQUEST_TYPE.httpMethodName();
596 String url = getResourceURL(knownResourceId);
597 final String entity = WRONG_XML_SCHEMA_DATA;
598 int statusCode = submitRequest(method, url, entity);
600 // Check the status code of the response: does it match
601 // the expected response(s)?
602 if(logger.isDebugEnabled()){
603 logger.debug(testName + ": url=" + url +
604 " status=" + statusCode);
606 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
607 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
608 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
613 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
616 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
617 // dependsOnMethods = {"update", "testSubmitRequest"})
618 public void updateNonExistent(String testName) throws Exception {
620 setupUpdateNonExistent();
622 // Submit the request to the service and store the response.
623 // Note: The ID used in this 'create' call may be arbitrary.
624 // The only relevant ID may be the one used in update(), below.
625 AcquisitionClient client = new AcquisitionClient();
626 PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
627 Response res = client.update(NON_EXISTENT_ID, multipart);
629 int statusCode = res.getStatus();
631 // Check the status code of the response: does it match
632 // the expected response(s)?
633 if(logger.isDebugEnabled()){
634 logger.debug(testName + ": status = " + statusCode);
636 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
637 invalidStatusCodeMessage(testRequestType, statusCode));
638 Assert.assertEquals(statusCode, testExpectedStatusCode);
644 // ---------------------------------------------------------------
645 // CRUD tests : DELETE tests
646 // ---------------------------------------------------------------
649 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
652 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
653 // dependsOnMethods = {"create", "read", "update"})
654 public void delete(String testName) throws Exception {
658 // Submit the request to the service and store the response.
659 AcquisitionClient client = new AcquisitionClient();
660 Response res = client.delete(knownResourceId);
663 statusCode = res.getStatus();
668 // Check the status code of the response: does it match
669 // the expected response(s)?
670 if(logger.isDebugEnabled()){
671 logger.debug(testName + ": status = " + statusCode);
673 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(testRequestType, statusCode));
675 Assert.assertEquals(statusCode, testExpectedStatusCode);
680 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
683 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
684 // dependsOnMethods = {"delete"})
685 public void deleteNonExistent(String testName) throws Exception {
687 setupDeleteNonExistent();
689 // Submit the request to the service and store the response.
690 AcquisitionClient client = new AcquisitionClient();
691 Response res = client.delete(NON_EXISTENT_ID);
694 statusCode = res.getStatus();
699 // Check the status code of the response: does it match
700 // the expected response(s)?
701 if(logger.isDebugEnabled()){
702 logger.debug(testName + ": status = " + statusCode);
704 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
705 invalidStatusCodeMessage(testRequestType, statusCode));
706 Assert.assertEquals(statusCode, testExpectedStatusCode);
709 // ---------------------------------------------------------------
710 // Utility tests : tests of code used in tests above
711 // ---------------------------------------------------------------
714 protected PoxPayloadOut createInstance(String identifier) {
715 return createAcquisitionInstance(identifier);
719 * Creates the acquisition instance.
721 * @param identifier the identifier
722 * @return the multipart output
724 private PoxPayloadOut createAcquisitionInstance(String identifier) {
725 AcquisitionsCommon acquisition = new AcquisitionsCommon();
726 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
728 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
729 List<String> acqSources = acqSourcesList.getAcquisitionSource();
730 // FIXME Use properly formatted refNames for representative acquisition
731 // sources in this example test record. The following are mere placeholders.
732 acqSources.add("Donor Acquisition Source-" + identifier);
733 acqSources.add("Museum Acquisition Source-" + identifier);
734 acquisition.setAcquisitionSources(acqSourcesList);
736 AcquisitionDateGroupList acqDatesList = new AcquisitionDateGroupList();
737 List<StructuredDateGroup> acqDates = acqDatesList.getAcquisitionDateGroup();
738 StructuredDateGroup acqDate1 = new StructuredDateGroup();
739 acqDate1.setDateDisplayDate(CURRENT_DATE_UTC);
740 StructuredDateGroup acqDate2 = new StructuredDateGroup();
741 acqDate2.setDateDisplayDate(CURRENT_DATE_UTC);
742 acqDates.add(acqDate1);
743 acqDates.add(acqDate2);
744 acquisition.setAcquisitionDateGroupList(acqDatesList);
746 OwnerList ownersList = new OwnerList();
747 List<String> owners = ownersList.getOwner();
748 // FIXME Use properly formatted refNames for representative owners
749 // in this example test record. The following are mere placeholders.
750 owners.add("First Owner -" + identifier);
751 owners.add("Second Owner-" + identifier);
752 acquisition.setOwners(ownersList);
754 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
755 PayloadOutputPart commonPart = multipart.addPart(acquisition,
756 MediaType.APPLICATION_XML_TYPE);
757 commonPart.setLabel(new AcquisitionClient().getCommonPartName());
759 if(logger.isDebugEnabled()){
760 logger.debug("to be created, acquisition common");
761 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
766 // FIXME: The following methods might be made generic and moved to a common package.
769 * Retrives an XML document from the given file, and uses
770 * the JAXB unmarshaller to create a Java object representation
771 * and ultimately a multipart payload that can be submitted in
772 * a create or update request.
774 * @param commonPartName
775 * @param commonPartFileName
779 private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
780 String commonPartFileName) throws Exception {
782 AcquisitionsCommon acquisition =
783 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
785 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
786 PayloadOutputPart commonPart = multipart.addPart(acquisition,
787 MediaType.APPLICATION_XML_TYPE);
788 commonPart.setLabel(commonPartName);
790 if (logger.isDebugEnabled()) {
791 logger.debug(testName + " to be created, acquisitions common");
792 logger.debug(objectAsXmlString(acquisition,
793 AcquisitionsCommon.class));
800 * Creates a record / resource from the data in an XML file.
802 * @param testName the test name
803 * @param fileName the file name
804 * @param useJaxb the use jaxb
806 * @throws Exception the exception
808 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
813 PoxPayloadOut multipart = null;
815 AcquisitionClient client = new AcquisitionClient();
817 multipart = createAcquisitionInstanceFromXml(testName,
818 client.getCommonPartName(), fileName);
821 multipart = createAcquisitionInstanceFromRawXml(testName,
822 client.getCommonPartName(), fileName);
824 Response res = client.create(multipart);
825 int statusCode = res.getStatus();
827 if (logger.isDebugEnabled()) {
828 logger.debug(testName + ": status = " + statusCode);
830 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
831 invalidStatusCodeMessage(testRequestType, statusCode));
832 Assert.assertEquals(statusCode, testExpectedStatusCode);
833 String newId = extractId(res);
834 allResourceIdsCreated.add(newId);
839 * Returns a multipart payload that can be submitted with a
840 * create or update request, by reading from an XML file.
842 * @param commonPartName
843 * @param commonPartFileName
847 private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
848 String commonPartFileName) throws Exception {
850 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
851 String stringObject = getXmlDocumentAsString(commonPartFileName);
852 if (logger.isDebugEnabled()) {
853 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
855 PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
856 commonPart.setLabel(commonPartName);
862 // FIXME: This duplicates code in read(), and should be consolidated.
863 // This is an expedient to support reading and verifying the contents
864 // of resources that have been created from test data XML files.
865 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
868 String testName = "readAcquisitionCommonPart";
872 // Submit the request to the service and store the response.
873 AcquisitionClient client = new AcquisitionClient();
874 Response res = client.read(csid);
875 AcquisitionsCommon acquisition = null;
877 // Check the status code of the response: does it match
878 // the expected response(s)?
879 assertStatusCode(res, testName);
880 PoxPayloadIn input = new PoxPayloadIn(res.readEntity(String.class));
882 if (logger.isDebugEnabled()) {
883 logger.debug(testName + ": Reading Common part ...");
885 acquisition = (AcquisitionsCommon) extractPart(input,
886 client.getCommonPartName(), AcquisitionsCommon.class);
887 Assert.assertNotNull(acquisition);
899 protected PoxPayloadOut createInstance(String commonPartName,
901 // TODO Auto-generated method stub
906 protected AcquisitionsCommon updateInstance(
907 AcquisitionsCommon commonPartObject) {
908 // TODO Auto-generated method stub
913 protected void compareUpdatedInstances(AcquisitionsCommon original,
914 AcquisitionsCommon updated) throws Exception {
915 // TODO Auto-generated method stub
920 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
921 * refer to this method in their @Test annotation declarations.
924 @Test(dataProvider = "testName",
926 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
927 public void CRUDTests(String testName) {
928 // Do nothing. Simply here to for a TestNG execution order for our tests