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.jaxb.AbstractCommonList;
33 import org.collectionspace.services.acquisition.AcquisitionsCommon;
34 import org.collectionspace.services.acquisition.AcquisitionsCommonList;
35 import org.collectionspace.services.acquisition.AcquisitionDateList;
36 import org.collectionspace.services.acquisition.AcquisitionFunding;
37 import org.collectionspace.services.acquisition.AcquisitionFundingList;
38 import org.collectionspace.services.acquisition.AcquisitionSourceList;
39 import org.jboss.resteasy.client.ClientResponse;
41 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
42 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
43 import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
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 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
71 protected CollectionSpaceClient getClientInstance() {
72 return new AcquisitionClient();
76 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
79 protected AbstractCommonList getAbstractCommonList(
80 ClientResponse<AbstractCommonList> response) {
81 return response.getEntity(AcquisitionsCommonList.class);
84 // ---------------------------------------------------------------
85 // CRUD tests : CREATE tests
86 // ---------------------------------------------------------------
89 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
92 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
93 public void create(String testName) throws Exception {
95 if (logger.isDebugEnabled()) {
96 logger.debug(testBanner(testName, CLASS_NAME));
99 // Perform setup, such as initializing the type of service request
100 // (e.g. CREATE, DELETE), its valid and expected status codes, and
101 // its associated HTTP method name (e.g. POST, DELETE).
104 // Submit the request to the service and store the response.
105 String identifier = createIdentifier();
107 AcquisitionClient client = new AcquisitionClient();
108 MultipartOutput multipart = createAcquisitionInstance(identifier);
109 ClientResponse<Response> res = client.create(multipart);
111 int statusCode = res.getStatus();
113 // Check the status code of the response: does it match
114 // the expected response(s)?
117 // Does it fall within the set of valid status codes?
118 // Does it exactly match the expected status code?
119 if(logger.isDebugEnabled()){
120 logger.debug(testName + ": status = " + statusCode);
122 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
123 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
124 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
126 // Store the ID returned from the first resource created
127 // for additional tests below.
128 if (knownResourceId == null){
129 knownResourceId = extractId(res);
130 if (logger.isDebugEnabled()) {
131 logger.debug(testName + ": knownResourceId=" + knownResourceId);
135 // Store the IDs from every resource created by tests,
136 // so they can be deleted after tests have been run.
137 allResourceIdsCreated.add(extractId(res));
141 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
144 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
145 dependsOnMethods = {"create"})
146 public void createList(String testName) throws Exception {
147 for(int i = 0; i < 3; i++){
153 * Tests to diagnose and fix CSPACE-2578.
155 * This is a bug identified in release 1.0 alpha, after first implementing an
156 * Acquisition Funding repeatable group of fields, in which record creation
157 * fails if there is whitespace (or more generally, a text node) between
158 * the acquisitionFunding container element and its first child field.
161 // Verify that record creation occurs successfully when there is NO whitespace
162 // between the acquisitionFunding tag and its first child element tag
163 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
164 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
165 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
166 if (logger.isDebugEnabled()) {
167 logger.debug(testBanner(testName, CLASS_NAME));
169 String testDataDir = System.getProperty("test-data.fileName");
171 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
172 testSubmitRequest(newId);
175 // Verify that record creation occurs successfully when there is whitespace
176 // between the acquisitionFunding tag and its first child element tag
178 // FIXME: This test currently fails. @Test annotation is currently commented
179 // out for check-in, to prevent service tests from failing. Can uncomment to test
180 // fixes, and also after the issue is resolved, to help detect any regressions.
182 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
183 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
184 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
185 if (logger.isDebugEnabled()) {
186 logger.debug(testBanner(testName, CLASS_NAME));
188 String testDataDir = System.getProperty("test-data.fileName");
190 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
191 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
192 testSubmitRequest(newId);
197 // Placeholders until the three tests below can be uncommented.
198 // See Issue CSPACE-401.
200 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
203 public void createWithEmptyEntityBody(String testName) throws Exception {
204 //Should this really be empty?
208 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
211 public void createWithMalformedXml(String testName) throws Exception {
212 //Should this really be empty?
216 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
219 public void createWithWrongXmlSchema(String testName) throws Exception {
220 //Should this really be empty?
225 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
226 dependsOnMethods = {"create", "testSubmitRequest"})
227 public void createWithMalformedXml(String testName) throws Exception {
229 if (logger.isDebugEnabled()) {
230 logger.debug(testBanner(testName, CLASS_NAME));
234 setupCreateWithMalformedXml();
236 // Submit the request to the service and store the response.
237 String method = REQUEST_TYPE.httpMethodName();
238 String url = getServiceRootURL();
239 final String entity = MALFORMED_XML_DATA; // Constant from base class.
240 int statusCode = submitRequest(method, url, entity);
242 // Check the status code of the response: does it match
243 // the expected response(s)?
244 if(logger.isDebugEnabled()){
245 logger.debug(testName + ": url=" + url +
246 " status=" + statusCode);
248 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
249 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
250 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
254 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
255 dependsOnMethods = {"create", "testSubmitRequest"})
256 public void createWithWrongXmlSchema(String testName) throws Exception {
258 if (logger.isDebugEnabled()) {
259 logger.debug(testBanner(testName, CLASS_NAME));
263 setupCreateWithWrongXmlSchema();
265 // Submit the request to the service and store the response.
266 String method = REQUEST_TYPE.httpMethodName();
267 String url = getServiceRootURL();
268 final String entity = WRONG_XML_SCHEMA_DATA;
269 int statusCode = submitRequest(method, url, entity);
271 // Check the status code of the response: does it match
272 // the expected response(s)?
273 if(logger.isDebugEnabled()){
274 logger.debug(testName + ": url=" + url +
275 " status=" + statusCode);
277 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
278 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
279 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
283 // ---------------------------------------------------------------
284 // CRUD tests : READ tests
285 // ---------------------------------------------------------------
288 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
291 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
292 dependsOnMethods = {"create"})
293 public void read(String testName) throws Exception {
295 if (logger.isDebugEnabled()) {
296 logger.debug(testBanner(testName, CLASS_NAME));
302 AcquisitionClient client = new AcquisitionClient();
304 // Submit the request to the service and store the response.
305 ClientResponse<MultipartInput> res = client.read(knownResourceId);
306 int statusCode = res.getStatus();
308 // Check the status code of the response: does it match
309 // the expected response(s)?
310 if(logger.isDebugEnabled()){
311 logger.debug(testName + ": status = " + statusCode);
313 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
314 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
315 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
317 MultipartInput input = (MultipartInput) res.getEntity();
318 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
319 client.getCommonPartName(), AcquisitionsCommon.class);
320 Assert.assertNotNull(acquisitionObject);
322 // Verify the number and contents of values in repeatable fields,
323 // as created in the instance record used for testing.
324 List<String> acqSources =
325 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
326 Assert.assertTrue(acqSources.size() > 0);
327 Assert.assertNotNull(acqSources.get(0));
329 List<String> acqDates =
330 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
331 Assert.assertTrue(acqDates.size() > 0);
332 Assert.assertNotNull(acqDates.get(0));
338 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
341 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
342 dependsOnMethods = {"read"})
343 public void readNonExistent(String testName) throws Exception {
345 if (logger.isDebugEnabled()) {
346 logger.debug(testBanner(testName, CLASS_NAME));
350 setupReadNonExistent();
352 // Submit the request to the service and store the response.
353 AcquisitionClient client = new AcquisitionClient();
354 ClientResponse<MultipartInput> res = client.read(NON_EXISTENT_ID);
355 int statusCode = res.getStatus();
357 // Check the status code of the response: does it match
358 // the expected response(s)?
359 if(logger.isDebugEnabled()){
360 logger.debug(testName + ": status = " + statusCode);
362 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
363 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
364 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
367 // ---------------------------------------------------------------
368 // CRUD tests : READ_LIST tests
369 // ---------------------------------------------------------------
372 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
375 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
376 dependsOnMethods = {"createList", "read"})
377 public void readList(String testName) throws Exception {
379 if (logger.isDebugEnabled()) {
380 logger.debug(testBanner(testName, CLASS_NAME));
386 // Submit the request to the service and store the response.
387 AcquisitionClient client = new AcquisitionClient();
388 ClientResponse<AcquisitionsCommonList> res = client.readList();
389 AcquisitionsCommonList list = res.getEntity();
390 int statusCode = res.getStatus();
392 // Check the status code of the response: does it match
393 // the expected response(s)?
394 if(logger.isDebugEnabled()){
395 logger.debug(testName + ": status = " + statusCode);
397 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
398 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
399 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
401 // Optionally output additional data about list members for debugging.
402 boolean iterateThroughList = false;
403 if(iterateThroughList && logger.isDebugEnabled()){
404 List<AcquisitionsCommonList.AcquisitionListItem> items =
405 list.getAcquisitionListItem();
407 for(AcquisitionsCommonList.AcquisitionListItem item : items){
408 logger.debug(testName + ": list-item[" + i + "] csid=" +
410 logger.debug(testName + ": list-item[" + i + "] objectNumber=" +
411 item.getAcquisitionReferenceNumber());
412 logger.debug(testName + ": list-item[" + i + "] acquisitionSources:");
413 AcquisitionSourceList acqSource = item.getAcquisitionSources();
414 for (String acquisitionSource : acqSource.getAcquisitionSource()) {
415 logger.debug("acquisitionSource=" + acquisitionSource);
417 logger.debug(testName + ": list-item[" + i + "] URI=" +
428 // ---------------------------------------------------------------
429 // CRUD tests : UPDATE tests
430 // ---------------------------------------------------------------
434 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
437 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
438 dependsOnMethods = {"read"})
439 public void update(String testName) throws Exception {
441 if (logger.isDebugEnabled()) {
442 logger.debug(testBanner(testName, CLASS_NAME));
448 // Retrieve the contents of a resource to update.
449 AcquisitionClient client = new AcquisitionClient();
450 ClientResponse<MultipartInput> res = client.read(knownResourceId);
451 if(logger.isDebugEnabled()){
452 logger.debug(testName + ": read status = " + res.getStatus());
454 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
456 if(logger.isDebugEnabled()){
457 logger.debug("got object to update with ID: " + knownResourceId);
459 MultipartInput input = (MultipartInput) res.getEntity();
461 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
462 client.getCommonPartName(), AcquisitionsCommon.class);
463 Assert.assertNotNull(acquisition);
465 // Update the content of this resource.
466 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
467 if(logger.isDebugEnabled()){
468 logger.debug("updated object");
469 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
471 // Submit the request to the service and store the response.
472 MultipartOutput output = new MultipartOutput();
473 OutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
474 commonPart.getHeaders().add("label", client.getCommonPartName());
476 res = client.update(knownResourceId, output);
477 int statusCode = res.getStatus();
478 // Check the status code of the response: does it match the expected response(s)?
479 if(logger.isDebugEnabled()){
480 logger.debug(testName + ": status = " + statusCode);
482 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
483 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
484 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
487 input = (MultipartInput) res.getEntity();
488 AcquisitionsCommon updatedAcquisition =
489 (AcquisitionsCommon) extractPart(input,
490 client.getCommonPartName(), AcquisitionsCommon.class);
491 Assert.assertNotNull(updatedAcquisition);
493 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
494 acquisition.getAcquisitionReferenceNumber(),
495 "Data in updated object did not match submitted data.");
500 // Placeholders until the three tests below can be uncommented.
501 // See Issue CSPACE-401.
503 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
506 public void updateWithEmptyEntityBody(String testName) throws Exception {
507 //Should this really be empty?
511 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
514 public void updateWithMalformedXml(String testName) throws Exception {
515 //Should this really be empty?
519 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
522 public void updateWithWrongXmlSchema(String testName) throws Exception {
523 //Should this really be empty?
528 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
529 dependsOnMethods = {"create", "update", "testSubmitRequest"})
530 public void updateWithEmptyEntityBody(String testName) throws Exception {
532 if (logger.isDebugEnabled()) {
533 logger.debug(testBanner(testName, CLASS_NAME));
537 setupUpdateWithEmptyEntityBody();
539 // Submit the request to the service and store the response.
540 String method = REQUEST_TYPE.httpMethodName();
541 String url = getResourceURL(knownResourceId);
542 String mediaType = MediaType.APPLICATION_XML;
543 final String entity = "";
544 int statusCode = submitRequest(method, url, mediaType, entity);
546 // Check the status code of the response: does it match
547 // the expected response(s)?
548 if(logger.isDebugEnabled()){
549 (testName + ": url=" + url + " status=" + statusCode);
551 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
552 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
553 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
557 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
558 dependsOnMethods = {"create", "testSubmitRequest"})
559 public void createWithEmptyEntityBody(String testName) throws Exception {
561 if (logger.isDebugEnabled()) {
562 logger.debug(testBanner(testName, CLASS_NAME));
566 setupCreateWithEmptyEntityBody();
568 // Submit the request to the service and store the response.
569 String method = REQUEST_TYPE.httpMethodName();
570 String url = getServiceRootURL();
571 String mediaType = MediaType.APPLICATION_XML;
572 final String entity = "";
573 int statusCode = submitRequest(method, url, mediaType, entity);
575 // Check the status code of the response: does it match
576 // the expected response(s)?
577 if(logger.isDebugEnabled()){
578 logger.debug(testName + ": url=" + url +
579 " status=" + statusCode);
581 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
582 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
583 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
587 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
588 dependsOnMethods = {"create", "update", "testSubmitRequest"})
589 public void updateWithMalformedXml(String testName) throws Exception {
591 if (logger.isDebugEnabled()) {
592 logger.debug(testBanner(testName, CLASS_NAME));
596 setupUpdateWithMalformedXml();
598 // Submit the request to the service and store the response.
599 String method = REQUEST_TYPE.httpMethodName();
600 String url = getResourceURL(knownResourceId);
601 final String entity = MALFORMED_XML_DATA;
602 int statusCode = submitRequest(method, url, entity);
604 // Check the status code of the response: does it match
605 // the expected response(s)?
606 if(logger.isDebugEnabled()){
607 logger.debug(testName + ": url=" + url +
608 " status=" + statusCode);
610 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
611 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
612 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
616 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
617 public void updateWithWrongXmlSchema(String testName) {
619 if (logger.isDebugEnabled()) {
620 logger.debug(testBanner(testName, CLASS_NAME));
624 setupUpdateWithWrongXmlSchema();
626 // Submit the request to the service and store the response.
627 String method = REQUEST_TYPE.httpMethodName();
628 String url = getResourceURL(knownResourceId);
629 final String entity = WRONG_XML_SCHEMA_DATA;
630 int statusCode = submitRequest(method, url, entity);
632 // Check the status code of the response: does it match
633 // the expected response(s)?
634 if(logger.isDebugEnabled()){
635 logger.debug(testName + ": url=" + url +
636 " status=" + statusCode);
638 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
639 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
640 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
645 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
648 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
649 dependsOnMethods = {"update", "testSubmitRequest"})
650 public void updateNonExistent(String testName) throws Exception {
652 if (logger.isDebugEnabled()) {
653 logger.debug(testBanner(testName, CLASS_NAME));
657 setupUpdateNonExistent();
659 // Submit the request to the service and store the response.
660 // Note: The ID used in this 'create' call may be arbitrary.
661 // The only relevant ID may be the one used in update(), below.
662 AcquisitionClient client = new AcquisitionClient();
663 MultipartOutput multipart = createAcquisitionInstance(NON_EXISTENT_ID);
664 ClientResponse<MultipartInput> res =
665 client.update(NON_EXISTENT_ID, multipart);
666 int statusCode = res.getStatus();
668 // Check the status code of the response: does it match
669 // the expected response(s)?
670 if(logger.isDebugEnabled()){
671 logger.debug(testName + ": status = " + statusCode);
673 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
674 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
675 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
678 // ---------------------------------------------------------------
679 // CRUD tests : DELETE tests
680 // ---------------------------------------------------------------
683 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
686 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
687 dependsOnMethods = {"create", "read", "update"})
688 public void delete(String testName) throws Exception {
690 if (logger.isDebugEnabled()) {
691 logger.debug(testBanner(testName, CLASS_NAME));
697 // Submit the request to the service and store the response.
698 AcquisitionClient client = new AcquisitionClient();
699 ClientResponse<Response> res = client.delete(knownResourceId);
700 int statusCode = res.getStatus();
702 // Check the status code of the response: does it match
703 // the expected response(s)?
704 if(logger.isDebugEnabled()){
705 logger.debug(testName + ": status = " + statusCode);
707 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
708 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
709 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
714 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
717 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
718 dependsOnMethods = {"delete"})
719 public void deleteNonExistent(String testName) throws Exception {
721 if (logger.isDebugEnabled()) {
722 logger.debug(testBanner(testName, CLASS_NAME));
726 setupDeleteNonExistent();
728 // Submit the request to the service and store the response.
729 AcquisitionClient client = new AcquisitionClient();
730 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
731 int statusCode = res.getStatus();
733 // Check the status code of the response: does it match
734 // the expected response(s)?
735 if(logger.isDebugEnabled()){
736 logger.debug(testName + ": status = " + statusCode);
738 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
739 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
740 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
743 // ---------------------------------------------------------------
744 // Utility tests : tests of code used in tests above
745 // ---------------------------------------------------------------
747 * Tests the code for manually submitting data that is used by several
748 * of the methods above.
752 @Test(dependsOnMethods = {"create", "read"})
753 public void testSubmitRequest() throws Exception {
754 testSubmitRequest(knownResourceId);
758 * Test submit request.
760 * @param resourceId the resource id
761 * @throws Exception the exception
763 private void testSubmitRequest(String resourceId) throws Exception {
765 // Expected status code: 200 OK
766 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
768 // Submit the request to the service and store the response.
769 String method = ServiceRequestType.READ.httpMethodName();
770 String url = getResourceURL(resourceId);
771 int statusCode = submitRequest(method, url);
773 // Check the status code of the response: does it match
774 // the expected response(s)?
775 if (logger.isDebugEnabled()) {
776 logger.debug("testSubmitRequest: url=" + url
777 + " status=" + statusCode);
779 Assert.assertEquals(statusCode, EXPECTED_STATUS);
783 // ---------------------------------------------------------------
784 // Utility methods used by tests above
785 // ---------------------------------------------------------------
787 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
790 public String getServicePathComponent() {
791 return new AcquisitionClient().getServicePathComponent();
796 * Creates the acquisition instance.
798 * @param identifier the identifier
799 * @return the multipart output
801 private MultipartOutput createAcquisitionInstance(String identifier) {
802 AcquisitionsCommon acquisition = new AcquisitionsCommon();
803 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
804 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
805 List<String> acqSources = acqSourcesList.getAcquisitionSource();
806 // FIXME Use properly formatted refNames for representative acquisition
807 // sources in this example test record. The following are mere placeholders.
808 acqSources.add("Donor Acquisition Source-" + identifier);
809 acqSources.add("Museum Acquisition Source-" + identifier);
810 acquisition.setAcquisitionSources(acqSourcesList);
811 AcquisitionDateList acqDatesList = new AcquisitionDateList();
812 List<String> acqDates = acqDatesList.getAcquisitionDate();
813 // FIXME Use properly timestamps for representative acquisition
814 // dates in this example test record. The following are mere placeholders.
815 acqDates.add("First Acquisition Date -" + identifier);
816 acqDates.add("Second Acquisition Date-" + identifier);
817 acquisition.setAcquisitionDates(acqDatesList);
818 acquisition.setOwner("DummyOwner");
819 MultipartOutput multipart = new MultipartOutput();
820 OutputPart commonPart = multipart.addPart(acquisition,
821 MediaType.APPLICATION_XML_TYPE);
822 commonPart.getHeaders().add("label", new AcquisitionClient().getCommonPartName());
824 if(logger.isDebugEnabled()){
825 logger.debug("to be created, acquisition common");
826 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
831 // FIXME: The following methods might be made generic and moved to a common package.
834 * Retrives an XML document from the given file, and uses
835 * the JAXB unmarshaller to create a Java object representation
836 * and ultimately a multipart payload that can be submitted in
837 * a create or update request.
839 * @param commonPartName
840 * @param commonPartFileName
844 private MultipartOutput createAcquisitionInstanceFromXml(String testName, String commonPartName,
845 String commonPartFileName) throws Exception {
847 AcquisitionsCommon acquisition =
848 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
850 MultipartOutput multipart = new MultipartOutput();
851 OutputPart commonPart = multipart.addPart(acquisition,
852 MediaType.APPLICATION_XML_TYPE);
853 commonPart.getHeaders().add("label", commonPartName);
855 if (logger.isDebugEnabled()) {
856 logger.debug(testName + " to be created, acquisitions common");
857 logger.debug(objectAsXmlString(acquisition,
858 AcquisitionsCommon.class));
865 * Creates a record / resource from the data in an XML file.
867 * @param testName the test name
868 * @param fileName the file name
869 * @param useJaxb the use jaxb
871 * @throws Exception the exception
873 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
878 MultipartOutput multipart = null;
880 AcquisitionClient client = new AcquisitionClient();
882 multipart = createAcquisitionInstanceFromXml(testName,
883 client.getCommonPartName(), fileName);
886 multipart = createAcquisitionInstanceFromRawXml(testName,
887 client.getCommonPartName(), fileName);
889 ClientResponse<Response> res = client.create(multipart);
890 int statusCode = res.getStatus();
892 if (logger.isDebugEnabled()) {
893 logger.debug(testName + ": status = " + statusCode);
895 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
896 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
897 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
898 String newId = extractId(res);
899 allResourceIdsCreated.add(newId);
904 * Returns a multipart payload that can be submitted with a
905 * create or update request, by reading from an XML file.
907 * @param commonPartName
908 * @param commonPartFileName
912 private MultipartOutput createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
913 String commonPartFileName) throws Exception {
915 MultipartOutput multipart = new MultipartOutput();
916 String stringObject = getXmlDocumentAsString(commonPartFileName);
917 if (logger.isDebugEnabled()) {
918 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
920 OutputPart commonPart = multipart.addPart(stringObject,
921 MediaType.APPLICATION_XML_TYPE);
922 commonPart.getHeaders().add("label", commonPartName);
928 // FIXME: This duplicates code in read(), and should be consolidated.
929 // This is an expedient to support reading and verifying the contents
930 // of resources that have been created from test data XML files.
931 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
934 String testName = "readAcquisitionCommonPart";
938 // Submit the request to the service and store the response.
939 AcquisitionClient client = new AcquisitionClient();
940 ClientResponse<MultipartInput> res = client.read(csid);
941 int statusCode = res.getStatus();
943 // Check the status code of the response: does it match
944 // the expected response(s)?
945 if (logger.isDebugEnabled()) {
946 logger.debug(testName + ": status = " + statusCode);
948 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
949 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
950 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
952 MultipartInput input = (MultipartInput) res.getEntity();
954 if (logger.isDebugEnabled()) {
955 logger.debug(testName + ": Reading Common part ...");
957 AcquisitionsCommon acquisition =
958 (AcquisitionsCommon) extractPart(input,
959 client.getCommonPartName(), AcquisitionsCommon.class);
960 Assert.assertNotNull(acquisition);