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.jaxb.AbstractCommonList;
36 import org.collectionspace.services.acquisition.AcquisitionsCommon;
37 import org.collectionspace.services.acquisition.AcquisitionDateList;
38 import org.collectionspace.services.acquisition.AcquisitionFunding;
39 import org.collectionspace.services.acquisition.AcquisitionFundingList;
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.jaxb.AbstractCommonList;
45 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
46 import org.testng.Assert;
47 import org.testng.annotations.Test;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
53 * AcquisitionServiceTest, carries out tests against a
54 * deployed and running Acquisition Service.
56 * $LastChangedRevision: 621 $
57 * $LastChangedDate: 2009-09-02 16:49:01 -0700 (Wed, 02 Sep 2009) $
59 public class AcquisitionServiceTest extends AbstractServiceTestImpl {
62 private final String CLASS_NAME = AcquisitionServiceTest.class.getName();
63 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
65 // Instance variables specific to this test.
66 /** The known resource id. */
67 private String knownResourceId = null;
70 public String getServicePathComponent() {
71 return AcquisitionClient.SERVICE_PATH_COMPONENT;
76 protected String getServiceName() {
77 return AcquisitionClient.SERVICE_NAME;
81 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
84 protected CollectionSpaceClient getClientInstance() {
85 return new AcquisitionClient();
89 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
92 protected AbstractCommonList getAbstractCommonList(
93 ClientResponse<AbstractCommonList> response) {
94 return response.getEntity(AbstractCommonList.class);
97 // ---------------------------------------------------------------
98 // CRUD tests : CREATE tests
99 // ---------------------------------------------------------------
102 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
105 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
106 public void create(String testName) throws Exception {
108 if (logger.isDebugEnabled()) {
109 logger.debug(testBanner(testName, CLASS_NAME));
112 // Perform setup, such as initializing the type of service request
113 // (e.g. CREATE, DELETE), its valid and expected status codes, and
114 // its associated HTTP method name (e.g. POST, DELETE).
117 // Submit the request to the service and store the response.
118 String identifier = createIdentifier();
120 AcquisitionClient client = new AcquisitionClient();
121 PoxPayloadOut multipart = createAcquisitionInstance(identifier);
122 ClientResponse<Response> res = client.create(multipart);
124 int statusCode = res.getStatus();
126 // Check the status code of the response: does it match
127 // the expected response(s)?
130 // Does it fall within the set of valid status codes?
131 // Does it exactly match the expected status code?
132 if(logger.isDebugEnabled()){
133 logger.debug(testName + ": status = " + statusCode);
135 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
136 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
137 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
139 // Store the ID returned from the first resource created
140 // for additional tests below.
141 if (knownResourceId == null){
142 knownResourceId = extractId(res);
143 if (logger.isDebugEnabled()) {
144 logger.debug(testName + ": knownResourceId=" + knownResourceId);
148 // Store the IDs from every resource created by tests,
149 // so they can be deleted after tests have been run.
150 allResourceIdsCreated.add(extractId(res));
154 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
157 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
158 dependsOnMethods = {"create"})
159 public void createList(String testName) throws Exception {
160 for(int i = 0; i < 3; i++){
166 * Tests to diagnose and fix CSPACE-2578.
168 * This is a bug identified in release 1.0 alpha, after first implementing an
169 * Acquisition Funding repeatable group of fields, in which record creation
170 * fails if there is whitespace (or more generally, a text node) between
171 * the acquisitionFunding container element and its first child field.
174 // Verify that record creation occurs successfully when there is NO whitespace
175 // between the acquisitionFunding tag and its first child element tag
176 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
177 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
178 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
179 if (logger.isDebugEnabled()) {
180 logger.debug(testBanner(testName, CLASS_NAME));
182 String testDataDir = System.getProperty("test-data.fileName");
184 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
185 testSubmitRequest(newId);
188 // Verify that record creation occurs successfully when there is whitespace
189 // between the acquisitionFunding tag and its first child element tag
191 // FIXME: This test currently fails. @Test annotation is currently commented
192 // out for check-in, to prevent service tests from failing. Can uncomment to test
193 // fixes, and also after the issue is resolved, to help detect any regressions.
195 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
196 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
197 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
198 if (logger.isDebugEnabled()) {
199 logger.debug(testBanner(testName, CLASS_NAME));
201 String testDataDir = System.getProperty("test-data.fileName");
203 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
204 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
205 testSubmitRequest(newId);
210 // Placeholders until the three tests below can be uncommented.
211 // See Issue CSPACE-401.
213 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
216 public void createWithEmptyEntityBody(String testName) throws Exception {
217 //Should this really be empty?
221 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
224 public void createWithMalformedXml(String testName) throws Exception {
225 //Should this really be empty?
229 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
232 public void createWithWrongXmlSchema(String testName) throws Exception {
233 //Should this really be empty?
238 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
239 dependsOnMethods = {"create", "testSubmitRequest"})
240 public void createWithMalformedXml(String testName) throws Exception {
242 if (logger.isDebugEnabled()) {
243 logger.debug(testBanner(testName, CLASS_NAME));
247 setupCreateWithMalformedXml();
249 // Submit the request to the service and store the response.
250 String method = REQUEST_TYPE.httpMethodName();
251 String url = getServiceRootURL();
252 final String entity = MALFORMED_XML_DATA; // Constant from base class.
253 int statusCode = submitRequest(method, url, entity);
255 // Check the status code of the response: does it match
256 // the expected response(s)?
257 if(logger.isDebugEnabled()){
258 logger.debug(testName + ": url=" + url +
259 " status=" + statusCode);
261 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
262 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
263 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
267 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
268 dependsOnMethods = {"create", "testSubmitRequest"})
269 public void createWithWrongXmlSchema(String testName) throws Exception {
271 if (logger.isDebugEnabled()) {
272 logger.debug(testBanner(testName, CLASS_NAME));
276 setupCreateWithWrongXmlSchema();
278 // Submit the request to the service and store the response.
279 String method = REQUEST_TYPE.httpMethodName();
280 String url = getServiceRootURL();
281 final String entity = WRONG_XML_SCHEMA_DATA;
282 int statusCode = submitRequest(method, url, entity);
284 // Check the status code of the response: does it match
285 // the expected response(s)?
286 if(logger.isDebugEnabled()){
287 logger.debug(testName + ": url=" + url +
288 " status=" + statusCode);
290 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
291 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
292 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
296 // ---------------------------------------------------------------
297 // CRUD tests : READ tests
298 // ---------------------------------------------------------------
301 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
304 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
305 dependsOnMethods = {"create"})
306 public void read(String testName) throws Exception {
308 if (logger.isDebugEnabled()) {
309 logger.debug(testBanner(testName, CLASS_NAME));
315 AcquisitionClient client = new AcquisitionClient();
317 // Submit the request to the service and store the response.
318 ClientResponse<String> res = client.read(knownResourceId);
319 int statusCode = res.getStatus();
321 // Check the status code of the response: does it match
322 // the expected response(s)?
323 if(logger.isDebugEnabled()){
324 logger.debug(testName + ": status = " + statusCode);
326 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
327 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
328 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
330 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
331 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
332 client.getCommonPartName(), AcquisitionsCommon.class);
333 Assert.assertNotNull(acquisitionObject);
335 // Verify the number and contents of values in repeatable fields,
336 // as created in the instance record used for testing.
337 List<String> acqSources =
338 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
339 Assert.assertTrue(acqSources.size() > 0);
340 Assert.assertNotNull(acqSources.get(0));
342 List<String> acqDates =
343 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
344 Assert.assertTrue(acqDates.size() > 0);
345 Assert.assertNotNull(acqDates.get(0));
347 List<String> owners =
348 acquisitionObject.getOwners().getOwner();
349 Assert.assertTrue(owners.size() > 0);
350 Assert.assertNotNull(owners.get(0));
355 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
358 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
359 dependsOnMethods = {"read"})
360 public void readNonExistent(String testName) throws Exception {
362 if (logger.isDebugEnabled()) {
363 logger.debug(testBanner(testName, CLASS_NAME));
367 setupReadNonExistent();
369 // Submit the request to the service and store the response.
370 AcquisitionClient client = new AcquisitionClient();
371 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
372 int statusCode = res.getStatus();
374 // Check the status code of the response: does it match
375 // the expected response(s)?
376 if(logger.isDebugEnabled()){
377 logger.debug(testName + ": status = " + statusCode);
379 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
380 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
381 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
384 // ---------------------------------------------------------------
385 // CRUD tests : READ_LIST tests
386 // ---------------------------------------------------------------
389 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
392 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
393 dependsOnMethods = {"createList", "read"})
394 public void readList(String testName) throws Exception {
396 if (logger.isDebugEnabled()) {
397 logger.debug(testBanner(testName, CLASS_NAME));
403 // Submit the request to the service and store the response.
404 AcquisitionClient client = new AcquisitionClient();
405 ClientResponse<AbstractCommonList> res = client.readList();
406 AbstractCommonList list = res.getEntity();
407 int statusCode = res.getStatus();
409 // Check the status code of the response: does it match
410 // the expected response(s)?
411 if(logger.isDebugEnabled()){
412 logger.debug(testName + ": status = " + statusCode);
414 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
415 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
416 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
418 // Optionally output additional data about list members for debugging.
419 boolean iterateThroughList = false;
420 if(iterateThroughList && logger.isDebugEnabled()){
421 List<AbstractCommonList.ListItem> items =
424 for(AbstractCommonList.ListItem item : items){
425 logger.debug(testName + ": list-item[" + i + "] " +
436 // ---------------------------------------------------------------
437 // CRUD tests : UPDATE tests
438 // ---------------------------------------------------------------
442 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
445 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
446 dependsOnMethods = {"read"})
447 public void update(String testName) throws Exception {
449 if (logger.isDebugEnabled()) {
450 logger.debug(testBanner(testName, CLASS_NAME));
456 // Retrieve the contents of a resource to update.
457 AcquisitionClient client = new AcquisitionClient();
458 ClientResponse<String> res = client.read(knownResourceId);
459 if(logger.isDebugEnabled()){
460 logger.debug(testName + ": read status = " + res.getStatus());
462 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
464 if(logger.isDebugEnabled()){
465 logger.debug("got object to update with ID: " + knownResourceId);
467 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
469 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
470 client.getCommonPartName(), AcquisitionsCommon.class);
471 Assert.assertNotNull(acquisition);
473 // Update the content of this resource.
474 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
475 if(logger.isDebugEnabled()){
476 logger.debug("updated object");
477 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
479 // Submit the request to the service and store the response.
480 PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
481 PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
482 commonPart.setLabel(client.getCommonPartName());
484 res = client.update(knownResourceId, output);
485 int statusCode = res.getStatus();
486 // Check the status code of the response: does it match the expected response(s)?
487 if(logger.isDebugEnabled()){
488 logger.debug(testName + ": status = " + statusCode);
490 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
491 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
492 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
495 input = new PoxPayloadIn(res.getEntity());
496 AcquisitionsCommon updatedAcquisition =
497 (AcquisitionsCommon) extractPart(input,
498 client.getCommonPartName(), AcquisitionsCommon.class);
499 Assert.assertNotNull(updatedAcquisition);
501 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
502 acquisition.getAcquisitionReferenceNumber(),
503 "Data in updated object did not match submitted data.");
508 // Placeholders until the three tests below can be uncommented.
509 // See Issue CSPACE-401.
511 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
514 public void updateWithEmptyEntityBody(String testName) throws Exception {
515 //Should this really be empty?
519 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
522 public void updateWithMalformedXml(String testName) throws Exception {
523 //Should this really be empty?
527 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
530 public void updateWithWrongXmlSchema(String testName) throws Exception {
531 //Should this really be empty?
536 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
537 dependsOnMethods = {"create", "update", "testSubmitRequest"})
538 public void updateWithEmptyEntityBody(String testName) throws Exception {
540 if (logger.isDebugEnabled()) {
541 logger.debug(testBanner(testName, CLASS_NAME));
545 setupUpdateWithEmptyEntityBody();
547 // Submit the request to the service and store the response.
548 String method = REQUEST_TYPE.httpMethodName();
549 String url = getResourceURL(knownResourceId);
550 String mediaType = MediaType.APPLICATION_XML;
551 final String entity = "";
552 int statusCode = submitRequest(method, url, mediaType, entity);
554 // Check the status code of the response: does it match
555 // the expected response(s)?
556 if(logger.isDebugEnabled()){
557 (testName + ": url=" + url + " status=" + statusCode);
559 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
560 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
561 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
565 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
566 dependsOnMethods = {"create", "testSubmitRequest"})
567 public void createWithEmptyEntityBody(String testName) throws Exception {
569 if (logger.isDebugEnabled()) {
570 logger.debug(testBanner(testName, CLASS_NAME));
574 setupCreateWithEmptyEntityBody();
576 // Submit the request to the service and store the response.
577 String method = REQUEST_TYPE.httpMethodName();
578 String url = getServiceRootURL();
579 String mediaType = MediaType.APPLICATION_XML;
580 final String entity = "";
581 int statusCode = submitRequest(method, url, mediaType, entity);
583 // Check the status code of the response: does it match
584 // the expected response(s)?
585 if(logger.isDebugEnabled()){
586 logger.debug(testName + ": url=" + url +
587 " status=" + statusCode);
589 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
590 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
591 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
595 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
596 dependsOnMethods = {"create", "update", "testSubmitRequest"})
597 public void updateWithMalformedXml(String testName) throws Exception {
599 if (logger.isDebugEnabled()) {
600 logger.debug(testBanner(testName, CLASS_NAME));
604 setupUpdateWithMalformedXml();
606 // Submit the request to the service and store the response.
607 String method = REQUEST_TYPE.httpMethodName();
608 String url = getResourceURL(knownResourceId);
609 final String entity = MALFORMED_XML_DATA;
610 int statusCode = submitRequest(method, url, entity);
612 // Check the status code of the response: does it match
613 // the expected response(s)?
614 if(logger.isDebugEnabled()){
615 logger.debug(testName + ": url=" + url +
616 " status=" + statusCode);
618 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
619 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
620 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
624 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
625 public void updateWithWrongXmlSchema(String testName) {
627 if (logger.isDebugEnabled()) {
628 logger.debug(testBanner(testName, CLASS_NAME));
632 setupUpdateWithWrongXmlSchema();
634 // Submit the request to the service and store the response.
635 String method = REQUEST_TYPE.httpMethodName();
636 String url = getResourceURL(knownResourceId);
637 final String entity = WRONG_XML_SCHEMA_DATA;
638 int statusCode = submitRequest(method, url, entity);
640 // Check the status code of the response: does it match
641 // the expected response(s)?
642 if(logger.isDebugEnabled()){
643 logger.debug(testName + ": url=" + url +
644 " status=" + statusCode);
646 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
647 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
648 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
653 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
656 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
657 dependsOnMethods = {"update", "testSubmitRequest"})
658 public void updateNonExistent(String testName) throws Exception {
660 if (logger.isDebugEnabled()) {
661 logger.debug(testBanner(testName, CLASS_NAME));
665 setupUpdateNonExistent();
667 // Submit the request to the service and store the response.
668 // Note: The ID used in this 'create' call may be arbitrary.
669 // The only relevant ID may be the one used in update(), below.
670 AcquisitionClient client = new AcquisitionClient();
671 PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
672 ClientResponse<String> res =
673 client.update(NON_EXISTENT_ID, multipart);
674 int statusCode = res.getStatus();
676 // Check the status code of the response: does it match
677 // the expected response(s)?
678 if(logger.isDebugEnabled()){
679 logger.debug(testName + ": status = " + statusCode);
681 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
682 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
683 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
686 // ---------------------------------------------------------------
687 // CRUD tests : DELETE tests
688 // ---------------------------------------------------------------
691 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
694 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
695 dependsOnMethods = {"create", "read", "update"})
696 public void delete(String testName) throws Exception {
698 if (logger.isDebugEnabled()) {
699 logger.debug(testBanner(testName, CLASS_NAME));
705 // Submit the request to the service and store the response.
706 AcquisitionClient client = new AcquisitionClient();
707 ClientResponse<Response> res = client.delete(knownResourceId);
708 int statusCode = res.getStatus();
710 // Check the status code of the response: does it match
711 // the expected response(s)?
712 if(logger.isDebugEnabled()){
713 logger.debug(testName + ": status = " + statusCode);
715 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
716 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
717 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
722 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
725 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
726 dependsOnMethods = {"delete"})
727 public void deleteNonExistent(String testName) throws Exception {
729 if (logger.isDebugEnabled()) {
730 logger.debug(testBanner(testName, CLASS_NAME));
734 setupDeleteNonExistent();
736 // Submit the request to the service and store the response.
737 AcquisitionClient client = new AcquisitionClient();
738 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
739 int statusCode = res.getStatus();
741 // Check the status code of the response: does it match
742 // the expected response(s)?
743 if(logger.isDebugEnabled()){
744 logger.debug(testName + ": status = " + statusCode);
746 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
747 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
748 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
751 // ---------------------------------------------------------------
752 // Utility tests : tests of code used in tests above
753 // ---------------------------------------------------------------
755 * Tests the code for manually submitting data that is used by several
756 * of the methods above.
760 @Test(dependsOnMethods = {"create", "read"})
761 public void testSubmitRequest() throws Exception {
762 testSubmitRequest(knownResourceId);
766 * Test submit request.
768 * @param resourceId the resource id
769 * @throws Exception the exception
771 private void testSubmitRequest(String resourceId) throws Exception {
773 // Expected status code: 200 OK
774 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
776 // Submit the request to the service and store the response.
777 String method = ServiceRequestType.READ.httpMethodName();
778 String url = getResourceURL(resourceId);
779 int statusCode = submitRequest(method, url);
781 // Check the status code of the response: does it match
782 // the expected response(s)?
783 if (logger.isDebugEnabled()) {
784 logger.debug("testSubmitRequest: url=" + url
785 + " status=" + statusCode);
787 Assert.assertEquals(statusCode, EXPECTED_STATUS);
791 // ---------------------------------------------------------------
792 // Utility methods used by tests above
793 // ---------------------------------------------------------------
796 * Creates the acquisition instance.
798 * @param identifier the identifier
799 * @return the multipart output
801 private PoxPayloadOut createAcquisitionInstance(String identifier) {
802 AcquisitionsCommon acquisition = new AcquisitionsCommon();
803 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
805 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
806 List<String> acqSources = acqSourcesList.getAcquisitionSource();
807 // FIXME Use properly formatted refNames for representative acquisition
808 // sources in this example test record. The following are mere placeholders.
809 acqSources.add("Donor Acquisition Source-" + identifier);
810 acqSources.add("Museum Acquisition Source-" + identifier);
811 acquisition.setAcquisitionSources(acqSourcesList);
813 AcquisitionDateList acqDatesList = new AcquisitionDateList();
814 List<String> acqDates = acqDatesList.getAcquisitionDate();
815 // FIXME Use properly timestamps for representative acquisition
816 // dates in this example test record. The following are mere placeholders.
817 acqDates.add("First Acquisition Date -" + identifier);
818 acqDates.add("Second Acquisition Date-" + identifier);
819 acquisition.setAcquisitionDates(acqDatesList);
821 OwnerList ownersList = new OwnerList();
822 List<String> owners = ownersList.getOwner();
823 // FIXME Use properly formatted refNames for representative owners
824 // in this example test record. The following are mere placeholders.
825 owners.add("First Owner -" + identifier);
826 owners.add("Second Owner-" + identifier);
827 acquisition.setOwners(ownersList);
829 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
830 PayloadOutputPart commonPart = multipart.addPart(acquisition,
831 MediaType.APPLICATION_XML_TYPE);
832 commonPart.setLabel(new AcquisitionClient().getCommonPartName());
834 if(logger.isDebugEnabled()){
835 logger.debug("to be created, acquisition common");
836 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
841 // FIXME: The following methods might be made generic and moved to a common package.
844 * Retrives an XML document from the given file, and uses
845 * the JAXB unmarshaller to create a Java object representation
846 * and ultimately a multipart payload that can be submitted in
847 * a create or update request.
849 * @param commonPartName
850 * @param commonPartFileName
854 private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
855 String commonPartFileName) throws Exception {
857 AcquisitionsCommon acquisition =
858 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
860 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
861 PayloadOutputPart commonPart = multipart.addPart(acquisition,
862 MediaType.APPLICATION_XML_TYPE);
863 commonPart.setLabel(commonPartName);
865 if (logger.isDebugEnabled()) {
866 logger.debug(testName + " to be created, acquisitions common");
867 logger.debug(objectAsXmlString(acquisition,
868 AcquisitionsCommon.class));
875 * Creates a record / resource from the data in an XML file.
877 * @param testName the test name
878 * @param fileName the file name
879 * @param useJaxb the use jaxb
881 * @throws Exception the exception
883 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
888 PoxPayloadOut multipart = null;
890 AcquisitionClient client = new AcquisitionClient();
892 multipart = createAcquisitionInstanceFromXml(testName,
893 client.getCommonPartName(), fileName);
896 multipart = createAcquisitionInstanceFromRawXml(testName,
897 client.getCommonPartName(), fileName);
899 ClientResponse<Response> res = client.create(multipart);
900 int statusCode = res.getStatus();
902 if (logger.isDebugEnabled()) {
903 logger.debug(testName + ": status = " + statusCode);
905 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
906 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
907 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
908 String newId = extractId(res);
909 allResourceIdsCreated.add(newId);
914 * Returns a multipart payload that can be submitted with a
915 * create or update request, by reading from an XML file.
917 * @param commonPartName
918 * @param commonPartFileName
922 private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
923 String commonPartFileName) throws Exception {
925 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
926 String stringObject = getXmlDocumentAsString(commonPartFileName);
927 if (logger.isDebugEnabled()) {
928 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
930 PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
931 commonPart.setLabel(commonPartName);
937 // FIXME: This duplicates code in read(), and should be consolidated.
938 // This is an expedient to support reading and verifying the contents
939 // of resources that have been created from test data XML files.
940 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
943 String testName = "readAcquisitionCommonPart";
947 // Submit the request to the service and store the response.
948 AcquisitionClient client = new AcquisitionClient();
949 ClientResponse<String> res = client.read(csid);
950 int statusCode = res.getStatus();
952 // Check the status code of the response: does it match
953 // the expected response(s)?
954 if (logger.isDebugEnabled()) {
955 logger.debug(testName + ": status = " + statusCode);
957 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
958 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
959 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
961 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
963 if (logger.isDebugEnabled()) {
964 logger.debug(testName + ": Reading Common part ...");
966 AcquisitionsCommon acquisition =
967 (AcquisitionsCommon) extractPart(input,
968 client.getCommonPartName(), AcquisitionsCommon.class);
969 Assert.assertNotNull(acquisition);