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.jaxb.AbstractCommonList;
37 import org.collectionspace.services.acquisition.AcquisitionsCommon;
38 import org.collectionspace.services.acquisition.AcquisitionDateList;
39 import org.collectionspace.services.acquisition.AcquisitionSourceList;
40 import org.collectionspace.services.acquisition.OwnerList;
41 import org.jboss.resteasy.client.ClientResponse;
43 import org.testng.Assert;
44 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 AbstractServiceTestImpl {
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 /** The known resource id. */
64 private String knownResourceId = null;
67 public String getServicePathComponent() {
68 return AcquisitionClient.SERVICE_PATH_COMPONENT;
73 protected String getServiceName() {
74 return AcquisitionClient.SERVICE_NAME;
78 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
81 protected CollectionSpaceClient getClientInstance() {
82 return new AcquisitionClient();
85 // ---------------------------------------------------------------
86 // CRUD tests : CREATE tests
87 // ---------------------------------------------------------------
90 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
93 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
94 public void create(String testName) throws Exception {
96 if (logger.isDebugEnabled()) {
97 logger.debug(testBanner(testName, CLASS_NAME));
100 // Perform setup, such as initializing the type of service request
101 // (e.g. CREATE, DELETE), its valid and expected status codes, and
102 // its associated HTTP method name (e.g. POST, DELETE).
105 // Submit the request to the service and store the response.
106 String identifier = createIdentifier();
108 AcquisitionClient client = new AcquisitionClient();
109 PoxPayloadOut multipart = createAcquisitionInstance(identifier);
110 ClientResponse<Response> res = client.create(multipart);
112 int statusCode = res.getStatus();
114 // Check the status code of the response: does it match
115 // the expected response(s)?
118 // Does it fall within the set of valid status codes?
119 // Does it exactly match the expected status code?
120 if(logger.isDebugEnabled()){
121 logger.debug(testName + ": status = " + statusCode);
123 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
124 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
125 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
127 // Store the ID returned from the first resource created
128 // for additional tests below.
129 if (knownResourceId == null){
130 knownResourceId = extractId(res);
131 if (logger.isDebugEnabled()) {
132 logger.debug(testName + ": knownResourceId=" + knownResourceId);
136 // Store the IDs from every resource created by tests,
137 // so they can be deleted after tests have been run.
138 allResourceIdsCreated.add(extractId(res));
142 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
145 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
146 dependsOnMethods = {"create"})
147 public void createList(String testName) throws Exception {
148 for(int i = 0; i < 3; i++){
154 * Tests to diagnose and fix CSPACE-2578.
156 * This is a bug identified in release 1.0 alpha, after first implementing an
157 * Acquisition Funding repeatable group of fields, in which record creation
158 * fails if there is whitespace (or more generally, a text node) between
159 * the acquisitionFunding container element and its first child field.
162 // Verify that record creation occurs successfully when there is NO whitespace
163 // between the acquisitionFunding tag and its first child element tag
164 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
165 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
166 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
167 if (logger.isDebugEnabled()) {
168 logger.debug(testBanner(testName, CLASS_NAME));
170 String testDataDir = System.getProperty("test-data.fileName");
172 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
173 testSubmitRequest(newId);
176 // Verify that record creation occurs successfully when there is whitespace
177 // between the acquisitionFunding tag and its first child element tag
179 // FIXME: This test currently fails. @Test annotation is currently commented
180 // out for check-in, to prevent service tests from failing. Can uncomment to test
181 // fixes, and also after the issue is resolved, to help detect any regressions.
183 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
184 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
185 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
186 if (logger.isDebugEnabled()) {
187 logger.debug(testBanner(testName, CLASS_NAME));
189 String testDataDir = System.getProperty("test-data.fileName");
191 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
192 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
193 testSubmitRequest(newId);
198 // Placeholders until the three tests below can be uncommented.
199 // See Issue CSPACE-401.
201 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
204 public void createWithEmptyEntityBody(String testName) throws Exception {
205 //Should this really be empty?
209 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
212 public void createWithMalformedXml(String testName) throws Exception {
213 //Should this really be empty?
217 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
220 public void createWithWrongXmlSchema(String testName) throws Exception {
221 //Should this really be empty?
226 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
227 dependsOnMethods = {"create", "testSubmitRequest"})
228 public void createWithMalformedXml(String testName) throws Exception {
230 if (logger.isDebugEnabled()) {
231 logger.debug(testBanner(testName, CLASS_NAME));
235 setupCreateWithMalformedXml();
237 // Submit the request to the service and store the response.
238 String method = REQUEST_TYPE.httpMethodName();
239 String url = getServiceRootURL();
240 final String entity = MALFORMED_XML_DATA; // Constant from base class.
241 int statusCode = submitRequest(method, url, entity);
243 // Check the status code of the response: does it match
244 // the expected response(s)?
245 if(logger.isDebugEnabled()){
246 logger.debug(testName + ": url=" + url +
247 " status=" + statusCode);
249 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
250 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
251 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
255 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
256 dependsOnMethods = {"create", "testSubmitRequest"})
257 public void createWithWrongXmlSchema(String testName) throws Exception {
259 if (logger.isDebugEnabled()) {
260 logger.debug(testBanner(testName, CLASS_NAME));
264 setupCreateWithWrongXmlSchema();
266 // Submit the request to the service and store the response.
267 String method = REQUEST_TYPE.httpMethodName();
268 String url = getServiceRootURL();
269 final String entity = WRONG_XML_SCHEMA_DATA;
270 int statusCode = submitRequest(method, url, entity);
272 // Check the status code of the response: does it match
273 // the expected response(s)?
274 if(logger.isDebugEnabled()){
275 logger.debug(testName + ": url=" + url +
276 " status=" + statusCode);
278 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
279 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
280 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
284 // ---------------------------------------------------------------
285 // CRUD tests : READ tests
286 // ---------------------------------------------------------------
289 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
292 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
293 dependsOnMethods = {"create"})
294 public void read(String testName) throws Exception {
296 if (logger.isDebugEnabled()) {
297 logger.debug(testBanner(testName, CLASS_NAME));
303 AcquisitionClient client = new AcquisitionClient();
305 // Submit the request to the service and store the response.
306 ClientResponse<String> res = client.read(knownResourceId);
307 int statusCode = res.getStatus();
309 // Check the status code of the response: does it match
310 // the expected response(s)?
311 if(logger.isDebugEnabled()){
312 logger.debug(testName + ": status = " + statusCode);
314 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
315 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
316 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
318 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
319 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
320 client.getCommonPartName(), AcquisitionsCommon.class);
321 Assert.assertNotNull(acquisitionObject);
323 // Verify the number and contents of values in repeatable fields,
324 // as created in the instance record used for testing.
325 List<String> acqSources =
326 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
327 Assert.assertTrue(acqSources.size() > 0);
328 Assert.assertNotNull(acqSources.get(0));
330 List<String> acqDates =
331 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
332 Assert.assertTrue(acqDates.size() > 0);
333 Assert.assertNotNull(acqDates.get(0));
335 List<String> owners =
336 acquisitionObject.getOwners().getOwner();
337 Assert.assertTrue(owners.size() > 0);
338 Assert.assertNotNull(owners.get(0));
343 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
346 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
347 dependsOnMethods = {"read"})
348 public void readNonExistent(String testName) throws Exception {
350 if (logger.isDebugEnabled()) {
351 logger.debug(testBanner(testName, CLASS_NAME));
355 setupReadNonExistent();
357 // Submit the request to the service and store the response.
358 AcquisitionClient client = new AcquisitionClient();
359 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
360 int statusCode = res.getStatus();
362 // Check the status code of the response: does it match
363 // the expected response(s)?
364 if(logger.isDebugEnabled()){
365 logger.debug(testName + ": status = " + statusCode);
367 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
368 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
369 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
372 // ---------------------------------------------------------------
373 // CRUD tests : READ_LIST tests
374 // ---------------------------------------------------------------
377 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
380 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
381 dependsOnMethods = {"createList", "read"})
382 public void readList(String testName) throws Exception {
384 if (logger.isDebugEnabled()) {
385 logger.debug(testBanner(testName, CLASS_NAME));
391 // Submit the request to the service and store the response.
392 AcquisitionClient client = new AcquisitionClient();
393 ClientResponse<AbstractCommonList> res = client.readList();
394 AbstractCommonList list = res.getEntity();
395 int statusCode = res.getStatus();
397 // Check the status code of the response: does it match
398 // the expected response(s)?
399 if(logger.isDebugEnabled()){
400 logger.debug(testName + ": status = " + statusCode);
402 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
403 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
404 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
406 // Optionally output additional data about list members for debugging.
407 if(logger.isTraceEnabled()){
408 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
416 // ---------------------------------------------------------------
417 // CRUD tests : UPDATE tests
418 // ---------------------------------------------------------------
422 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
425 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
426 dependsOnMethods = {"read"})
427 public void update(String testName) throws Exception {
429 if (logger.isDebugEnabled()) {
430 logger.debug(testBanner(testName, CLASS_NAME));
436 // Retrieve the contents of a resource to update.
437 AcquisitionClient client = new AcquisitionClient();
438 ClientResponse<String> res = client.read(knownResourceId);
439 if(logger.isDebugEnabled()){
440 logger.debug(testName + ": read status = " + res.getStatus());
442 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
444 if(logger.isDebugEnabled()){
445 logger.debug("got object to update with ID: " + knownResourceId);
447 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
449 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
450 client.getCommonPartName(), AcquisitionsCommon.class);
451 Assert.assertNotNull(acquisition);
453 // Update the content of this resource.
454 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
455 if(logger.isDebugEnabled()){
456 logger.debug("updated object");
457 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
459 // Submit the request to the service and store the response.
460 PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
461 PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
462 commonPart.setLabel(client.getCommonPartName());
464 res = client.update(knownResourceId, output);
465 int statusCode = res.getStatus();
466 // Check the status code of the response: does it match the expected response(s)?
467 if(logger.isDebugEnabled()){
468 logger.debug(testName + ": status = " + statusCode);
470 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
471 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
472 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
475 input = new PoxPayloadIn(res.getEntity());
476 AcquisitionsCommon updatedAcquisition =
477 (AcquisitionsCommon) extractPart(input,
478 client.getCommonPartName(), AcquisitionsCommon.class);
479 Assert.assertNotNull(updatedAcquisition);
481 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
482 acquisition.getAcquisitionReferenceNumber(),
483 "Data in updated object did not match submitted data.");
488 // Placeholders until the three tests below can be uncommented.
489 // See Issue CSPACE-401.
491 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
494 public void updateWithEmptyEntityBody(String testName) throws Exception {
495 //Should this really be empty?
499 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
502 public void updateWithMalformedXml(String testName) throws Exception {
503 //Should this really be empty?
507 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
510 public void updateWithWrongXmlSchema(String testName) throws Exception {
511 //Should this really be empty?
516 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
517 dependsOnMethods = {"create", "update", "testSubmitRequest"})
518 public void updateWithEmptyEntityBody(String testName) throws Exception {
520 if (logger.isDebugEnabled()) {
521 logger.debug(testBanner(testName, CLASS_NAME));
525 setupUpdateWithEmptyEntityBody();
527 // Submit the request to the service and store the response.
528 String method = REQUEST_TYPE.httpMethodName();
529 String url = getResourceURL(knownResourceId);
530 String mediaType = MediaType.APPLICATION_XML;
531 final String entity = "";
532 int statusCode = submitRequest(method, url, mediaType, entity);
534 // Check the status code of the response: does it match
535 // the expected response(s)?
536 if(logger.isDebugEnabled()){
537 (testName + ": url=" + url + " status=" + statusCode);
539 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
540 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
541 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
545 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
546 dependsOnMethods = {"create", "testSubmitRequest"})
547 public void createWithEmptyEntityBody(String testName) throws Exception {
549 if (logger.isDebugEnabled()) {
550 logger.debug(testBanner(testName, CLASS_NAME));
554 setupCreateWithEmptyEntityBody();
556 // Submit the request to the service and store the response.
557 String method = REQUEST_TYPE.httpMethodName();
558 String url = getServiceRootURL();
559 String mediaType = MediaType.APPLICATION_XML;
560 final String entity = "";
561 int statusCode = submitRequest(method, url, mediaType, entity);
563 // Check the status code of the response: does it match
564 // the expected response(s)?
565 if(logger.isDebugEnabled()){
566 logger.debug(testName + ": url=" + url +
567 " status=" + statusCode);
569 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
570 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
571 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
575 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
576 dependsOnMethods = {"create", "update", "testSubmitRequest"})
577 public void updateWithMalformedXml(String testName) throws Exception {
579 if (logger.isDebugEnabled()) {
580 logger.debug(testBanner(testName, CLASS_NAME));
584 setupUpdateWithMalformedXml();
586 // Submit the request to the service and store the response.
587 String method = REQUEST_TYPE.httpMethodName();
588 String url = getResourceURL(knownResourceId);
589 final String entity = MALFORMED_XML_DATA;
590 int statusCode = submitRequest(method, url, entity);
592 // Check the status code of the response: does it match
593 // the expected response(s)?
594 if(logger.isDebugEnabled()){
595 logger.debug(testName + ": url=" + url +
596 " status=" + statusCode);
598 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
599 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
600 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
604 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
605 public void updateWithWrongXmlSchema(String testName) {
607 if (logger.isDebugEnabled()) {
608 logger.debug(testBanner(testName, CLASS_NAME));
612 setupUpdateWithWrongXmlSchema();
614 // Submit the request to the service and store the response.
615 String method = REQUEST_TYPE.httpMethodName();
616 String url = getResourceURL(knownResourceId);
617 final String entity = WRONG_XML_SCHEMA_DATA;
618 int statusCode = submitRequest(method, url, entity);
620 // Check the status code of the response: does it match
621 // the expected response(s)?
622 if(logger.isDebugEnabled()){
623 logger.debug(testName + ": url=" + url +
624 " status=" + statusCode);
626 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
627 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
628 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
633 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
636 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
637 dependsOnMethods = {"update", "testSubmitRequest"})
638 public void updateNonExistent(String testName) throws Exception {
640 if (logger.isDebugEnabled()) {
641 logger.debug(testBanner(testName, CLASS_NAME));
645 setupUpdateNonExistent();
647 // Submit the request to the service and store the response.
648 // Note: The ID used in this 'create' call may be arbitrary.
649 // The only relevant ID may be the one used in update(), below.
650 AcquisitionClient client = new AcquisitionClient();
651 PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
652 ClientResponse<String> res =
653 client.update(NON_EXISTENT_ID, multipart);
654 int statusCode = res.getStatus();
656 // Check the status code of the response: does it match
657 // the expected response(s)?
658 if(logger.isDebugEnabled()){
659 logger.debug(testName + ": status = " + statusCode);
661 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
662 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
663 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
666 // ---------------------------------------------------------------
667 // CRUD tests : DELETE tests
668 // ---------------------------------------------------------------
671 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
674 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
675 dependsOnMethods = {"create", "read", "update"})
676 public void delete(String testName) throws Exception {
678 if (logger.isDebugEnabled()) {
679 logger.debug(testBanner(testName, CLASS_NAME));
685 // Submit the request to the service and store the response.
686 AcquisitionClient client = new AcquisitionClient();
687 ClientResponse<Response> res = client.delete(knownResourceId);
688 int statusCode = res.getStatus();
690 // Check the status code of the response: does it match
691 // the expected response(s)?
692 if(logger.isDebugEnabled()){
693 logger.debug(testName + ": status = " + statusCode);
695 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
696 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
697 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
705 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
706 dependsOnMethods = {"delete"})
707 public void deleteNonExistent(String testName) throws Exception {
709 if (logger.isDebugEnabled()) {
710 logger.debug(testBanner(testName, CLASS_NAME));
714 setupDeleteNonExistent();
716 // Submit the request to the service and store the response.
717 AcquisitionClient client = new AcquisitionClient();
718 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
719 int statusCode = res.getStatus();
721 // Check the status code of the response: does it match
722 // the expected response(s)?
723 if(logger.isDebugEnabled()){
724 logger.debug(testName + ": status = " + statusCode);
726 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
727 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
728 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
731 // ---------------------------------------------------------------
732 // Utility tests : tests of code used in tests above
733 // ---------------------------------------------------------------
735 * Tests the code for manually submitting data that is used by several
736 * of the methods above.
740 @Test(dependsOnMethods = {"create", "read"})
741 public void testSubmitRequest() throws Exception {
742 testSubmitRequest(knownResourceId);
746 * Test submit request.
748 * @param resourceId the resource id
749 * @throws Exception the exception
751 private void testSubmitRequest(String resourceId) throws Exception {
753 // Expected status code: 200 OK
754 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
756 // Submit the request to the service and store the response.
757 String method = ServiceRequestType.READ.httpMethodName();
758 String url = getResourceURL(resourceId);
759 int statusCode = submitRequest(method, url);
761 // Check the status code of the response: does it match
762 // the expected response(s)?
763 if (logger.isDebugEnabled()) {
764 logger.debug("testSubmitRequest: url=" + url
765 + " status=" + statusCode);
767 Assert.assertEquals(statusCode, EXPECTED_STATUS);
771 // ---------------------------------------------------------------
772 // Utility methods used by tests above
773 // ---------------------------------------------------------------
776 protected PoxPayloadOut createInstance(String identifier) {
777 return createAcquisitionInstance(identifier);
781 * Creates the acquisition instance.
783 * @param identifier the identifier
784 * @return the multipart output
786 private PoxPayloadOut createAcquisitionInstance(String identifier) {
787 AcquisitionsCommon acquisition = new AcquisitionsCommon();
788 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
790 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
791 List<String> acqSources = acqSourcesList.getAcquisitionSource();
792 // FIXME Use properly formatted refNames for representative acquisition
793 // sources in this example test record. The following are mere placeholders.
794 acqSources.add("Donor Acquisition Source-" + identifier);
795 acqSources.add("Museum Acquisition Source-" + identifier);
796 acquisition.setAcquisitionSources(acqSourcesList);
798 AcquisitionDateList acqDatesList = new AcquisitionDateList();
799 List<String> acqDates = acqDatesList.getAcquisitionDate();
800 // FIXME Use properly timestamps for representative acquisition
801 // dates in this example test record. The following are mere placeholders.
802 acqDates.add("First Acquisition Date -" + identifier);
803 acqDates.add("Second Acquisition Date-" + identifier);
804 acquisition.setAcquisitionDates(acqDatesList);
806 OwnerList ownersList = new OwnerList();
807 List<String> owners = ownersList.getOwner();
808 // FIXME Use properly formatted refNames for representative owners
809 // in this example test record. The following are mere placeholders.
810 owners.add("First Owner -" + identifier);
811 owners.add("Second Owner-" + identifier);
812 acquisition.setOwners(ownersList);
814 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
815 PayloadOutputPart commonPart = multipart.addPart(acquisition,
816 MediaType.APPLICATION_XML_TYPE);
817 commonPart.setLabel(new AcquisitionClient().getCommonPartName());
819 if(logger.isDebugEnabled()){
820 logger.debug("to be created, acquisition common");
821 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
826 // FIXME: The following methods might be made generic and moved to a common package.
829 * Retrives an XML document from the given file, and uses
830 * the JAXB unmarshaller to create a Java object representation
831 * and ultimately a multipart payload that can be submitted in
832 * a create or update request.
834 * @param commonPartName
835 * @param commonPartFileName
839 private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
840 String commonPartFileName) throws Exception {
842 AcquisitionsCommon acquisition =
843 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
845 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
846 PayloadOutputPart commonPart = multipart.addPart(acquisition,
847 MediaType.APPLICATION_XML_TYPE);
848 commonPart.setLabel(commonPartName);
850 if (logger.isDebugEnabled()) {
851 logger.debug(testName + " to be created, acquisitions common");
852 logger.debug(objectAsXmlString(acquisition,
853 AcquisitionsCommon.class));
860 * Creates a record / resource from the data in an XML file.
862 * @param testName the test name
863 * @param fileName the file name
864 * @param useJaxb the use jaxb
866 * @throws Exception the exception
868 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
873 PoxPayloadOut multipart = null;
875 AcquisitionClient client = new AcquisitionClient();
877 multipart = createAcquisitionInstanceFromXml(testName,
878 client.getCommonPartName(), fileName);
881 multipart = createAcquisitionInstanceFromRawXml(testName,
882 client.getCommonPartName(), fileName);
884 ClientResponse<Response> res = client.create(multipart);
885 int statusCode = res.getStatus();
887 if (logger.isDebugEnabled()) {
888 logger.debug(testName + ": status = " + statusCode);
890 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
891 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
892 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
893 String newId = extractId(res);
894 allResourceIdsCreated.add(newId);
899 * Returns a multipart payload that can be submitted with a
900 * create or update request, by reading from an XML file.
902 * @param commonPartName
903 * @param commonPartFileName
907 private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
908 String commonPartFileName) throws Exception {
910 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
911 String stringObject = getXmlDocumentAsString(commonPartFileName);
912 if (logger.isDebugEnabled()) {
913 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
915 PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
916 commonPart.setLabel(commonPartName);
922 // FIXME: This duplicates code in read(), and should be consolidated.
923 // This is an expedient to support reading and verifying the contents
924 // of resources that have been created from test data XML files.
925 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
928 String testName = "readAcquisitionCommonPart";
932 // Submit the request to the service and store the response.
933 AcquisitionClient client = new AcquisitionClient();
934 ClientResponse<String> res = client.read(csid);
935 int statusCode = res.getStatus();
937 // Check the status code of the response: does it match
938 // the expected response(s)?
939 if (logger.isDebugEnabled()) {
940 logger.debug(testName + ": status = " + statusCode);
942 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
943 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
944 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
946 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
948 if (logger.isDebugEnabled()) {
949 logger.debug(testName + ": Reading Common part ...");
951 AcquisitionsCommon acquisition =
952 (AcquisitionsCommon) extractPart(input,
953 client.getCommonPartName(), AcquisitionsCommon.class);
954 Assert.assertNotNull(acquisition);