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;
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
49 * AcquisitionServiceTest, carries out tests against a
50 * deployed and running Acquisition Service.
52 * $LastChangedRevision: 621 $
53 * $LastChangedDate: 2009-09-02 16:49:01 -0700 (Wed, 02 Sep 2009) $
55 public class AcquisitionServiceTest extends AbstractServiceTestImpl {
58 private final String CLASS_NAME = AcquisitionServiceTest.class.getName();
59 private final Logger logger = LoggerFactory.getLogger(CLASS_NAME);
61 // Instance variables specific to this test.
62 /** The known resource id. */
63 private String knownResourceId = null;
66 public String getServicePathComponent() {
67 return AcquisitionClient.SERVICE_PATH_COMPONENT;
72 protected String getServiceName() {
73 return AcquisitionClient.SERVICE_NAME;
77 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
80 protected CollectionSpaceClient getClientInstance() {
81 return new AcquisitionClient();
85 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
88 protected AbstractCommonList getAbstractCommonList(
89 ClientResponse<AbstractCommonList> response) {
90 return response.getEntity(AbstractCommonList.class);
93 // ---------------------------------------------------------------
94 // CRUD tests : CREATE tests
95 // ---------------------------------------------------------------
98 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
101 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class)
102 public void create(String testName) throws Exception {
104 if (logger.isDebugEnabled()) {
105 logger.debug(testBanner(testName, CLASS_NAME));
108 // Perform setup, such as initializing the type of service request
109 // (e.g. CREATE, DELETE), its valid and expected status codes, and
110 // its associated HTTP method name (e.g. POST, DELETE).
113 // Submit the request to the service and store the response.
114 String identifier = createIdentifier();
116 AcquisitionClient client = new AcquisitionClient();
117 PoxPayloadOut multipart = createAcquisitionInstance(identifier);
118 ClientResponse<Response> res = client.create(multipart);
120 int statusCode = res.getStatus();
122 // Check the status code of the response: does it match
123 // the expected response(s)?
126 // Does it fall within the set of valid status codes?
127 // Does it exactly match the expected status code?
128 if(logger.isDebugEnabled()){
129 logger.debug(testName + ": status = " + statusCode);
131 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
132 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
133 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
135 // Store the ID returned from the first resource created
136 // for additional tests below.
137 if (knownResourceId == null){
138 knownResourceId = extractId(res);
139 if (logger.isDebugEnabled()) {
140 logger.debug(testName + ": knownResourceId=" + knownResourceId);
144 // Store the IDs from every resource created by tests,
145 // so they can be deleted after tests have been run.
146 allResourceIdsCreated.add(extractId(res));
150 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
153 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
154 dependsOnMethods = {"create"})
155 public void createList(String testName) throws Exception {
156 for(int i = 0; i < 3; i++){
162 * Tests to diagnose and fix CSPACE-2578.
164 * This is a bug identified in release 1.0 alpha, after first implementing an
165 * Acquisition Funding repeatable group of fields, in which record creation
166 * fails if there is whitespace (or more generally, a text node) between
167 * the acquisitionFunding container element and its first child field.
170 // Verify that record creation occurs successfully when there is NO whitespace
171 // between the acquisitionFunding tag and its first child element tag
172 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
173 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
174 public void createFromXmlNoWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
175 if (logger.isDebugEnabled()) {
176 logger.debug(testBanner(testName, CLASS_NAME));
178 String testDataDir = System.getProperty("test-data.fileName");
180 createFromXmlFile(testName, testDataDir + "/cspace-2578-no-whitespace.xml", false);
181 testSubmitRequest(newId);
184 // Verify that record creation occurs successfully when there is whitespace
185 // between the acquisitionFunding tag and its first child element tag
187 // FIXME: This test currently fails. @Test annotation is currently commented
188 // out for check-in, to prevent service tests from failing. Can uncomment to test
189 // fixes, and also after the issue is resolved, to help detect any regressions.
191 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
192 dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2578group"})
193 public void createFromXmlWhitespaceAfterRepeatableGroupTag(String testName) throws Exception {
194 if (logger.isDebugEnabled()) {
195 logger.debug(testBanner(testName, CLASS_NAME));
197 String testDataDir = System.getProperty("test-data.fileName");
199 createFromXmlFile(testName, testDataDir + "/cspace-2578-whitespace.xml", false);
200 AcquisitionsCommon acquisition = readAcquisitionCommonPart(newId);
201 testSubmitRequest(newId);
206 // Placeholders until the three tests below can be uncommented.
207 // See Issue CSPACE-401.
209 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
212 public void createWithEmptyEntityBody(String testName) throws Exception {
213 //Should this really be empty?
217 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
220 public void createWithMalformedXml(String testName) throws Exception {
221 //Should this really be empty?
225 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
228 public void createWithWrongXmlSchema(String testName) throws Exception {
229 //Should this really be empty?
234 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
235 dependsOnMethods = {"create", "testSubmitRequest"})
236 public void createWithMalformedXml(String testName) throws Exception {
238 if (logger.isDebugEnabled()) {
239 logger.debug(testBanner(testName, CLASS_NAME));
243 setupCreateWithMalformedXml();
245 // Submit the request to the service and store the response.
246 String method = REQUEST_TYPE.httpMethodName();
247 String url = getServiceRootURL();
248 final String entity = MALFORMED_XML_DATA; // Constant from base class.
249 int statusCode = submitRequest(method, url, entity);
251 // Check the status code of the response: does it match
252 // the expected response(s)?
253 if(logger.isDebugEnabled()){
254 logger.debug(testName + ": url=" + url +
255 " status=" + statusCode);
257 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
258 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
259 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
263 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
264 dependsOnMethods = {"create", "testSubmitRequest"})
265 public void createWithWrongXmlSchema(String testName) throws Exception {
267 if (logger.isDebugEnabled()) {
268 logger.debug(testBanner(testName, CLASS_NAME));
272 setupCreateWithWrongXmlSchema();
274 // Submit the request to the service and store the response.
275 String method = REQUEST_TYPE.httpMethodName();
276 String url = getServiceRootURL();
277 final String entity = WRONG_XML_SCHEMA_DATA;
278 int statusCode = submitRequest(method, url, entity);
280 // Check the status code of the response: does it match
281 // the expected response(s)?
282 if(logger.isDebugEnabled()){
283 logger.debug(testName + ": url=" + url +
284 " status=" + statusCode);
286 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
287 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
288 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
292 // ---------------------------------------------------------------
293 // CRUD tests : READ tests
294 // ---------------------------------------------------------------
297 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
300 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
301 dependsOnMethods = {"create"})
302 public void read(String testName) throws Exception {
304 if (logger.isDebugEnabled()) {
305 logger.debug(testBanner(testName, CLASS_NAME));
311 AcquisitionClient client = new AcquisitionClient();
313 // Submit the request to the service and store the response.
314 ClientResponse<String> res = client.read(knownResourceId);
315 int statusCode = res.getStatus();
317 // Check the status code of the response: does it match
318 // the expected response(s)?
319 if(logger.isDebugEnabled()){
320 logger.debug(testName + ": status = " + statusCode);
322 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
323 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
324 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
326 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
327 AcquisitionsCommon acquisitionObject = (AcquisitionsCommon) extractPart(input,
328 client.getCommonPartName(), AcquisitionsCommon.class);
329 Assert.assertNotNull(acquisitionObject);
331 // Verify the number and contents of values in repeatable fields,
332 // as created in the instance record used for testing.
333 List<String> acqSources =
334 acquisitionObject.getAcquisitionSources().getAcquisitionSource();
335 Assert.assertTrue(acqSources.size() > 0);
336 Assert.assertNotNull(acqSources.get(0));
338 List<String> acqDates =
339 acquisitionObject.getAcquisitionDates().getAcquisitionDate();
340 Assert.assertTrue(acqDates.size() > 0);
341 Assert.assertNotNull(acqDates.get(0));
343 List<String> owners =
344 acquisitionObject.getOwners().getOwner();
345 Assert.assertTrue(owners.size() > 0);
346 Assert.assertNotNull(owners.get(0));
351 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
354 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
355 dependsOnMethods = {"read"})
356 public void readNonExistent(String testName) throws Exception {
358 if (logger.isDebugEnabled()) {
359 logger.debug(testBanner(testName, CLASS_NAME));
363 setupReadNonExistent();
365 // Submit the request to the service and store the response.
366 AcquisitionClient client = new AcquisitionClient();
367 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
368 int statusCode = res.getStatus();
370 // Check the status code of the response: does it match
371 // the expected response(s)?
372 if(logger.isDebugEnabled()){
373 logger.debug(testName + ": status = " + statusCode);
375 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
376 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
377 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
380 // ---------------------------------------------------------------
381 // CRUD tests : READ_LIST tests
382 // ---------------------------------------------------------------
385 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
388 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
389 dependsOnMethods = {"createList", "read"})
390 public void readList(String testName) throws Exception {
392 if (logger.isDebugEnabled()) {
393 logger.debug(testBanner(testName, CLASS_NAME));
399 // Submit the request to the service and store the response.
400 AcquisitionClient client = new AcquisitionClient();
401 ClientResponse<AbstractCommonList> res = client.readList();
402 AbstractCommonList list = res.getEntity();
403 int statusCode = res.getStatus();
405 // Check the status code of the response: does it match
406 // the expected response(s)?
407 if(logger.isDebugEnabled()){
408 logger.debug(testName + ": status = " + statusCode);
410 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
411 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
412 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
414 // Optionally output additional data about list members for debugging.
415 boolean iterateThroughList = true;
416 if(iterateThroughList && logger.isDebugEnabled()){
417 ListItemsInAbstractCommonList(list, logger, testName);
425 // ---------------------------------------------------------------
426 // CRUD tests : UPDATE tests
427 // ---------------------------------------------------------------
431 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
434 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
435 dependsOnMethods = {"read"})
436 public void update(String testName) throws Exception {
438 if (logger.isDebugEnabled()) {
439 logger.debug(testBanner(testName, CLASS_NAME));
445 // Retrieve the contents of a resource to update.
446 AcquisitionClient client = new AcquisitionClient();
447 ClientResponse<String> res = client.read(knownResourceId);
448 if(logger.isDebugEnabled()){
449 logger.debug(testName + ": read status = " + res.getStatus());
451 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
453 if(logger.isDebugEnabled()){
454 logger.debug("got object to update with ID: " + knownResourceId);
456 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
458 AcquisitionsCommon acquisition = (AcquisitionsCommon) extractPart(input,
459 client.getCommonPartName(), AcquisitionsCommon.class);
460 Assert.assertNotNull(acquisition);
462 // Update the content of this resource.
463 acquisition.setAcquisitionReferenceNumber("updated-" + acquisition.getAcquisitionReferenceNumber());
464 if(logger.isDebugEnabled()){
465 logger.debug("updated object");
466 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
468 // Submit the request to the service and store the response.
469 PoxPayloadOut output = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
470 PayloadOutputPart commonPart = output.addPart(acquisition, MediaType.APPLICATION_XML_TYPE);
471 commonPart.setLabel(client.getCommonPartName());
473 res = client.update(knownResourceId, output);
474 int statusCode = res.getStatus();
475 // Check the status code of the response: does it match the expected response(s)?
476 if(logger.isDebugEnabled()){
477 logger.debug(testName + ": status = " + statusCode);
479 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
480 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
481 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
484 input = new PoxPayloadIn(res.getEntity());
485 AcquisitionsCommon updatedAcquisition =
486 (AcquisitionsCommon) extractPart(input,
487 client.getCommonPartName(), AcquisitionsCommon.class);
488 Assert.assertNotNull(updatedAcquisition);
490 Assert.assertEquals(updatedAcquisition.getAcquisitionReferenceNumber(),
491 acquisition.getAcquisitionReferenceNumber(),
492 "Data in updated object did not match submitted data.");
497 // Placeholders until the three tests below can be uncommented.
498 // See Issue CSPACE-401.
500 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
503 public void updateWithEmptyEntityBody(String testName) throws Exception {
504 //Should this really be empty?
508 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
511 public void updateWithMalformedXml(String testName) throws Exception {
512 //Should this really be empty?
516 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
519 public void updateWithWrongXmlSchema(String testName) throws Exception {
520 //Should this really be empty?
525 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
526 dependsOnMethods = {"create", "update", "testSubmitRequest"})
527 public void updateWithEmptyEntityBody(String testName) throws Exception {
529 if (logger.isDebugEnabled()) {
530 logger.debug(testBanner(testName, CLASS_NAME));
534 setupUpdateWithEmptyEntityBody();
536 // Submit the request to the service and store the response.
537 String method = REQUEST_TYPE.httpMethodName();
538 String url = getResourceURL(knownResourceId);
539 String mediaType = MediaType.APPLICATION_XML;
540 final String entity = "";
541 int statusCode = submitRequest(method, url, mediaType, entity);
543 // Check the status code of the response: does it match
544 // the expected response(s)?
545 if(logger.isDebugEnabled()){
546 (testName + ": url=" + url + " status=" + statusCode);
548 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
549 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
550 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
554 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
555 dependsOnMethods = {"create", "testSubmitRequest"})
556 public void createWithEmptyEntityBody(String testName) throws Exception {
558 if (logger.isDebugEnabled()) {
559 logger.debug(testBanner(testName, CLASS_NAME));
563 setupCreateWithEmptyEntityBody();
565 // Submit the request to the service and store the response.
566 String method = REQUEST_TYPE.httpMethodName();
567 String url = getServiceRootURL();
568 String mediaType = MediaType.APPLICATION_XML;
569 final String entity = "";
570 int statusCode = submitRequest(method, url, mediaType, entity);
572 // Check the status code of the response: does it match
573 // the expected response(s)?
574 if(logger.isDebugEnabled()){
575 logger.debug(testName + ": url=" + url +
576 " status=" + statusCode);
578 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
579 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
580 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
584 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class,
585 dependsOnMethods = {"create", "update", "testSubmitRequest"})
586 public void updateWithMalformedXml(String testName) throws Exception {
588 if (logger.isDebugEnabled()) {
589 logger.debug(testBanner(testName, CLASS_NAME));
593 setupUpdateWithMalformedXml();
595 // Submit the request to the service and store the response.
596 String method = REQUEST_TYPE.httpMethodName();
597 String url = getResourceURL(knownResourceId);
598 final String entity = MALFORMED_XML_DATA;
599 int statusCode = submitRequest(method, url, entity);
601 // Check the status code of the response: does it match
602 // the expected response(s)?
603 if(logger.isDebugEnabled()){
604 logger.debug(testName + ": url=" + url +
605 " status=" + statusCode);
607 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
608 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
609 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
613 @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"})
614 public void updateWithWrongXmlSchema(String testName) {
616 if (logger.isDebugEnabled()) {
617 logger.debug(testBanner(testName, CLASS_NAME));
621 setupUpdateWithWrongXmlSchema();
623 // Submit the request to the service and store the response.
624 String method = REQUEST_TYPE.httpMethodName();
625 String url = getResourceURL(knownResourceId);
626 final String entity = WRONG_XML_SCHEMA_DATA;
627 int statusCode = submitRequest(method, url, entity);
629 // Check the status code of the response: does it match
630 // the expected response(s)?
631 if(logger.isDebugEnabled()){
632 logger.debug(testName + ": url=" + url +
633 " status=" + statusCode);
635 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
636 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
637 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
642 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
645 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
646 dependsOnMethods = {"update", "testSubmitRequest"})
647 public void updateNonExistent(String testName) throws Exception {
649 if (logger.isDebugEnabled()) {
650 logger.debug(testBanner(testName, CLASS_NAME));
654 setupUpdateNonExistent();
656 // Submit the request to the service and store the response.
657 // Note: The ID used in this 'create' call may be arbitrary.
658 // The only relevant ID may be the one used in update(), below.
659 AcquisitionClient client = new AcquisitionClient();
660 PoxPayloadOut multipart = createAcquisitionInstance(NON_EXISTENT_ID);
661 ClientResponse<String> res =
662 client.update(NON_EXISTENT_ID, multipart);
663 int statusCode = res.getStatus();
665 // Check the status code of the response: does it match
666 // the expected response(s)?
667 if(logger.isDebugEnabled()){
668 logger.debug(testName + ": status = " + statusCode);
670 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
671 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
672 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
675 // ---------------------------------------------------------------
676 // CRUD tests : DELETE tests
677 // ---------------------------------------------------------------
680 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
683 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
684 dependsOnMethods = {"create", "read", "update"})
685 public void delete(String testName) throws Exception {
687 if (logger.isDebugEnabled()) {
688 logger.debug(testBanner(testName, CLASS_NAME));
694 // Submit the request to the service and store the response.
695 AcquisitionClient client = new AcquisitionClient();
696 ClientResponse<Response> res = client.delete(knownResourceId);
697 int statusCode = res.getStatus();
699 // Check the status code of the response: does it match
700 // the expected response(s)?
701 if(logger.isDebugEnabled()){
702 logger.debug(testName + ": status = " + statusCode);
704 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
705 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
706 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
711 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
714 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
715 dependsOnMethods = {"delete"})
716 public void deleteNonExistent(String testName) throws Exception {
718 if (logger.isDebugEnabled()) {
719 logger.debug(testBanner(testName, CLASS_NAME));
723 setupDeleteNonExistent();
725 // Submit the request to the service and store the response.
726 AcquisitionClient client = new AcquisitionClient();
727 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
728 int statusCode = res.getStatus();
730 // Check the status code of the response: does it match
731 // the expected response(s)?
732 if(logger.isDebugEnabled()){
733 logger.debug(testName + ": status = " + statusCode);
735 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
736 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
737 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
740 // ---------------------------------------------------------------
741 // Utility tests : tests of code used in tests above
742 // ---------------------------------------------------------------
744 * Tests the code for manually submitting data that is used by several
745 * of the methods above.
749 @Test(dependsOnMethods = {"create", "read"})
750 public void testSubmitRequest() throws Exception {
751 testSubmitRequest(knownResourceId);
755 * Test submit request.
757 * @param resourceId the resource id
758 * @throws Exception the exception
760 private void testSubmitRequest(String resourceId) throws Exception {
762 // Expected status code: 200 OK
763 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
765 // Submit the request to the service and store the response.
766 String method = ServiceRequestType.READ.httpMethodName();
767 String url = getResourceURL(resourceId);
768 int statusCode = submitRequest(method, url);
770 // Check the status code of the response: does it match
771 // the expected response(s)?
772 if (logger.isDebugEnabled()) {
773 logger.debug("testSubmitRequest: url=" + url
774 + " status=" + statusCode);
776 Assert.assertEquals(statusCode, EXPECTED_STATUS);
780 // ---------------------------------------------------------------
781 // Utility methods used by tests above
782 // ---------------------------------------------------------------
785 protected PoxPayloadOut createInstance(String identifier) {
786 return createAcquisitionInstance(identifier);
790 * Creates the acquisition instance.
792 * @param identifier the identifier
793 * @return the multipart output
795 private PoxPayloadOut createAcquisitionInstance(String identifier) {
796 AcquisitionsCommon acquisition = new AcquisitionsCommon();
797 acquisition.setAcquisitionReferenceNumber("acquisitionReferenceNumber-" + identifier);
799 AcquisitionSourceList acqSourcesList = new AcquisitionSourceList();
800 List<String> acqSources = acqSourcesList.getAcquisitionSource();
801 // FIXME Use properly formatted refNames for representative acquisition
802 // sources in this example test record. The following are mere placeholders.
803 acqSources.add("Donor Acquisition Source-" + identifier);
804 acqSources.add("Museum Acquisition Source-" + identifier);
805 acquisition.setAcquisitionSources(acqSourcesList);
807 AcquisitionDateList acqDatesList = new AcquisitionDateList();
808 List<String> acqDates = acqDatesList.getAcquisitionDate();
809 // FIXME Use properly timestamps for representative acquisition
810 // dates in this example test record. The following are mere placeholders.
811 acqDates.add("First Acquisition Date -" + identifier);
812 acqDates.add("Second Acquisition Date-" + identifier);
813 acquisition.setAcquisitionDates(acqDatesList);
815 OwnerList ownersList = new OwnerList();
816 List<String> owners = ownersList.getOwner();
817 // FIXME Use properly formatted refNames for representative owners
818 // in this example test record. The following are mere placeholders.
819 owners.add("First Owner -" + identifier);
820 owners.add("Second Owner-" + identifier);
821 acquisition.setOwners(ownersList);
823 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
824 PayloadOutputPart commonPart = multipart.addPart(acquisition,
825 MediaType.APPLICATION_XML_TYPE);
826 commonPart.setLabel(new AcquisitionClient().getCommonPartName());
828 if(logger.isDebugEnabled()){
829 logger.debug("to be created, acquisition common");
830 logger.debug(objectAsXmlString(acquisition, AcquisitionsCommon.class));
835 // FIXME: The following methods might be made generic and moved to a common package.
838 * Retrives an XML document from the given file, and uses
839 * the JAXB unmarshaller to create a Java object representation
840 * and ultimately a multipart payload that can be submitted in
841 * a create or update request.
843 * @param commonPartName
844 * @param commonPartFileName
848 private PoxPayloadOut createAcquisitionInstanceFromXml(String testName, String commonPartName,
849 String commonPartFileName) throws Exception {
851 AcquisitionsCommon acquisition =
852 (AcquisitionsCommon) getObjectFromFile(AcquisitionsCommon.class,
854 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
855 PayloadOutputPart commonPart = multipart.addPart(acquisition,
856 MediaType.APPLICATION_XML_TYPE);
857 commonPart.setLabel(commonPartName);
859 if (logger.isDebugEnabled()) {
860 logger.debug(testName + " to be created, acquisitions common");
861 logger.debug(objectAsXmlString(acquisition,
862 AcquisitionsCommon.class));
869 * Creates a record / resource from the data in an XML file.
871 * @param testName the test name
872 * @param fileName the file name
873 * @param useJaxb the use jaxb
875 * @throws Exception the exception
877 private String createFromXmlFile(String testName, String fileName, boolean useJaxb) throws Exception {
882 PoxPayloadOut multipart = null;
884 AcquisitionClient client = new AcquisitionClient();
886 multipart = createAcquisitionInstanceFromXml(testName,
887 client.getCommonPartName(), fileName);
890 multipart = createAcquisitionInstanceFromRawXml(testName,
891 client.getCommonPartName(), fileName);
893 ClientResponse<Response> res = client.create(multipart);
894 int statusCode = res.getStatus();
896 if (logger.isDebugEnabled()) {
897 logger.debug(testName + ": status = " + statusCode);
899 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
900 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
901 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
902 String newId = extractId(res);
903 allResourceIdsCreated.add(newId);
908 * Returns a multipart payload that can be submitted with a
909 * create or update request, by reading from an XML file.
911 * @param commonPartName
912 * @param commonPartFileName
916 private PoxPayloadOut createAcquisitionInstanceFromRawXml(String testName, String commonPartName,
917 String commonPartFileName) throws Exception {
919 PoxPayloadOut multipart = new PoxPayloadOut(AcquisitionClient.SERVICE_PAYLOAD_NAME);
920 String stringObject = getXmlDocumentAsString(commonPartFileName);
921 if (logger.isDebugEnabled()) {
922 logger.debug(testName + " to be created, acquisition common " + "\n" + stringObject);
924 PayloadOutputPart commonPart = multipart.addPart(stringObject, stringObject);
925 commonPart.setLabel(commonPartName);
931 // FIXME: This duplicates code in read(), and should be consolidated.
932 // This is an expedient to support reading and verifying the contents
933 // of resources that have been created from test data XML files.
934 private AcquisitionsCommon readAcquisitionCommonPart(String csid)
937 String testName = "readAcquisitionCommonPart";
941 // Submit the request to the service and store the response.
942 AcquisitionClient client = new AcquisitionClient();
943 ClientResponse<String> res = client.read(csid);
944 int statusCode = res.getStatus();
946 // Check the status code of the response: does it match
947 // the expected response(s)?
948 if (logger.isDebugEnabled()) {
949 logger.debug(testName + ": status = " + statusCode);
951 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
952 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
953 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
955 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
957 if (logger.isDebugEnabled()) {
958 logger.debug(testName + ": Reading Common part ...");
960 AcquisitionsCommon acquisition =
961 (AcquisitionsCommon) extractPart(input,
962 client.getCommonPartName(), AcquisitionsCommon.class);
963 Assert.assertNotNull(acquisition);