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;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
29 import org.collectionspace.services.client.AbstractCommonListUtils;
30 import org.collectionspace.services.client.AcquisitionClient;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.PayloadOutputPart;
33 import org.collectionspace.services.client.PoxPayloadIn;
34 import org.collectionspace.services.client.PoxPayloadOut;
35 import org.collectionspace.services.common.api.GregorianCalendarDateTimeUtils;
36 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.jboss.resteasy.client.ClientResponse;
43 import org.collectionspace.services.acquisition.StructuredDateGroup;
45 import org.testng.Assert;
46 import org.testng.annotations.Test;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
52 * AcquisitionServiceTest, carries out tests against a
53 * deployed and running Acquisition Service.
55 * $LastChangedRevision: 621 $
56 * $LastChangedDate: 2009-09-02 16:49:01 -0700 (Wed, 02 Sep 2009) $
58 public class AcquisitionServiceTest extends AbstractPoxServiceTestImpl<AbstractCommonList, AcquisitionsCommon> {
61 private final String CLASS_NAME = AcquisitionServiceTest.class.getName();
62 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
64 // Instance variables specific to this test.
65 private final static String CURRENT_DATE_UTC =
66 GregorianCalendarDateTimeUtils.timestampUTC();
69 public String getServicePathComponent() {
70 return AcquisitionClient.SERVICE_PATH_COMPONENT;
74 protected String getServiceName() {
75 return AcquisitionClient.SERVICE_NAME;
79 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
82 protected CollectionSpaceClient getClientInstance() {
83 return new AcquisitionClient();
86 // ---------------------------------------------------------------
87 // CRUD tests : CREATE tests
88 // ---------------------------------------------------------------
91 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
94 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
95 public void create(String testName) throws Exception {
96 // Perform setup, such as initializing the type of service request
97 // (e.g. CREATE, DELETE), its valid and expected status codes, and
98 // its associated HTTP method name (e.g. POST, DELETE).
101 // Submit the request to the service and store the response.
102 String identifier = createIdentifier();
104 AcquisitionClient client = new AcquisitionClient();
105 PoxPayloadOut multipart = createAcquisitionInstance(identifier);
106 Response res = client.create(multipart);
108 int statusCode = res.getStatus();
110 // Check the status code of the response: does it match
111 // the expected response(s)?
114 // Does it fall within the set of valid status codes?
115 // Does it exactly match the expected status code?
116 if(logger.isDebugEnabled()){
117 logger.debug(testName + ": status = " + statusCode);
119 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
120 invalidStatusCodeMessage(testRequestType, statusCode));
121 Assert.assertEquals(statusCode, testExpectedStatusCode);
123 // Store the ID returned from the first resource created
124 // for additional tests below.
125 if (knownResourceId == null){
126 knownResourceId = extractId(res);
127 if (logger.isDebugEnabled()) {
128 logger.debug(testName + ": knownResourceId=" + knownResourceId);
132 // Store the IDs from every resource created by tests,
133 // so they can be deleted after tests have been run.
134 allResourceIdsCreated.add(extractId(res));
138 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
141 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
142 // dependsOnMethods = {"create"})
143 public void createList(String testName) throws Exception {
144 for(int i = 0; i < 3; i++){
150 * Tests to diagnose and fix CSPACE-2578.
152 * This is a bug identified in release 1.0 alpha, after first implementing an
153 * Acquisition Funding repeatable group of fields, in which record creation
154 * fails if there is whitespace (or more generally, a text node) between
155 * the acquisitionFunding container element and its first child field.
158 // Verify that record creation occurs successfully when there is NO whitespace
159 // between the acquisitionFunding tag and its first child element tag
160 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
161 dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"})
162 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
163 String testDataDir = System.getProperty("test-data.fileName");
165 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
166 testSubmitRequest(newId);
169 // Verify that record creation occurs successfully when there is whitespace
170 // between the acquisitionFunding tag and its first child element tag
172 // FIXME: This test currently fails. @Test annotation is currently commented
173 // out for check-in, to prevent service tests from failing. Can uncomment to test
174 // fixes, and also after the issue is resolved, to help detect any regressions.
176 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
177 dependsOnMethods = {"CRUDTests"}, groups = {"cspace2578group"})
178 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
179 String testDataDir = System.getProperty("test-data.fileName");
181 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
182 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
183 testSubmitRequest(newId);
188 // Placeholders until the three tests below can be uncommented.
189 // See Issue CSPACE-401.
191 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
194 public void createWithEmptyEntityBody(String testName) throws Exception {
195 //Should this really be empty?
199 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
202 public void createWithMalformedXml(String testName) throws Exception {
203 //Should this really be empty?
207 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
210 public void createWithWrongXmlSchema(String testName) throws Exception {
211 //Should this really be empty?
216 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
217 dependsOnMethods = {"create", "testSubmitRequest"})
218 public void createWithMalformedXml(String testName) throws Exception {
220 if (logger.isDebugEnabled()) {
221 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 final String entity = MALFORMED_XML_DATA; // Constant from base class.
231 int statusCode = submitRequest(method, url, entity);
233 // Check the status code of the response: does it match
234 // the expected response(s)?
235 if(logger.isDebugEnabled()){
236 logger.debug(testName + ": url=" + url +
237 " status=" + statusCode);
239 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
240 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
241 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
245 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
246 dependsOnMethods = {"create", "testSubmitRequest"})
247 public void createWithWrongXmlSchema(String testName) throws Exception {
249 if (logger.isDebugEnabled()) {
250 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 final String entity = WRONG_XML_SCHEMA_DATA;
260 int statusCode = submitRequest(method, url, entity);
262 // Check the status code of the response: does it match
263 // the expected response(s)?
264 if(logger.isDebugEnabled()){
265 logger.debug(testName + ": url=" + url +
266 " status=" + statusCode);
268 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
269 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
270 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 {
288 AcquisitionClient client = new AcquisitionClient();
290 // Submit the request to the service and store the response.
291 Response res = client.read(knownResourceId);
292 PoxPayloadIn input = null;
294 int statusCode = res.getStatus();
296 // Check the status code of the response: does it match
297 // the expected response(s)?
298 if(logger.isDebugEnabled()){
299 logger.debug(testName + ": status = " + statusCode);
301 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
302 invalidStatusCodeMessage(testRequestType, statusCode));
303 Assert.assertEquals(statusCode, testExpectedStatusCode);
305 input = new PoxPayloadIn((String)res.getEntity());
310 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
311 client.getCommonPartName(), AcquisitionsCommon.class);
312 Assert.assertNotNull(acquisitionObject);
314 // Verify the number and contents of values in repeatable fields,
315 // as created in the instance record used for testing.
316 List<String> acqSources = acquisitionObject.getAcquisitionSources().getAcquisitionSource();
317 Assert.assertTrue(acqSources.size() > 0);
318 Assert.assertNotNull(acqSources.get(0));
320 List<StructuredDateGroup> acqDates = acquisitionObject.getAcquisitionDateGroupList().getAcquisitionDateGroup();
321 Assert.assertTrue(acqDates.size() > 0);
322 Assert.assertNotNull(acqDates.get(0));
324 List<String> owners =
325 acquisitionObject.getOwners().getOwner();
326 Assert.assertTrue(owners.size() > 0);
327 Assert.assertNotNull(owners.get(0));
332 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
335 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
336 // dependsOnMethods = {"read"})
337 public void readNonExistent(String testName) throws Exception {
339 setupReadNonExistent();
341 // Submit the request to the service and store the response.
342 AcquisitionClient client = new AcquisitionClient();
343 Response res = client.read(NON_EXISTENT_ID);
344 int statusCode = res.getStatus();
346 // Check the status code of the response: does it match
347 // the expected response(s)?
348 if(logger.isDebugEnabled()){
349 logger.debug(testName + ": status = " + statusCode);
351 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
352 invalidStatusCodeMessage(testRequestType, statusCode));
353 Assert.assertEquals(statusCode, testExpectedStatusCode);
356 // ---------------------------------------------------------------
357 // CRUD tests : READ_LIST tests
358 // ---------------------------------------------------------------
361 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
364 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
365 // dependsOnMethods = {"createList", "read"})
366 public void readList(String testName) throws Exception {
370 // Submit the request to the service and store the response.
371 AcquisitionClient client = new AcquisitionClient();
372 Response res = client.readList();
374 // Check the status code of the response: does it match
375 // the expected response(s)?
376 assertStatusCode(res, testName);
377 AbstractCommonList list = res.readEntity(this.getCommonListType());
379 // Optionally output additional data about list members for debugging.
380 if (logger.isTraceEnabled() == true){
381 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
393 // ---------------------------------------------------------------
394 // CRUD tests : UPDATE tests
395 // ---------------------------------------------------------------
399 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
402 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
403 // dependsOnMethods = {"read"})
404 public void update(String testName) throws Exception {
408 // Retrieve the contents of a resource to update.
409 AcquisitionClient client = new AcquisitionClient();
410 Response res = client.read(knownResourceId);
411 PoxPayloadIn input = null;
413 if(logger.isDebugEnabled()){
414 logger.debug(testName + ": read status = " + res.getStatus());
416 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
418 input = new PoxPayloadIn((String)res.getEntity());
423 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
424 client.getCommonPartName(), AcquisitionsCommon.class);
425 Assert.assertNotNull(acquisition);
427 // Update the content of this resource.
428 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
429 if(logger.isDebugEnabled()){
430 logger.debug("updated object");
431 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
433 // Submit the request to the service and store the response.
434 PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
435 PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
436 commonPart.setLabel(client.getCommonPartName());
438 res = client.update(knownResourceId, output);
440 int statusCode = res.getStatus();
441 // Check the status code of the response: does it match the expected response(s)?
442 if(logger.isDebugEnabled()){
443 logger.debug(testName + ": status = " + statusCode);
445 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
446 invalidStatusCodeMessage(testRequestType, statusCode));
447 Assert.assertEquals(statusCode, testExpectedStatusCode);
449 input = new PoxPayloadIn((String)res.getEntity());
450 AcquisitionsCommon updatedAcquisition =
451 (AcquisitionsCommon) extractPart(input,
452 client.getCommonPartName(), AcquisitionsCommon.class);
453 Assert.assertNotNull(updatedAcquisition);
455 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
456 acquisition.getAcquisitionReferenceNumber(),
457 "Data in updated object did not match submitted data.");
465 // Placeholders until the three tests below can be uncommented.
466 // See Issue CSPACE-401.
468 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
471 public void updateWithEmptyEntityBody(String testName) throws Exception {
472 //Should this really be empty?
476 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
479 public void updateWithMalformedXml(String testName) throws Exception {
480 //Should this really be empty?
484 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
487 public void updateWithWrongXmlSchema(String testName) throws Exception {
488 //Should this really be empty?
493 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
494 dependsOnMethods = {"create", "update", "testSubmitRequest"})
495 public void updateWithEmptyEntityBody(String testName) throws Exception {
497 if (logger.isDebugEnabled()) {
498 logger.debug(testBanner(testName, CLASS_NAME));
502 setupUpdateWithEmptyEntityBody();
504 // Submit the request to the service and store the response.
505 String method = REQUEST_TYPE.httpMethodName();
506 String url = getResourceURL(knownResourceId);
507 String mediaType = MediaType.APPLICATION_XML;
508 final String entity = "";
509 int statusCode = submitRequest(method, url, mediaType, entity);
511 // Check the status code of the response: does it match
512 // the expected response(s)?
513 if(logger.isDebugEnabled()){
514 (testName + ": url=" + url + " status=" + statusCode);
516 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
517 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
518 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
522 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
523 dependsOnMethods = {"create", "testSubmitRequest"})
524 public void createWithEmptyEntityBody(String testName) throws Exception {
526 if (logger.isDebugEnabled()) {
527 logger.debug(testBanner(testName, CLASS_NAME));
531 setupCreateWithEmptyEntityBody();
533 // Submit the request to the service and store the response.
534 String method = REQUEST_TYPE.httpMethodName();
535 String url = getServiceRootURL();
536 String mediaType = MediaType.APPLICATION_XML;
537 final String entity = "";
538 int statusCode = submitRequest(method, url, mediaType, entity);
540 // Check the status code of the response: does it match
541 // the expected response(s)?
542 if(logger.isDebugEnabled()){
543 logger.debug(testName + ": url=" + url +
544 " status=" + statusCode);
546 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
547 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
548 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
552 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
553 dependsOnMethods = {"create", "update", "testSubmitRequest"})
554 public void updateWithMalformedXml(String testName) throws Exception {
556 if (logger.isDebugEnabled()) {
557 logger.debug(testBanner(testName, CLASS_NAME));
561 setupUpdateWithMalformedXml();
563 // Submit the request to the service and store the response.
564 String method = REQUEST_TYPE.httpMethodName();
565 String url = getResourceURL(knownResourceId);
566 final String entity = MALFORMED_XML_DATA;
567 int statusCode = submitRequest(method, url, entity);
569 // Check the status code of the response: does it match
570 // the expected response(s)?
571 if(logger.isDebugEnabled()){
572 logger.debug(testName + ": url=" + url +
573 " status=" + statusCode);
575 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
576 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
577 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
581 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
582 public void updateWithWrongXmlSchema(String testName) {
584 if (logger.isDebugEnabled()) {
585 logger.debug(testBanner(testName, CLASS_NAME));
589 setupUpdateWithWrongXmlSchema();
591 // Submit the request to the service and store the response.
592 String method = REQUEST_TYPE.httpMethodName();
593 String url = getResourceURL(knownResourceId);
594 final String entity = WRONG_XML_SCHEMA_DATA;
595 int statusCode = submitRequest(method, url, entity);
597 // Check the status code of the response: does it match
598 // the expected response(s)?
599 if(logger.isDebugEnabled()){
600 logger.debug(testName + ": url=" + url +
601 " status=" + statusCode);
603 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
604 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
605 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
610 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
613 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
614 // dependsOnMethods = {"update", "testSubmitRequest"})
615 public void updateNonExistent(String testName) throws Exception {
617 setupUpdateNonExistent();
619 // Submit the request to the service and store the response.
620 // Note: The ID used in this 'create' call may be arbitrary.
621 // The only relevant ID may be the one used in update(), below.
622 AcquisitionClient client = new AcquisitionClient();
623 PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
624 Response res = client.update(NON_EXISTENT_ID, multipart);
626 int statusCode = res.getStatus();
628 // Check the status code of the response: does it match
629 // the expected response(s)?
630 if(logger.isDebugEnabled()){
631 logger.debug(testName + ": status = " + statusCode);
633 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
634 invalidStatusCodeMessage(testRequestType, statusCode));
635 Assert.assertEquals(statusCode, testExpectedStatusCode);
641 // ---------------------------------------------------------------
642 // CRUD tests : DELETE tests
643 // ---------------------------------------------------------------
646 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
649 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
650 // dependsOnMethods = {"create", "read", "update"})
651 public void delete(String testName) throws Exception {
655 // Submit the request to the service and store the response.
656 AcquisitionClient client = new AcquisitionClient();
657 Response res = client.delete(knownResourceId);
660 statusCode = res.getStatus();
665 // Check the status code of the response: does it match
666 // the expected response(s)?
667 if(logger.isDebugEnabled()){
668 logger.debug(testName + ": status = " + statusCode);
670 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
671 invalidStatusCodeMessage(testRequestType, statusCode));
672 Assert.assertEquals(statusCode, testExpectedStatusCode);
677 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
680 // @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
681 // dependsOnMethods = {"delete"})
682 public void deleteNonExistent(String testName) throws Exception {
684 setupDeleteNonExistent();
686 // Submit the request to the service and store the response.
687 AcquisitionClient client = new AcquisitionClient();
688 Response res = client.delete(NON_EXISTENT_ID);
691 statusCode = res.getStatus();
696 // Check the status code of the response: does it match
697 // the expected response(s)?
698 if(logger.isDebugEnabled()){
699 logger.debug(testName + ": status = " + statusCode);
701 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
702 invalidStatusCodeMessage(testRequestType, statusCode));
703 Assert.assertEquals(statusCode, testExpectedStatusCode);
706 // ---------------------------------------------------------------
707 // Utility tests : tests of code used in tests above
708 // ---------------------------------------------------------------
711 protected PoxPayloadOut createInstance(String identifier) {
712 return createAcquisitionInstance(identifier);
716 * Creates the acquisition instance.
718 * @param identifier the identifier
719 * @return the multipart output
721 private PoxPayloadOut createAcquisitionInstance(String identifier) {
722 AcquisitionsCommon acquisition = new AcquisitionsCommon();
723 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
725 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
726 List<String> acqSources = acqSourcesList.getAcquisitionSource();
727 // FIXME Use properly formatted refNames for representative acquisition
728 // sources in this example test record. The following are mere placeholders.
729 acqSources.add("Donor Acquisition Source-" + identifier);
730 acqSources.add("Museum Acquisition Source-" + identifier);
731 acquisition.setAcquisitionSources(acqSourcesList);
733 AcquisitionDateGroupList acqDatesList = new AcquisitionDateGroupList();
734 List<StructuredDateGroup> acqDates = acqDatesList.getAcquisitionDateGroup();
735 StructuredDateGroup acqDate1 = new StructuredDateGroup();
736 acqDate1.setDateDisplayDate(CURRENT_DATE_UTC);
737 StructuredDateGroup acqDate2 = new StructuredDateGroup();
738 acqDate2.setDateDisplayDate(CURRENT_DATE_UTC);
739 acqDates.add(acqDate1);
740 acqDates.add(acqDate2);
741 acquisition.setAcquisitionDateGroupList(acqDatesList);
743 OwnerList ownersList = new OwnerList();
744 List<String> owners = ownersList.getOwner();
745 // FIXME Use properly formatted refNames for representative owners
746 // in this example test record. The following are mere placeholders.
747 owners.add("First Owner -" + identifier);
748 owners.add("Second Owner-" + identifier);
749 acquisition.setOwners(ownersList);
751 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
752 PayloadOutputPart commonPart = multipart.addPart(acquisition,
753 MediaType.APPLICATION_XML_TYPE);
754 commonPart.setLabel(new AcquisitionClient().getCommonPartName());
756 if(logger.isDebugEnabled()){
757 logger.debug("to be created, acquisition common");
758 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
763 // FIXME: The following methods might be made generic and moved to a common package.
766 * Retrives an XML document from the given file, and uses
767 * the JAXB unmarshaller to create a Java object representation
768 * and ultimately a multipart payload that can be submitted in
769 * a create or update request.
771 * @param commonPartName
772 * @param commonPartFileName
776 private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
777 String commonPartFileName) throws Exception {
779 AcquisitionsCommon acquisition =
780 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
782 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
783 PayloadOutputPart commonPart = multipart.addPart(acquisition,
784 MediaType.APPLICATION_XML_TYPE);
785 commonPart.setLabel(commonPartName);
787 if (logger.isDebugEnabled()) {
788 logger.debug(testName + " to be created, acquisitions common");
789 logger.debug(objectAsXmlString(acquisition,
790 AcquisitionsCommon.class));
797 * Creates a record / resource from the data in an XML file.
799 * @param testName the test name
800 * @param fileName the file name
801 * @param useJaxb the use jaxb
803 * @throws Exception the exception
805 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
810 PoxPayloadOut multipart = null;
812 AcquisitionClient client = new AcquisitionClient();
814 multipart = createAcquisitionInstanceFromXml(testName,
815 client.getCommonPartName(), fileName);
818 multipart = createAcquisitionInstanceFromRawXml(testName,
819 client.getCommonPartName(), fileName);
821 Response res = client.create(multipart);
822 int statusCode = res.getStatus();
824 if (logger.isDebugEnabled()) {
825 logger.debug(testName + ": status = " + statusCode);
827 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
828 invalidStatusCodeMessage(testRequestType, statusCode));
829 Assert.assertEquals(statusCode, testExpectedStatusCode);
830 String newId = extractId(res);
831 allResourceIdsCreated.add(newId);
836 * Returns a multipart payload that can be submitted with a
837 * create or update request, by reading from an XML file.
839 * @param commonPartName
840 * @param commonPartFileName
844 private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
845 String commonPartFileName) throws Exception {
847 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
848 String stringObject = getXmlDocumentAsString(commonPartFileName);
849 if (logger.isDebugEnabled()) {
850 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
852 PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
853 commonPart.setLabel(commonPartName);
859 // FIXME: This duplicates code in read(), and should be consolidated.
860 // This is an expedient to support reading and verifying the contents
861 // of resources that have been created from test data XML files.
862 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
865 String testName = "readAcquisitionCommonPart";
869 // Submit the request to the service and store the response.
870 AcquisitionClient client = new AcquisitionClient();
871 Response res = client.read(csid);
872 AcquisitionsCommon acquisition = null;
874 // Check the status code of the response: does it match
875 // the expected response(s)?
876 assertStatusCode(res, testName);
877 PoxPayloadIn input = new PoxPayloadIn((String)res.getEntity());
879 if (logger.isDebugEnabled()) {
880 logger.debug(testName + ": Reading Common part ...");
882 acquisition = (AcquisitionsCommon) extractPart(input,
883 client.getCommonPartName(), AcquisitionsCommon.class);
884 Assert.assertNotNull(acquisition);
896 protected PoxPayloadOut createInstance(String commonPartName,
898 // TODO Auto-generated method stub
903 protected AcquisitionsCommon updateInstance(
904 AcquisitionsCommon commonPartObject) {
905 // TODO Auto-generated method stub
910 protected void compareUpdatedInstances(AcquisitionsCommon original,
911 AcquisitionsCommon updated) throws Exception {
912 // TODO Auto-generated method stub
917 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
918 * refer to this method in their @Test annotation declarations.
921 @Test(dataProvider = "testName",
923 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
924 public void CRUDTests(String testName) {
925 // Do nothing. Simply here to for a TestNG execution order for our tests