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.AcquisitionSourceList;
39 import org.collectionspace.services.acquisition.OwnerList;
40 import org.jboss.resteasy.client.ClientResponse;
41 import org.w3c.dom.Element;
42 import org.w3c.dom.Node;
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;
68 public String getServicePathComponent() {
69 return AcquisitionClient.SERVICE_PATH_COMPONENT;
74 protected String getServiceName() {
75 return AcquisitionClient.SERVICE_NAME;
79 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
82 protected CollectionSpaceClient getClientInstance() {
83 return new AcquisitionClient();
87 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
90 protected AbstractCommonList getAbstractCommonList(
91 ClientResponse<AbstractCommonList> response) {
92 return response.getEntity(AbstractCommonList.class);
95 // ---------------------------------------------------------------
96 // CRUD tests : CREATE tests
97 // ---------------------------------------------------------------
100 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
103 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
104 public void create(String testName) throws Exception {
106 if (logger.isDebugEnabled()) {
107 logger.debug(testBanner(testName, CLASS_NAME));
110 // Perform setup, such as initializing the type of service request
111 // (e.g. CREATE, DELETE), its valid and expected status codes, and
112 // its associated HTTP method name (e.g. POST, DELETE).
115 // Submit the request to the service and store the response.
116 String identifier = createIdentifier();
118 AcquisitionClient client = new AcquisitionClient();
119 PoxPayloadOut multipart = createAcquisitionInstance(identifier);
120 ClientResponse<Response> res = client.create(multipart);
122 int statusCode = res.getStatus();
124 // Check the status code of the response: does it match
125 // the expected response(s)?
128 // Does it fall within the set of valid status codes?
129 // Does it exactly match the expected status code?
130 if(logger.isDebugEnabled()){
131 logger.debug(testName + ": status = " + statusCode);
133 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
134 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
135 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
137 // Store the ID returned from the first resource created
138 // for additional tests below.
139 if (knownResourceId == null){
140 knownResourceId = extractId(res);
141 if (logger.isDebugEnabled()) {
142 logger.debug(testName + ": knownResourceId=" + knownResourceId);
146 // Store the IDs from every resource created by tests,
147 // so they can be deleted after tests have been run.
148 allResourceIdsCreated.add(extractId(res));
152 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
155 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
156 dependsOnMethods = {"create"})
157 public void createList(String testName) throws Exception {
158 for(int i = 0; i < 3; i++){
164 * Tests to diagnose and fix CSPACE-2578.
166 * This is a bug identified in release 1.0 alpha, after first implementing an
167 * Acquisition Funding repeatable group of fields, in which record creation
168 * fails if there is whitespace (or more generally, a text node) between
169 * the acquisitionFunding container element and its first child field.
172 // Verify that record creation occurs successfully when there is NO whitespace
173 // between the acquisitionFunding tag and its first child element tag
174 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
175 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
176 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
177 if (logger.isDebugEnabled()) {
178 logger.debug(testBanner(testName, CLASS_NAME));
180 String testDataDir = System.getProperty("test-data.fileName");
182 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
183 testSubmitRequest(newId);
186 // Verify that record creation occurs successfully when there is whitespace
187 // between the acquisitionFunding tag and its first child element tag
189 // FIXME: This test currently fails. @Test annotation is currently commented
190 // out for check-in, to prevent service tests from failing. Can uncomment to test
191 // fixes, and also after the issue is resolved, to help detect any regressions.
193 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
194 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
195 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
196 if (logger.isDebugEnabled()) {
197 logger.debug(testBanner(testName, CLASS_NAME));
199 String testDataDir = System.getProperty("test-data.fileName");
201 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
202 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
203 testSubmitRequest(newId);
208 // Placeholders until the three tests below can be uncommented.
209 // See Issue CSPACE-401.
211 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
214 public void createWithEmptyEntityBody(String testName) throws Exception {
215 //Should this really be empty?
219 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
222 public void createWithMalformedXml(String testName) throws Exception {
223 //Should this really be empty?
227 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
230 public void createWithWrongXmlSchema(String testName) throws Exception {
231 //Should this really be empty?
236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
237 dependsOnMethods = {"create", "testSubmitRequest"})
238 public void createWithMalformedXml(String testName) throws Exception {
240 if (logger.isDebugEnabled()) {
241 logger.debug(testBanner(testName, CLASS_NAME));
245 setupCreateWithMalformedXml();
247 // Submit the request to the service and store the response.
248 String method = REQUEST_TYPE.httpMethodName();
249 String url = getServiceRootURL();
250 final String entity = MALFORMED_XML_DATA; // Constant from base class.
251 int statusCode = submitRequest(method, url, entity);
253 // Check the status code of the response: does it match
254 // the expected response(s)?
255 if(logger.isDebugEnabled()){
256 logger.debug(testName + ": url=" + url +
257 " status=" + statusCode);
259 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
260 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
261 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
265 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
266 dependsOnMethods = {"create", "testSubmitRequest"})
267 public void createWithWrongXmlSchema(String testName) throws Exception {
269 if (logger.isDebugEnabled()) {
270 logger.debug(testBanner(testName, CLASS_NAME));
274 setupCreateWithWrongXmlSchema();
276 // Submit the request to the service and store the response.
277 String method = REQUEST_TYPE.httpMethodName();
278 String url = getServiceRootURL();
279 final String entity = WRONG_XML_SCHEMA_DATA;
280 int statusCode = submitRequest(method, url, entity);
282 // Check the status code of the response: does it match
283 // the expected response(s)?
284 if(logger.isDebugEnabled()){
285 logger.debug(testName + ": url=" + url +
286 " status=" + statusCode);
288 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
289 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
290 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
294 // ---------------------------------------------------------------
295 // CRUD tests : READ tests
296 // ---------------------------------------------------------------
299 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
302 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
303 dependsOnMethods = {"create"})
304 public void read(String testName) throws Exception {
306 if (logger.isDebugEnabled()) {
307 logger.debug(testBanner(testName, CLASS_NAME));
313 AcquisitionClient client = new AcquisitionClient();
315 // Submit the request to the service and store the response.
316 ClientResponse<String> res = client.read(knownResourceId);
317 int statusCode = res.getStatus();
319 // Check the status code of the response: does it match
320 // the expected response(s)?
321 if(logger.isDebugEnabled()){
322 logger.debug(testName + ": status = " + statusCode);
324 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
325 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
326 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
328 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
329 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
330 client.getCommonPartName(), AcquisitionsCommon.class);
331 Assert.assertNotNull(acquisitionObject);
333 // Verify the number and contents of values in repeatable fields,
334 // as created in the instance record used for testing.
335 List<String> acqSources =
336 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
337 Assert.assertTrue(acqSources.size() > 0);
338 Assert.assertNotNull(acqSources.get(0));
340 List<String> acqDates =
341 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
342 Assert.assertTrue(acqDates.size() > 0);
343 Assert.assertNotNull(acqDates.get(0));
345 List<String> owners =
346 acquisitionObject.getOwners().getOwner();
347 Assert.assertTrue(owners.size() > 0);
348 Assert.assertNotNull(owners.get(0));
353 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
356 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
357 dependsOnMethods = {"read"})
358 public void readNonExistent(String testName) throws Exception {
360 if (logger.isDebugEnabled()) {
361 logger.debug(testBanner(testName, CLASS_NAME));
365 setupReadNonExistent();
367 // Submit the request to the service and store the response.
368 AcquisitionClient client = new AcquisitionClient();
369 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
370 int statusCode = res.getStatus();
372 // Check the status code of the response: does it match
373 // the expected response(s)?
374 if(logger.isDebugEnabled()){
375 logger.debug(testName + ": status = " + statusCode);
377 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
378 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
379 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
382 // ---------------------------------------------------------------
383 // CRUD tests : READ_LIST tests
384 // ---------------------------------------------------------------
387 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
390 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
391 dependsOnMethods = {"createList", "read"})
392 public void readList(String testName) throws Exception {
394 if (logger.isDebugEnabled()) {
395 logger.debug(testBanner(testName, CLASS_NAME));
401 // Submit the request to the service and store the response.
402 AcquisitionClient client = new AcquisitionClient();
403 ClientResponse<AbstractCommonList> res = client.readList();
404 AbstractCommonList list = res.getEntity();
405 int statusCode = res.getStatus();
407 // Check the status code of the response: does it match
408 // the expected response(s)?
409 if(logger.isDebugEnabled()){
410 logger.debug(testName + ": status = " + statusCode);
412 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
413 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
414 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
416 // Optionally output additional data about list members for debugging.
417 boolean iterateThroughList = true;
418 if(iterateThroughList && logger.isDebugEnabled()){
419 List<AbstractCommonList.ListItem> items =
422 for(AbstractCommonList.ListItem item : items){
423 List<Element> elList = item.getAny();
424 StringBuilder elementStrings = new StringBuilder();
425 for(Element el : elList) {
426 Node textEl = el.getFirstChild();
427 elementStrings.append("["+el.getNodeName()+":"+((textEl!=null)?textEl.getNodeValue():"NULL")+"] ");
429 logger.debug(testName + ": list-item[" + i + "]: "+elementStrings.toString());
439 // ---------------------------------------------------------------
440 // CRUD tests : UPDATE tests
441 // ---------------------------------------------------------------
445 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
448 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
449 dependsOnMethods = {"read"})
450 public void update(String testName) throws Exception {
452 if (logger.isDebugEnabled()) {
453 logger.debug(testBanner(testName, CLASS_NAME));
459 // Retrieve the contents of a resource to update.
460 AcquisitionClient client = new AcquisitionClient();
461 ClientResponse<String> res = client.read(knownResourceId);
462 if(logger.isDebugEnabled()){
463 logger.debug(testName + ": read status = " + res.getStatus());
465 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
467 if(logger.isDebugEnabled()){
468 logger.debug("got object to update with ID: " + knownResourceId);
470 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
472 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
473 client.getCommonPartName(), AcquisitionsCommon.class);
474 Assert.assertNotNull(acquisition);
476 // Update the content of this resource.
477 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
478 if(logger.isDebugEnabled()){
479 logger.debug("updated object");
480 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
482 // Submit the request to the service and store the response.
483 PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
484 PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
485 commonPart.setLabel(client.getCommonPartName());
487 res = client.update(knownResourceId, output);
488 int statusCode = res.getStatus();
489 // Check the status code of the response: does it match the expected response(s)?
490 if(logger.isDebugEnabled()){
491 logger.debug(testName + ": status = " + statusCode);
493 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
494 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
495 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
498 input = new PoxPayloadIn(res.getEntity());
499 AcquisitionsCommon updatedAcquisition =
500 (AcquisitionsCommon) extractPart(input,
501 client.getCommonPartName(), AcquisitionsCommon.class);
502 Assert.assertNotNull(updatedAcquisition);
504 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
505 acquisition.getAcquisitionReferenceNumber(),
506 "Data in updated object did not match submitted data.");
511 // Placeholders until the three tests below can be uncommented.
512 // See Issue CSPACE-401.
514 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
517 public void updateWithEmptyEntityBody(String testName) throws Exception {
518 //Should this really be empty?
522 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
525 public void updateWithMalformedXml(String testName) throws Exception {
526 //Should this really be empty?
530 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
533 public void updateWithWrongXmlSchema(String testName) throws Exception {
534 //Should this really be empty?
539 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
540 dependsOnMethods = {"create", "update", "testSubmitRequest"})
541 public void updateWithEmptyEntityBody(String testName) throws Exception {
543 if (logger.isDebugEnabled()) {
544 logger.debug(testBanner(testName, CLASS_NAME));
548 setupUpdateWithEmptyEntityBody();
550 // Submit the request to the service and store the response.
551 String method = REQUEST_TYPE.httpMethodName();
552 String url = getResourceURL(knownResourceId);
553 String mediaType = MediaType.APPLICATION_XML;
554 final String entity = "";
555 int statusCode = submitRequest(method, url, mediaType, entity);
557 // Check the status code of the response: does it match
558 // the expected response(s)?
559 if(logger.isDebugEnabled()){
560 (testName + ": url=" + url + " status=" + statusCode);
562 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
563 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
564 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
568 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
569 dependsOnMethods = {"create", "testSubmitRequest"})
570 public void createWithEmptyEntityBody(String testName) throws Exception {
572 if (logger.isDebugEnabled()) {
573 logger.debug(testBanner(testName, CLASS_NAME));
577 setupCreateWithEmptyEntityBody();
579 // Submit the request to the service and store the response.
580 String method = REQUEST_TYPE.httpMethodName();
581 String url = getServiceRootURL();
582 String mediaType = MediaType.APPLICATION_XML;
583 final String entity = "";
584 int statusCode = submitRequest(method, url, mediaType, entity);
586 // Check the status code of the response: does it match
587 // the expected response(s)?
588 if(logger.isDebugEnabled()){
589 logger.debug(testName + ": url=" + url +
590 " status=" + statusCode);
592 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
593 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
594 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
598 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
599 dependsOnMethods = {"create", "update", "testSubmitRequest"})
600 public void updateWithMalformedXml(String testName) throws Exception {
602 if (logger.isDebugEnabled()) {
603 logger.debug(testBanner(testName, CLASS_NAME));
607 setupUpdateWithMalformedXml();
609 // Submit the request to the service and store the response.
610 String method = REQUEST_TYPE.httpMethodName();
611 String url = getResourceURL(knownResourceId);
612 final String entity = MALFORMED_XML_DATA;
613 int statusCode = submitRequest(method, url, entity);
615 // Check the status code of the response: does it match
616 // the expected response(s)?
617 if(logger.isDebugEnabled()){
618 logger.debug(testName + ": url=" + url +
619 " status=" + statusCode);
621 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
622 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
623 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
627 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
628 public void updateWithWrongXmlSchema(String testName) {
630 if (logger.isDebugEnabled()) {
631 logger.debug(testBanner(testName, CLASS_NAME));
635 setupUpdateWithWrongXmlSchema();
637 // Submit the request to the service and store the response.
638 String method = REQUEST_TYPE.httpMethodName();
639 String url = getResourceURL(knownResourceId);
640 final String entity = WRONG_XML_SCHEMA_DATA;
641 int statusCode = submitRequest(method, url, entity);
643 // Check the status code of the response: does it match
644 // the expected response(s)?
645 if(logger.isDebugEnabled()){
646 logger.debug(testName + ": url=" + url +
647 " status=" + statusCode);
649 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
650 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
651 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
656 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
659 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
660 dependsOnMethods = {"update", "testSubmitRequest"})
661 public void updateNonExistent(String testName) throws Exception {
663 if (logger.isDebugEnabled()) {
664 logger.debug(testBanner(testName, CLASS_NAME));
668 setupUpdateNonExistent();
670 // Submit the request to the service and store the response.
671 // Note: The ID used in this 'create' call may be arbitrary.
672 // The only relevant ID may be the one used in update(), below.
673 AcquisitionClient client = new AcquisitionClient();
674 PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
675 ClientResponse<String> res =
676 client.update(NON_EXISTENT_ID, multipart);
677 int statusCode = res.getStatus();
679 // Check the status code of the response: does it match
680 // the expected response(s)?
681 if(logger.isDebugEnabled()){
682 logger.debug(testName + ": status = " + statusCode);
684 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
685 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
686 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
689 // ---------------------------------------------------------------
690 // CRUD tests : DELETE tests
691 // ---------------------------------------------------------------
694 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
697 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
698 dependsOnMethods = {"create", "read", "update"})
699 public void delete(String testName) throws Exception {
701 if (logger.isDebugEnabled()) {
702 logger.debug(testBanner(testName, CLASS_NAME));
708 // Submit the request to the service and store the response.
709 AcquisitionClient client = new AcquisitionClient();
710 ClientResponse<Response> res = client.delete(knownResourceId);
711 int statusCode = res.getStatus();
713 // Check the status code of the response: does it match
714 // the expected response(s)?
715 if(logger.isDebugEnabled()){
716 logger.debug(testName + ": status = " + statusCode);
718 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
719 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
720 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
725 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
728 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
729 dependsOnMethods = {"delete"})
730 public void deleteNonExistent(String testName) throws Exception {
732 if (logger.isDebugEnabled()) {
733 logger.debug(testBanner(testName, CLASS_NAME));
737 setupDeleteNonExistent();
739 // Submit the request to the service and store the response.
740 AcquisitionClient client = new AcquisitionClient();
741 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
742 int statusCode = res.getStatus();
744 // Check the status code of the response: does it match
745 // the expected response(s)?
746 if(logger.isDebugEnabled()){
747 logger.debug(testName + ": status = " + statusCode);
749 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
750 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
751 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
754 // ---------------------------------------------------------------
755 // Utility tests : tests of code used in tests above
756 // ---------------------------------------------------------------
758 * Tests the code for manually submitting data that is used by several
759 * of the methods above.
763 @Test(dependsOnMethods = {"create", "read"})
764 public void testSubmitRequest() throws Exception {
765 testSubmitRequest(knownResourceId);
769 * Test submit request.
771 * @param resourceId the resource id
772 * @throws Exception the exception
774 private void testSubmitRequest(String resourceId) throws Exception {
776 // Expected status code: 200 OK
777 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
779 // Submit the request to the service and store the response.
780 String method = ServiceRequestType.READ.httpMethodName();
781 String url = getResourceURL(resourceId);
782 int statusCode = submitRequest(method, url);
784 // Check the status code of the response: does it match
785 // the expected response(s)?
786 if (logger.isDebugEnabled()) {
787 logger.debug("testSubmitRequest: url=" + url
788 + " status=" + statusCode);
790 Assert.assertEquals(statusCode, EXPECTED_STATUS);
794 // ---------------------------------------------------------------
795 // Utility methods used by tests above
796 // ---------------------------------------------------------------
799 protected PoxPayloadOut createInstance(String identifier) {
800 return createAcquisitionInstance(identifier);
804 * Creates the acquisition instance.
806 * @param identifier the identifier
807 * @return the multipart output
809 private PoxPayloadOut createAcquisitionInstance(String identifier) {
810 AcquisitionsCommon acquisition = new AcquisitionsCommon();
811 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
813 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
814 List<String> acqSources = acqSourcesList.getAcquisitionSource();
815 // FIXME Use properly formatted refNames for representative acquisition
816 // sources in this example test record. The following are mere placeholders.
817 acqSources.add("Donor Acquisition Source-" + identifier);
818 acqSources.add("Museum Acquisition Source-" + identifier);
819 acquisition.setAcquisitionSources(acqSourcesList);
821 AcquisitionDateList acqDatesList = new AcquisitionDateList();
822 List<String> acqDates = acqDatesList.getAcquisitionDate();
823 // FIXME Use properly timestamps for representative acquisition
824 // dates in this example test record. The following are mere placeholders.
825 acqDates.add("First Acquisition Date -" + identifier);
826 acqDates.add("Second Acquisition Date-" + identifier);
827 acquisition.setAcquisitionDates(acqDatesList);
829 OwnerList ownersList = new OwnerList();
830 List<String> owners = ownersList.getOwner();
831 // FIXME Use properly formatted refNames for representative owners
832 // in this example test record. The following are mere placeholders.
833 owners.add("First Owner -" + identifier);
834 owners.add("Second Owner-" + identifier);
835 acquisition.setOwners(ownersList);
837 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
838 PayloadOutputPart commonPart = multipart.addPart(acquisition,
839 MediaType.APPLICATION_XML_TYPE);
840 commonPart.setLabel(new AcquisitionClient().getCommonPartName());
842 if(logger.isDebugEnabled()){
843 logger.debug("to be created, acquisition common");
844 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
849 // FIXME: The following methods might be made generic and moved to a common package.
852 * Retrives an XML document from the given file, and uses
853 * the JAXB unmarshaller to create a Java object representation
854 * and ultimately a multipart payload that can be submitted in
855 * a create or update request.
857 * @param commonPartName
858 * @param commonPartFileName
862 private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
863 String commonPartFileName) throws Exception {
865 AcquisitionsCommon acquisition =
866 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
868 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
869 PayloadOutputPart commonPart = multipart.addPart(acquisition,
870 MediaType.APPLICATION_XML_TYPE);
871 commonPart.setLabel(commonPartName);
873 if (logger.isDebugEnabled()) {
874 logger.debug(testName + " to be created, acquisitions common");
875 logger.debug(objectAsXmlString(acquisition,
876 AcquisitionsCommon.class));
883 * Creates a record / resource from the data in an XML file.
885 * @param testName the test name
886 * @param fileName the file name
887 * @param useJaxb the use jaxb
889 * @throws Exception the exception
891 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
896 PoxPayloadOut multipart = null;
898 AcquisitionClient client = new AcquisitionClient();
900 multipart = createAcquisitionInstanceFromXml(testName,
901 client.getCommonPartName(), fileName);
904 multipart = createAcquisitionInstanceFromRawXml(testName,
905 client.getCommonPartName(), fileName);
907 ClientResponse<Response> res = client.create(multipart);
908 int statusCode = res.getStatus();
910 if (logger.isDebugEnabled()) {
911 logger.debug(testName + ": status = " + statusCode);
913 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
914 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
915 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
916 String newId = extractId(res);
917 allResourceIdsCreated.add(newId);
922 * Returns a multipart payload that can be submitted with a
923 * create or update request, by reading from an XML file.
925 * @param commonPartName
926 * @param commonPartFileName
930 private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
931 String commonPartFileName) throws Exception {
933 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
934 String stringObject = getXmlDocumentAsString(commonPartFileName);
935 if (logger.isDebugEnabled()) {
936 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
938 PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
939 commonPart.setLabel(commonPartName);
945 // FIXME: This duplicates code in read(), and should be consolidated.
946 // This is an expedient to support reading and verifying the contents
947 // of resources that have been created from test data XML files.
948 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
951 String testName = "readAcquisitionCommonPart";
955 // Submit the request to the service and store the response.
956 AcquisitionClient client = new AcquisitionClient();
957 ClientResponse<String> res = client.read(csid);
958 int statusCode = res.getStatus();
960 // Check the status code of the response: does it match
961 // the expected response(s)?
962 if (logger.isDebugEnabled()) {
963 logger.debug(testName + ": status = " + statusCode);
965 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
966 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
967 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
969 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
971 if (logger.isDebugEnabled()) {
972 logger.debug(testName + ": Reading Common part ...");
974 AcquisitionsCommon acquisition =
975 (AcquisitionsCommon) extractPart(input,
976 client.getCommonPartName(), AcquisitionsCommon.class);
977 Assert.assertNotNull(acquisition);