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.AcquisitionClient;
30 import org.collectionspace.services.client.CollectionSpaceClient;
31 import org.collectionspace.services.client.PayloadOutputPart;
32 import org.collectionspace.services.client.PoxPayloadIn;
33 import org.collectionspace.services.client.PoxPayloadOut;
34 import org.collectionspace.services.common.AbstractCommonListUtils;
35 import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
36 import org.collectionspace.services.jaxb.AbstractCommonList;
38 import org.collectionspace.services.acquisition.AcquisitionsCommon;
39 import org.collectionspace.services.acquisition.AcquisitionDateList;
40 import org.collectionspace.services.acquisition.AcquisitionSourceList;
41 import org.collectionspace.services.acquisition.OwnerList;
42 import org.jboss.resteasy.client.ClientResponse;
44 import org.testng.Assert;
45 import org.testng.annotations.Test;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
51 * AcquisitionServiceTest, carries out tests against a
52 * deployed and running Acquisition Service.
54 * $LastChangedRevision: 621 $
55 * $LastChangedDate: 2009-09-02 16:49:01 -0700 (Wed, 02 Sep 2009) $
57 public class AcquisitionServiceTest extends AbstractServiceTestImpl {
60 private final String CLASS_NAME = AcquisitionServiceTest.class.getName();
61 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
63 // Instance variables specific to this test.
64 /** The known resource id. */
65 private String knownResourceId = null;
66 private final static String CURRENT_DATE_UTC =
67 GregorianCalendarDateTimeUtils.timestampUTC();
71 public String getServicePathComponent() {
72 return AcquisitionClient.SERVICE_PATH_COMPONENT;
77 protected String getServiceName() {
78 return AcquisitionClient.SERVICE_NAME;
82 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
85 protected CollectionSpaceClient getClientInstance() {
86 return new AcquisitionClient();
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 {
100 if (logger.isDebugEnabled()) {
101 logger.debug(testBanner(testName, CLASS_NAME));
104 // Perform setup, such as initializing the type of service request
105 // (e.g. CREATE, DELETE), its valid and expected status codes, and
106 // its associated HTTP method name (e.g. POST, DELETE).
109 // Submit the request to the service and store the response.
110 String identifier = createIdentifier();
112 AcquisitionClient client = new AcquisitionClient();
113 PoxPayloadOut multipart = createAcquisitionInstance(identifier);
114 ClientResponse<Response> res = client.create(multipart);
116 int statusCode = res.getStatus();
118 // Check the status code of the response: does it match
119 // the expected response(s)?
122 // Does it fall within the set of valid status codes?
123 // Does it exactly match the expected status code?
124 if(logger.isDebugEnabled()){
125 logger.debug(testName + ": status = " + statusCode);
127 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
128 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
129 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
131 // Store the ID returned from the first resource created
132 // for additional tests below.
133 if (knownResourceId == null){
134 knownResourceId = extractId(res);
135 if (logger.isDebugEnabled()) {
136 logger.debug(testName + ": knownResourceId=" + knownResourceId);
140 // Store the IDs from every resource created by tests,
141 // so they can be deleted after tests have been run.
142 allResourceIdsCreated.add(extractId(res));
146 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
149 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
150 dependsOnMethods = {"create"})
151 public void createList(String testName) throws Exception {
152 for(int i = 0; i < 3; i++){
158 * Tests to diagnose and fix CSPACE-2578.
160 * This is a bug identified in release 1.0 alpha, after first implementing an
161 * Acquisition Funding repeatable group of fields, in which record creation
162 * fails if there is whitespace (or more generally, a text node) between
163 * the acquisitionFunding container element and its first child field.
166 // Verify that record creation occurs successfully when there is NO whitespace
167 // between the acquisitionFunding tag and its first child element tag
168 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
169 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
170 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
171 if (logger.isDebugEnabled()) {
172 logger.debug(testBanner(testName, CLASS_NAME));
174 String testDataDir = System.getProperty("test-data.fileName");
176 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
177 testSubmitRequest(newId);
180 // Verify that record creation occurs successfully when there is whitespace
181 // between the acquisitionFunding tag and its first child element tag
183 // FIXME: This test currently fails. @Test annotation is currently commented
184 // out for check-in, to prevent service tests from failing. Can uncomment to test
185 // fixes, and also after the issue is resolved, to help detect any regressions.
187 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
188 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
189 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
190 if (logger.isDebugEnabled()) {
191 logger.debug(testBanner(testName, CLASS_NAME));
193 String testDataDir = System.getProperty("test-data.fileName");
195 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
196 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
197 testSubmitRequest(newId);
202 // Placeholders until the three tests below can be uncommented.
203 // See Issue CSPACE-401.
205 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
208 public void createWithEmptyEntityBody(String testName) throws Exception {
209 //Should this really be empty?
213 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
216 public void createWithMalformedXml(String testName) throws Exception {
217 //Should this really be empty?
221 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
224 public void createWithWrongXmlSchema(String testName) throws Exception {
225 //Should this really be empty?
230 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
231 dependsOnMethods = {"create", "testSubmitRequest"})
232 public void createWithMalformedXml(String testName) throws Exception {
234 if (logger.isDebugEnabled()) {
235 logger.debug(testBanner(testName, CLASS_NAME));
239 setupCreateWithMalformedXml();
241 // Submit the request to the service and store the response.
242 String method = REQUEST_TYPE.httpMethodName();
243 String url = getServiceRootURL();
244 final String entity = MALFORMED_XML_DATA; // Constant from base class.
245 int statusCode = submitRequest(method, url, entity);
247 // Check the status code of the response: does it match
248 // the expected response(s)?
249 if(logger.isDebugEnabled()){
250 logger.debug(testName + ": url=" + url +
251 " status=" + statusCode);
253 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
254 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
255 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
259 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
260 dependsOnMethods = {"create", "testSubmitRequest"})
261 public void createWithWrongXmlSchema(String testName) throws Exception {
263 if (logger.isDebugEnabled()) {
264 logger.debug(testBanner(testName, CLASS_NAME));
268 setupCreateWithWrongXmlSchema();
270 // Submit the request to the service and store the response.
271 String method = REQUEST_TYPE.httpMethodName();
272 String url = getServiceRootURL();
273 final String entity = WRONG_XML_SCHEMA_DATA;
274 int statusCode = submitRequest(method, url, entity);
276 // Check the status code of the response: does it match
277 // the expected response(s)?
278 if(logger.isDebugEnabled()){
279 logger.debug(testName + ": url=" + url +
280 " status=" + statusCode);
282 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
283 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
284 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
288 // ---------------------------------------------------------------
289 // CRUD tests : READ tests
290 // ---------------------------------------------------------------
293 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
296 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
297 dependsOnMethods = {"create"})
298 public void read(String testName) throws Exception {
300 if (logger.isDebugEnabled()) {
301 logger.debug(testBanner(testName, CLASS_NAME));
307 AcquisitionClient client = new AcquisitionClient();
309 // Submit the request to the service and store the response.
310 ClientResponse<String> res = client.read(knownResourceId);
311 int statusCode = res.getStatus();
313 // Check the status code of the response: does it match
314 // the expected response(s)?
315 if(logger.isDebugEnabled()){
316 logger.debug(testName + ": status = " + statusCode);
318 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
319 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
320 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
322 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
323 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
324 client.getCommonPartName(), AcquisitionsCommon.class);
325 Assert.assertNotNull(acquisitionObject);
327 // Verify the number and contents of values in repeatable fields,
328 // as created in the instance record used for testing.
329 List<String> acqSources =
330 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
331 Assert.assertTrue(acqSources.size() > 0);
332 Assert.assertNotNull(acqSources.get(0));
334 List<String> acqDates =
335 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
336 Assert.assertTrue(acqDates.size() > 0);
337 Assert.assertNotNull(acqDates.get(0));
339 List<String> owners =
340 acquisitionObject.getOwners().getOwner();
341 Assert.assertTrue(owners.size() > 0);
342 Assert.assertNotNull(owners.get(0));
347 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
350 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
351 dependsOnMethods = {"read"})
352 public void readNonExistent(String testName) throws Exception {
354 if (logger.isDebugEnabled()) {
355 logger.debug(testBanner(testName, CLASS_NAME));
359 setupReadNonExistent();
361 // Submit the request to the service and store the response.
362 AcquisitionClient client = new AcquisitionClient();
363 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
364 int statusCode = res.getStatus();
366 // Check the status code of the response: does it match
367 // the expected response(s)?
368 if(logger.isDebugEnabled()){
369 logger.debug(testName + ": status = " + statusCode);
371 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
372 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
373 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
376 // ---------------------------------------------------------------
377 // CRUD tests : READ_LIST tests
378 // ---------------------------------------------------------------
381 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
384 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
385 dependsOnMethods = {"createList", "read"})
386 public void readList(String testName) throws Exception {
388 if (logger.isDebugEnabled()) {
389 logger.debug(testBanner(testName, CLASS_NAME));
395 // Submit the request to the service and store the response.
396 AcquisitionClient client = new AcquisitionClient();
397 ClientResponse<AbstractCommonList> res = client.readList();
398 AbstractCommonList list = res.getEntity();
399 int statusCode = res.getStatus();
401 // Check the status code of the response: does it match
402 // the expected response(s)?
403 if(logger.isDebugEnabled()){
404 logger.debug(testName + ": status = " + statusCode);
406 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
407 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
408 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
410 // Optionally output additional data about list members for debugging.
411 if(logger.isTraceEnabled()){
412 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
420 // ---------------------------------------------------------------
421 // CRUD tests : UPDATE tests
422 // ---------------------------------------------------------------
426 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
429 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
430 dependsOnMethods = {"read"})
431 public void update(String testName) throws Exception {
433 if (logger.isDebugEnabled()) {
434 logger.debug(testBanner(testName, CLASS_NAME));
440 // Retrieve the contents of a resource to update.
441 AcquisitionClient client = new AcquisitionClient();
442 ClientResponse<String> res = client.read(knownResourceId);
443 if(logger.isDebugEnabled()){
444 logger.debug(testName + ": read status = " + res.getStatus());
446 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
448 if(logger.isDebugEnabled()){
449 logger.debug("got object to update with ID: " + knownResourceId);
451 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
453 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
454 client.getCommonPartName(), AcquisitionsCommon.class);
455 Assert.assertNotNull(acquisition);
457 // Update the content of this resource.
458 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
459 if(logger.isDebugEnabled()){
460 logger.debug("updated object");
461 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
463 // Submit the request to the service and store the response.
464 PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
465 PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
466 commonPart.setLabel(client.getCommonPartName());
468 res = client.update(knownResourceId, output);
469 int statusCode = res.getStatus();
470 // Check the status code of the response: does it match the expected response(s)?
471 if(logger.isDebugEnabled()){
472 logger.debug(testName + ": status = " + statusCode);
474 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
475 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
476 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
479 input = new PoxPayloadIn(res.getEntity());
480 AcquisitionsCommon updatedAcquisition =
481 (AcquisitionsCommon) extractPart(input,
482 client.getCommonPartName(), AcquisitionsCommon.class);
483 Assert.assertNotNull(updatedAcquisition);
485 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
486 acquisition.getAcquisitionReferenceNumber(),
487 "Data in updated object did not match submitted data.");
492 // Placeholders until the three tests below can be uncommented.
493 // See Issue CSPACE-401.
495 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
498 public void updateWithEmptyEntityBody(String testName) throws Exception {
499 //Should this really be empty?
503 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
506 public void updateWithMalformedXml(String testName) throws Exception {
507 //Should this really be empty?
511 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
514 public void updateWithWrongXmlSchema(String testName) throws Exception {
515 //Should this really be empty?
520 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
521 dependsOnMethods = {"create", "update", "testSubmitRequest"})
522 public void updateWithEmptyEntityBody(String testName) throws Exception {
524 if (logger.isDebugEnabled()) {
525 logger.debug(testBanner(testName, CLASS_NAME));
529 setupUpdateWithEmptyEntityBody();
531 // Submit the request to the service and store the response.
532 String method = REQUEST_TYPE.httpMethodName();
533 String url = getResourceURL(knownResourceId);
534 String mediaType = MediaType.APPLICATION_XML;
535 final String entity = "";
536 int statusCode = submitRequest(method, url, mediaType, entity);
538 // Check the status code of the response: does it match
539 // the expected response(s)?
540 if(logger.isDebugEnabled()){
541 (testName + ": url=" + url + " status=" + statusCode);
543 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
544 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
545 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
549 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
550 dependsOnMethods = {"create", "testSubmitRequest"})
551 public void createWithEmptyEntityBody(String testName) throws Exception {
553 if (logger.isDebugEnabled()) {
554 logger.debug(testBanner(testName, CLASS_NAME));
558 setupCreateWithEmptyEntityBody();
560 // Submit the request to the service and store the response.
561 String method = REQUEST_TYPE.httpMethodName();
562 String url = getServiceRootURL();
563 String mediaType = MediaType.APPLICATION_XML;
564 final String entity = "";
565 int statusCode = submitRequest(method, url, mediaType, entity);
567 // Check the status code of the response: does it match
568 // the expected response(s)?
569 if(logger.isDebugEnabled()){
570 logger.debug(testName + ": url=" + url +
571 " status=" + statusCode);
573 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
574 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
575 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
579 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
580 dependsOnMethods = {"create", "update", "testSubmitRequest"})
581 public void updateWithMalformedXml(String testName) throws Exception {
583 if (logger.isDebugEnabled()) {
584 logger.debug(testBanner(testName, CLASS_NAME));
588 setupUpdateWithMalformedXml();
590 // Submit the request to the service and store the response.
591 String method = REQUEST_TYPE.httpMethodName();
592 String url = getResourceURL(knownResourceId);
593 final String entity = MALFORMED_XML_DATA;
594 int statusCode = submitRequest(method, url, entity);
596 // Check the status code of the response: does it match
597 // the expected response(s)?
598 if(logger.isDebugEnabled()){
599 logger.debug(testName + ": url=" + url +
600 " status=" + statusCode);
602 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
603 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
604 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
608 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
609 public void updateWithWrongXmlSchema(String testName) {
611 if (logger.isDebugEnabled()) {
612 logger.debug(testBanner(testName, CLASS_NAME));
616 setupUpdateWithWrongXmlSchema();
618 // Submit the request to the service and store the response.
619 String method = REQUEST_TYPE.httpMethodName();
620 String url = getResourceURL(knownResourceId);
621 final String entity = WRONG_XML_SCHEMA_DATA;
622 int statusCode = submitRequest(method, url, entity);
624 // Check the status code of the response: does it match
625 // the expected response(s)?
626 if(logger.isDebugEnabled()){
627 logger.debug(testName + ": url=" + url +
628 " status=" + statusCode);
630 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
631 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
632 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
637 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
640 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
641 dependsOnMethods = {"update", "testSubmitRequest"})
642 public void updateNonExistent(String testName) throws Exception {
644 if (logger.isDebugEnabled()) {
645 logger.debug(testBanner(testName, CLASS_NAME));
649 setupUpdateNonExistent();
651 // Submit the request to the service and store the response.
652 // Note: The ID used in this 'create' call may be arbitrary.
653 // The only relevant ID may be the one used in update(), below.
654 AcquisitionClient client = new AcquisitionClient();
655 PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
656 ClientResponse<String> res =
657 client.update(NON_EXISTENT_ID, multipart);
658 int statusCode = res.getStatus();
660 // Check the status code of the response: does it match
661 // the expected response(s)?
662 if(logger.isDebugEnabled()){
663 logger.debug(testName + ": status = " + statusCode);
665 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
666 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
667 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
670 // ---------------------------------------------------------------
671 // CRUD tests : DELETE tests
672 // ---------------------------------------------------------------
675 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
678 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
679 dependsOnMethods = {"create", "read", "update"})
680 public void delete(String testName) throws Exception {
682 if (logger.isDebugEnabled()) {
683 logger.debug(testBanner(testName, CLASS_NAME));
689 // Submit the request to the service and store the response.
690 AcquisitionClient client = new AcquisitionClient();
691 ClientResponse<Response> res = client.delete(knownResourceId);
692 int statusCode = res.getStatus();
694 // Check the status code of the response: does it match
695 // the expected response(s)?
696 if(logger.isDebugEnabled()){
697 logger.debug(testName + ": status = " + statusCode);
699 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
700 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
701 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
706 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
709 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
710 dependsOnMethods = {"delete"})
711 public void deleteNonExistent(String testName) throws Exception {
713 if (logger.isDebugEnabled()) {
714 logger.debug(testBanner(testName, CLASS_NAME));
718 setupDeleteNonExistent();
720 // Submit the request to the service and store the response.
721 AcquisitionClient client = new AcquisitionClient();
722 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
723 int statusCode = res.getStatus();
725 // Check the status code of the response: does it match
726 // the expected response(s)?
727 if(logger.isDebugEnabled()){
728 logger.debug(testName + ": status = " + statusCode);
730 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
731 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
732 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
735 // ---------------------------------------------------------------
736 // Utility tests : tests of code used in tests above
737 // ---------------------------------------------------------------
739 * Tests the code for manually submitting data that is used by several
740 * of the methods above.
744 @Test(dependsOnMethods = {"create", "read"})
745 public void testSubmitRequest() throws Exception {
746 testSubmitRequest(knownResourceId);
750 * Test submit request.
752 * @param resourceId the resource id
753 * @throws Exception the exception
755 private void testSubmitRequest(String resourceId) throws Exception {
757 // Expected status code: 200 OK
758 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
760 // Submit the request to the service and store the response.
761 String method = ServiceRequestType.READ.httpMethodName();
762 String url = getResourceURL(resourceId);
763 int statusCode = submitRequest(method, url);
765 // Check the status code of the response: does it match
766 // the expected response(s)?
767 if (logger.isDebugEnabled()) {
768 logger.debug("testSubmitRequest: url=" + url
769 + " status=" + statusCode);
771 Assert.assertEquals(statusCode, EXPECTED_STATUS);
775 // ---------------------------------------------------------------
776 // Utility methods used by tests above
777 // ---------------------------------------------------------------
780 protected PoxPayloadOut createInstance(String identifier) {
781 return createAcquisitionInstance(identifier);
785 * Creates the acquisition instance.
787 * @param identifier the identifier
788 * @return the multipart output
790 private PoxPayloadOut createAcquisitionInstance(String identifier) {
791 AcquisitionsCommon acquisition = new AcquisitionsCommon();
792 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
794 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
795 List<String> acqSources = acqSourcesList.getAcquisitionSource();
796 // FIXME Use properly formatted refNames for representative acquisition
797 // sources in this example test record. The following are mere placeholders.
798 acqSources.add("Donor Acquisition Source-" + identifier);
799 acqSources.add("Museum Acquisition Source-" + identifier);
800 acquisition.setAcquisitionSources(acqSourcesList);
802 AcquisitionDateList acqDatesList = new AcquisitionDateList();
803 List<String> acqDates = acqDatesList.getAcquisitionDate();
804 acqDates.add(CURRENT_DATE_UTC);
805 acqDates.add(CURRENT_DATE_UTC);
806 acquisition.setAcquisitionDates(acqDatesList);
808 OwnerList ownersList = new OwnerList();
809 List<String> owners = ownersList.getOwner();
810 // FIXME Use properly formatted refNames for representative owners
811 // in this example test record. The following are mere placeholders.
812 owners.add("First Owner -" + identifier);
813 owners.add("Second Owner-" + identifier);
814 acquisition.setOwners(ownersList);
816 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
817 PayloadOutputPart commonPart = multipart.addPart(acquisition,
818 MediaType.APPLICATION_XML_TYPE);
819 commonPart.setLabel(new AcquisitionClient().getCommonPartName());
821 if(logger.isDebugEnabled()){
822 logger.debug("to be created, acquisition common");
823 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
828 // FIXME: The following methods might be made generic and moved to a common package.
831 * Retrives an XML document from the given file, and uses
832 * the JAXB unmarshaller to create a Java object representation
833 * and ultimately a multipart payload that can be submitted in
834 * a create or update request.
836 * @param commonPartName
837 * @param commonPartFileName
841 private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
842 String commonPartFileName) throws Exception {
844 AcquisitionsCommon acquisition =
845 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
847 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
848 PayloadOutputPart commonPart = multipart.addPart(acquisition,
849 MediaType.APPLICATION_XML_TYPE);
850 commonPart.setLabel(commonPartName);
852 if (logger.isDebugEnabled()) {
853 logger.debug(testName + " to be created, acquisitions common");
854 logger.debug(objectAsXmlString(acquisition,
855 AcquisitionsCommon.class));
862 * Creates a record / resource from the data in an XML file.
864 * @param testName the test name
865 * @param fileName the file name
866 * @param useJaxb the use jaxb
868 * @throws Exception the exception
870 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
875 PoxPayloadOut multipart = null;
877 AcquisitionClient client = new AcquisitionClient();
879 multipart = createAcquisitionInstanceFromXml(testName,
880 client.getCommonPartName(), fileName);
883 multipart = createAcquisitionInstanceFromRawXml(testName,
884 client.getCommonPartName(), fileName);
886 ClientResponse<Response> res = client.create(multipart);
887 int statusCode = res.getStatus();
889 if (logger.isDebugEnabled()) {
890 logger.debug(testName + ": status = " + statusCode);
892 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
893 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
894 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
895 String newId = extractId(res);
896 allResourceIdsCreated.add(newId);
901 * Returns a multipart payload that can be submitted with a
902 * create or update request, by reading from an XML file.
904 * @param commonPartName
905 * @param commonPartFileName
909 private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
910 String commonPartFileName) throws Exception {
912 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
913 String stringObject = getXmlDocumentAsString(commonPartFileName);
914 if (logger.isDebugEnabled()) {
915 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
917 PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
918 commonPart.setLabel(commonPartName);
924 // FIXME: This duplicates code in read(), and should be consolidated.
925 // This is an expedient to support reading and verifying the contents
926 // of resources that have been created from test data XML files.
927 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
930 String testName = "readAcquisitionCommonPart";
934 // Submit the request to the service and store the response.
935 AcquisitionClient client = new AcquisitionClient();
936 ClientResponse<String> res = client.read(csid);
937 int statusCode = res.getStatus();
939 // Check the status code of the response: does it match
940 // the expected response(s)?
941 if (logger.isDebugEnabled()) {
942 logger.debug(testName + ": status = " + statusCode);
944 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
945 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
946 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
948 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
950 if (logger.isDebugEnabled()) {
951 logger.debug(testName + ": Reading Common part ...");
953 AcquisitionsCommon acquisition =
954 (AcquisitionsCommon) extractPart(input,
955 client.getCommonPartName(), AcquisitionsCommon.class);
956 Assert.assertNotNull(acquisition);