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.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
30 import org.collectionspace.services.LocationJAXBSchema;
31 import org.collectionspace.services.client.CollectionSpaceClient;
32 import org.collectionspace.services.client.ContactClient;
33 import org.collectionspace.services.client.ContactClientUtils;
34 import org.collectionspace.services.client.PayloadOutputPart;
35 import org.collectionspace.services.client.PoxPayloadIn;
36 import org.collectionspace.services.client.PoxPayloadOut;
37 import org.collectionspace.services.contact.ContactsCommon;
38 import org.collectionspace.services.contact.ContactsCommonList;
39 import org.collectionspace.services.client.LocationAuthorityClient;
40 import org.collectionspace.services.client.LocationAuthorityClientUtils;
41 import org.collectionspace.services.jaxb.AbstractCommonList;
42 import org.collectionspace.services.location.LocationauthoritiesCommon;
43 import org.collectionspace.services.location.LocationauthoritiesCommonList;
44 import org.collectionspace.services.location.LocationsCommon;
45 import org.collectionspace.services.location.LocationsCommonList;
47 import javax.ws.rs.core.MediaType;
48 import javax.ws.rs.core.Response;
49 import org.jboss.resteasy.client.ClientResponse;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
54 import org.testng.Assert;
55 import org.testng.annotations.AfterClass;
56 import org.testng.annotations.Test;
59 * LocationAuthorityServiceTest, carries out tests against a
60 * deployed and running LocationAuthority Service.
62 * $LastChangedRevision: 753 $
63 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
65 public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
68 private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName();
69 private final Logger logger = LoggerFactory.getLogger(LocationAuthorityServiceTest.class);
72 public String getServicePathComponent() {
73 return LocationAuthorityClient.SERVICE_PATH_COMPONENT;
77 protected String getServiceName() {
78 return LocationAuthorityClient.SERVICE_NAME;
81 public String getItemServicePathComponent() {
82 return LocationAuthorityClient.SERVICE_PATH_ITEMS_COMPONENT;
85 // Instance variables specific to this test.
87 // /** The SERVICE path component. */
88 // final String SERVICE_PATH_COMPONENT = "locationauthorities";
90 // /** The ITEM service path component. */
91 // final String ITEM_SERVICE_PATH_COMPONENT = "items";
93 // /** The CONTACT service path component. */
94 // final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
96 final String TEST_NAME = "Shelf 1";
97 final String TEST_SHORTID = "shelf1";
98 final String TEST_CONDITION_NOTE = "Basically clean";
99 final String TEST_CONDITION_NOTE_DATE = "June 11, 1979";
100 final String TEST_SECURITY_NOTE = "Kind of safe";
101 final String TEST_ACCESS_NOTE = "Only right-thinkers may see";
102 final String TEST_ADDRESS = "123 Main Street, Anytown USA";
103 // TODO Make loc type be a controlled vocab term.
104 final String TEST_LOCATION_TYPE = "Shelf";
105 // TODO Make status type be a controlled vocab term.
106 final String TEST_STATUS = "Approved";
108 /** The known resource id. */
109 private String knownResourceId = null;
110 private String knownResourceShortIdentifer = null;
111 private String knownResourceRefName = null;
112 private String knownLocationTypeRefName = null;
113 private String knownItemResourceId = null;
114 private String knownItemResourceShortIdentifer = null;
115 private String knownContactResourceId = null;
117 /** The n items to create in list. */
118 private int nItemsToCreateInList = 3;
120 /** The all resource ids created. */
121 private List<String> allResourceIdsCreated = new ArrayList<String>();
123 /** The all item resource ids created. */
124 private Map<String, String> allItemResourceIdsCreated =
125 new HashMap<String, String>();
127 protected void setKnownResource( String id, String shortIdentifer,
129 knownResourceId = id;
130 knownResourceShortIdentifer = shortIdentifer;
131 knownResourceRefName = refName;
134 protected void setKnownItemResource( String id, String shortIdentifer ) {
135 knownItemResourceId = id;
136 knownItemResourceShortIdentifer = shortIdentifer;
140 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
143 protected CollectionSpaceClient getClientInstance() {
144 return new LocationAuthorityClient();
148 * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse)
151 protected AbstractCommonList getAbstractCommonList(
152 ClientResponse<AbstractCommonList> response) {
153 return response.getEntity(LocationsCommonList.class);
156 // ---------------------------------------------------------------
157 // CRUD tests : CREATE tests
158 // ---------------------------------------------------------------
161 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
164 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
166 public void create(String testName) throws Exception {
168 if (logger.isDebugEnabled()) {
169 logger.debug(testBanner(testName, CLASS_NAME));
171 // Perform setup, such as initializing the type of service request
172 // (e.g. CREATE, DELETE), its valid and expected status codes, and
173 // its associated HTTP method name (e.g. POST, DELETE).
176 // Submit the request to the service and store the response.
177 LocationAuthorityClient client = new LocationAuthorityClient();
178 String shortId = createIdentifier();
179 String displayName = "displayName-" + shortId;
180 String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
181 PoxPayloadOut multipart =
182 LocationAuthorityClientUtils.createLocationAuthorityInstance(
183 displayName, shortId, client.getCommonPartName());
185 ClientResponse<Response> res = client.create(multipart);
187 int statusCode = res.getStatus();
189 // Check the status code of the response: does it match
190 // the expected response(s)?
193 // Does it fall within the set of valid status codes?
194 // Does it exactly match the expected status code?
195 if(logger.isDebugEnabled()){
196 logger.debug(testName + ": status = " + statusCode);
198 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
199 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
200 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
202 newID = LocationAuthorityClientUtils.extractId(res);
204 res.releaseConnection();
206 // Store the ID returned from the first resource created
207 // for additional tests below.
208 if (knownResourceId == null){
209 setKnownResource( newID, shortId, baseRefName );
210 if (logger.isDebugEnabled()) {
211 logger.debug(testName + ": knownResourceId=" + knownResourceId);
214 // Store the IDs from every resource created by tests,
215 // so they can be deleted after tests have been run.
216 allResourceIdsCreated.add(newID);
222 * @param testName the test name
224 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
225 groups = {"create"}, dependsOnMethods = {"create"})
226 public void createItem(String testName) {
227 if(logger.isDebugEnabled()){
228 logger.debug(testBanner(testName, CLASS_NAME));
231 createItemInAuthority(knownResourceId, knownResourceRefName);
235 * Creates the item in authority.
237 * @param vcsid the vcsid
238 * @param authRefName the auth ref name
241 private String createItemInAuthority(String vcsid, String authRefName) {
243 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
244 if(logger.isDebugEnabled()){
245 logger.debug(testBanner(testName, CLASS_NAME));
248 // Submit the request to the service and store the response.
249 LocationAuthorityClient client = new LocationAuthorityClient();
250 Map<String, String> shelf1Map = new HashMap<String,String>();
251 // TODO Make loc type and status be controlled vocabs.
252 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
253 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
254 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
255 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
256 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
257 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
258 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
259 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
260 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
262 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
263 authRefName, shelf1Map, client );
265 // Store the ID returned from the first item resource created
266 // for additional tests below.
267 if (knownItemResourceId == null){
268 setKnownItemResource(newID, TEST_SHORTID);
269 if (logger.isDebugEnabled()) {
270 logger.debug(testName + ": knownItemResourceId=" + newID);
274 // Store the IDs from any item resources created
275 // by tests, along with the IDs of their parents, so these items
276 // can be deleted after all tests have been run.
277 allItemResourceIdsCreated.put(newID, vcsid);
286 // Placeholders until the three tests below can be uncommented.
287 // See Issue CSPACE-401.
289 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
292 public void createWithEmptyEntityBody(String testName) throws Exception {
296 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
299 public void createWithMalformedXml(String testName) throws Exception {
303 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
306 public void createWithWrongXmlSchema(String testName) throws Exception {
310 // ---------------------------------------------------------------
311 // CRUD tests : CREATE LIST tests
312 // ---------------------------------------------------------------
315 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
318 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
319 groups = {"createList"}, dependsOnGroups = {"create"})
320 public void createList(String testName) throws Exception {
321 for (int i = 0; i < nItemsToCreateInList; i++) {
327 * Creates the item list.
329 * @param testName the test name
330 * @throws Exception the exception
332 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
333 groups = {"createList"}, dependsOnMethods = {"createList"})
334 public void createItemList(String testName) throws Exception {
335 // Add items to the initially-created, known parent record.
336 for (int j = 0; j < nItemsToCreateInList; j++) {
337 createItem(testName);
341 // ---------------------------------------------------------------
342 // CRUD tests : READ tests
343 // ---------------------------------------------------------------
346 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
349 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
350 groups = {"read"}, dependsOnGroups = {"create"})
351 public void read(String testName) throws Exception {
353 if (logger.isDebugEnabled()) {
354 logger.debug(testBanner(testName, CLASS_NAME));
359 // Submit the request to the service and store the response.
360 LocationAuthorityClient client = new LocationAuthorityClient();
362 ClientResponse<String> res = client.read(knownResourceId);
364 int statusCode = res.getStatus();
366 // Check the status code of the response: does it match
367 // the expected response(s)?
368 if(logger.isDebugEnabled()){
369 logger.debug(testName + ": status = " + statusCode);
371 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
372 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
373 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
374 //FIXME: remove the following try catch once Aron fixes signatures
376 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
377 LocationauthoritiesCommon locationAuthority =
378 (LocationauthoritiesCommon) extractPart(input,
379 client.getCommonPartName(), LocationauthoritiesCommon.class);
380 Assert.assertNotNull(locationAuthority);
381 } catch (Exception e) {
382 throw new RuntimeException(e);
385 res.releaseConnection();
392 * @param testName the test name
393 * @throws Exception the exception
395 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
396 groups = {"read"}, dependsOnGroups = {"create"})
397 public void readByName(String testName) throws Exception {
399 if (logger.isDebugEnabled()) {
400 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
405 // Submit the request to the service and store the response.
406 LocationAuthorityClient client = new LocationAuthorityClient();
407 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
409 int statusCode = res.getStatus();
411 // Check the status code of the response: does it match
412 // the expected response(s)?
413 if(logger.isDebugEnabled()){
414 logger.debug(testName + ": status = " + statusCode);
416 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
417 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
418 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
419 //FIXME: remove the following try catch once Aron fixes signatures
421 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
422 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
423 client.getCommonPartName(), LocationauthoritiesCommon.class);
424 Assert.assertNotNull(locationAuthority);
425 } catch (Exception e) {
426 throw new RuntimeException(e);
429 res.releaseConnection();
437 * @param testName the test name
438 * @throws Exception the exception
440 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
441 groups = {"read"}, dependsOnMethods = {"read"})
442 public void readItem(String testName) throws Exception {
444 if (logger.isDebugEnabled()) {
445 logger.debug(testBanner(testName, CLASS_NAME));
450 // Submit the request to the service and store the response.
451 LocationAuthorityClient client = new LocationAuthorityClient();
452 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
454 int statusCode = res.getStatus();
456 // Check the status code of the response: does it match
457 // the expected response(s)?
458 if(logger.isDebugEnabled()){
459 logger.debug(testName + ": status = " + statusCode);
461 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
462 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
463 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
465 // Check whether we've received a location.
466 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
467 LocationsCommon location = (LocationsCommon) extractPart(input,
468 client.getItemCommonPartName(), LocationsCommon.class);
469 Assert.assertNotNull(location);
470 boolean showFull = true;
471 if(showFull && logger.isDebugEnabled()){
472 logger.debug(testName + ": returned payload:");
473 logger.debug(objectAsXmlString(location, LocationsCommon.class));
475 Assert.assertEquals(location.getInAuthority(), knownResourceId);
477 res.releaseConnection();
483 * Verify item display name.
485 * @param testName the test name
486 * @throws Exception the exception
488 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
489 dependsOnMethods = {"readItem", "updateItem"})
490 public void verifyItemDisplayName(String testName) throws Exception {
492 if (logger.isDebugEnabled()) {
493 logger.debug(testBanner(testName, CLASS_NAME));
498 // Submit the request to the service and store the response.
499 LocationAuthorityClient client = new LocationAuthorityClient();
500 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
502 int statusCode = res.getStatus();
504 // Check the status code of the response: does it match
505 // the expected response(s)?
506 if(logger.isDebugEnabled()){
507 logger.debug(testName + ": status = " + statusCode);
509 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
510 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
511 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
513 // Check whether location has expected displayName.
514 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
515 LocationsCommon location = (LocationsCommon) extractPart(input,
516 client.getItemCommonPartName(), LocationsCommon.class);
517 Assert.assertNotNull(location);
518 String displayName = location.getDisplayName();
519 // Make sure displayName matches computed form
520 String expectedDisplayName =
521 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
522 Assert.assertNotNull(displayName, expectedDisplayName);
524 // Update the shortName and verify the computed name is updated.
525 location.setCsid(null);
526 location.setDisplayNameComputed(true);
527 location.setName("updated-" + TEST_NAME);
528 expectedDisplayName =
529 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
531 // Submit the updated resource to the service and store the response.
532 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
533 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
534 commonPart.setLabel(client.getItemCommonPartName());
535 res.releaseConnection();
536 res = client.updateItem(knownResourceId, knownItemResourceId, output);
537 statusCode = res.getStatus();
539 // Check the status code of the response: does it match the expected response(s)?
540 if(logger.isDebugEnabled()){
541 logger.debug("updateItem: status = " + statusCode);
543 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
544 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
545 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
547 // Retrieve the updated resource and verify that its contents exist.
548 input = new PoxPayloadIn(res.getEntity());
549 LocationsCommon updatedLocation =
550 (LocationsCommon) extractPart(input,
551 client.getItemCommonPartName(), LocationsCommon.class);
552 Assert.assertNotNull(updatedLocation);
554 // Verify that the updated resource received the correct data.
555 Assert.assertEquals(updatedLocation.getName(), location.getName(),
556 "Updated ForeName in Location did not match submitted data.");
557 // Verify that the updated resource computes the right displayName.
558 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
559 "Updated ForeName in Location not reflected in computed DisplayName.");
561 // Now Update the displayName, not computed and verify the computed name is overriden.
562 location.setDisplayNameComputed(false);
563 expectedDisplayName = "TestName";
564 location.setDisplayName(expectedDisplayName);
566 // Submit the updated resource to the service and store the response.
567 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
568 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
569 commonPart.setLabel(client.getItemCommonPartName());
570 res.releaseConnection();
571 res = client.updateItem(knownResourceId, knownItemResourceId, output);
572 statusCode = res.getStatus();
574 // Check the status code of the response: does it match the expected response(s)?
575 if(logger.isDebugEnabled()){
576 logger.debug("updateItem: status = " + statusCode);
578 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
579 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
580 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
582 // Retrieve the updated resource and verify that its contents exist.
583 input = new PoxPayloadIn(res.getEntity());
585 (LocationsCommon) extractPart(input,
586 client.getItemCommonPartName(), LocationsCommon.class);
587 Assert.assertNotNull(updatedLocation);
589 // Verify that the updated resource received the correct data.
590 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
591 "Updated displayNameComputed in Location did not match submitted data.");
592 // Verify that the updated resource computes the right displayName.
593 Assert.assertEquals(updatedLocation.getDisplayName(),
595 "Updated DisplayName (not computed) in Location not stored.");
597 res.releaseConnection();
602 * Verify illegal item display name.
604 * @param testName the test name
605 * @throws Exception the exception
607 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
608 dependsOnMethods = {"verifyItemDisplayName"})
609 public void verifyIllegalItemDisplayName(String testName) throws Exception {
611 if (logger.isDebugEnabled()) {
612 logger.debug(testBanner(testName, CLASS_NAME));
615 // FIXME: create a setup configuration for this operation.
616 setupUpdateWithWrongXmlSchema();
618 // Submit the request to the service and store the response.
619 LocationAuthorityClient client = new LocationAuthorityClient();
620 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
622 int statusCode = res.getStatus();
624 // Check the status code of the response: does it match
625 // the expected response(s)?
626 if(logger.isDebugEnabled()){
627 logger.debug(testName + ": status = " + statusCode);
629 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
630 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
631 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
633 // Check whether Location has expected displayName.
634 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
635 LocationsCommon location = (LocationsCommon) extractPart(input,
636 client.getItemCommonPartName(), LocationsCommon.class);
637 Assert.assertNotNull(location);
638 // Try to Update with computed false and no displayName
639 location.setDisplayNameComputed(false);
640 location.setDisplayName(null);
642 // Submit the updated resource to the service and store the response.
643 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
644 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
645 commonPart.setLabel(client.getItemCommonPartName());
646 res.releaseConnection();
647 res = client.updateItem(knownResourceId, knownItemResourceId, output);
648 statusCode = res.getStatus();
650 // Check the status code of the response: does it match the expected response(s)?
651 if(logger.isDebugEnabled()){
652 logger.debug("updateItem: status = " + statusCode);
654 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
655 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
656 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
658 res.releaseConnection();
665 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
668 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
669 groups = {"read"}, dependsOnMethods = {"read"})
670 public void readNonExistent(String testName) {
672 if (logger.isDebugEnabled()) {
673 logger.debug(testBanner(testName, CLASS_NAME));
676 setupReadNonExistent();
678 // Submit the request to the service and store the response.
679 LocationAuthorityClient client = new LocationAuthorityClient();
680 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
682 int statusCode = res.getStatus();
684 // Check the status code of the response: does it match
685 // the expected response(s)?
686 if(logger.isDebugEnabled()){
687 logger.debug(testName + ": status = " + statusCode);
689 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
690 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
691 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
693 res.releaseConnection();
698 * Read item non existent.
700 * @param testName the test name
702 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
703 groups = {"read"}, dependsOnMethods = {"readItem"})
704 public void readItemNonExistent(String testName) {
706 if (logger.isDebugEnabled()) {
707 logger.debug(testBanner(testName, CLASS_NAME));
710 setupReadNonExistent();
712 // Submit the request to the service and store the response.
713 LocationAuthorityClient client = new LocationAuthorityClient();
714 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
716 int statusCode = res.getStatus();
718 // Check the status code of the response: does it match
719 // the expected response(s)?
720 if(logger.isDebugEnabled()){
721 logger.debug(testName + ": status = " + statusCode);
723 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
724 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
725 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
727 res.releaseConnection();
732 // ---------------------------------------------------------------
733 // CRUD tests : READ_LIST tests
734 // ---------------------------------------------------------------
738 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
741 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
742 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
743 public void readList(String testName) throws Exception {
745 if (logger.isDebugEnabled()) {
746 logger.debug(testBanner(testName, CLASS_NAME));
751 // Submit the request to the service and store the response.
752 LocationAuthorityClient client = new LocationAuthorityClient();
753 ClientResponse<LocationauthoritiesCommonList> res = client.readList();
755 LocationauthoritiesCommonList list = res.getEntity();
756 int statusCode = res.getStatus();
758 // Check the status code of the response: does it match
759 // the expected response(s)?
760 if(logger.isDebugEnabled()){
761 logger.debug(testName + ": status = " + statusCode);
763 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
764 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
765 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
767 // Optionally output additional data about list members for debugging.
768 boolean iterateThroughList = false;
769 if (iterateThroughList && logger.isDebugEnabled()) {
770 List<LocationauthoritiesCommonList.LocationauthorityListItem> items =
771 list.getLocationauthorityListItem();
773 for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) {
774 String csid = item.getCsid();
775 logger.debug(testName + ": list-item[" + i + "] csid=" +
777 logger.debug(testName + ": list-item[" + i + "] displayName=" +
778 item.getDisplayName());
779 logger.debug(testName + ": list-item[" + i + "] URI=" +
781 readItemList(csid, null);
786 res.releaseConnection();
793 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
794 public void readItemList() {
795 String testName = "readItemList";
796 if (logger.isDebugEnabled()) {
797 logger.debug(testBanner(testName, CLASS_NAME));
799 readItemList(knownResourceId, null);
803 * Read item list by authority name.
805 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
806 public void readItemListByAuthorityName() {
807 String testName = "readItemListByAuthorityName";
808 if (logger.isDebugEnabled()) {
809 logger.debug(testBanner(testName, CLASS_NAME));
811 readItemList(null, knownResourceShortIdentifer);
817 * @param vcsid the vcsid
818 * @param name the name
820 private void readItemList(String vcsid, String shortId) {
822 String testName = "readItemList";
827 // Submit the request to the service and store the response.
828 LocationAuthorityClient client = new LocationAuthorityClient();
829 ClientResponse<LocationsCommonList> res = null;
831 res = client.readItemList(vcsid, null, null);
832 } else if(shortId!= null) {
833 res = client.readItemListForNamedAuthority(shortId, null, null);
835 Assert.fail("readItemList passed null csid and name!");
838 LocationsCommonList list = res.getEntity();
839 int statusCode = res.getStatus();
841 // Check the status code of the response: does it match
842 // the expected response(s)?
843 if(logger.isDebugEnabled()){
844 logger.debug(testName + ": status = " + statusCode);
846 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
847 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
848 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
850 List<LocationsCommonList.LocationListItem> items =
851 list.getLocationListItem();
852 int nItemsReturned = items.size();
853 // There will be one item created, associated with a
854 // known parent resource, by the createItem test.
856 // In addition, there will be 'nItemsToCreateInList'
857 // additional items created by the createItemList test,
858 // all associated with the same parent resource.
859 int nExpectedItems = nItemsToCreateInList + 1;
860 if(logger.isDebugEnabled()){
861 logger.debug(testName + ": Expected "
862 + nExpectedItems +" items; got: "+nItemsReturned);
864 Assert.assertEquals(nItemsReturned, nExpectedItems);
867 for (LocationsCommonList.LocationListItem item : items) {
868 Assert.assertTrue((null != item.getRefName()), "Item refName is null!");
869 Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!");
870 // Optionally output additional data about list members for debugging.
871 boolean showDetails = true;
872 if (showDetails && logger.isDebugEnabled()) {
873 logger.debug(" " + testName + ": list-item[" + i + "] csid=" +
875 logger.debug(" " + testName + ": list-item[" + i + "] refName=" +
877 logger.debug(" " + testName + ": list-item[" + i + "] displayName=" +
878 item.getDisplayName());
879 logger.debug(" " + testName + ": list-item[" + i + "] URI=" +
885 res.releaseConnection();
893 // ---------------------------------------------------------------
894 // CRUD tests : UPDATE tests
895 // ---------------------------------------------------------------
898 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
901 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
902 groups = {"update"}, dependsOnGroups = {"read", "readList"})
903 public void update(String testName) throws Exception {
905 if (logger.isDebugEnabled()) {
906 logger.debug(testBanner(testName, CLASS_NAME));
911 // Retrieve the contents of a resource to update.
912 LocationAuthorityClient client = new LocationAuthorityClient();
913 ClientResponse<String> res = client.read(knownResourceId);
915 if(logger.isDebugEnabled()){
916 logger.debug(testName + ": read status = " + res.getStatus());
918 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
920 if(logger.isDebugEnabled()){
921 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
923 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
924 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
925 client.getCommonPartName(), LocationauthoritiesCommon.class);
926 Assert.assertNotNull(locationAuthority);
928 // Update the contents of this resource.
929 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
930 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
931 if(logger.isDebugEnabled()){
932 logger.debug("to be updated LocationAuthority");
933 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
936 // Submit the updated resource to the service and store the response.
937 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
938 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
939 commonPart.setLabel(client.getCommonPartName());
940 res.releaseConnection();
941 res = client.update(knownResourceId, output);
942 int statusCode = res.getStatus();
944 // Check the status code of the response: does it match 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 // Retrieve the updated resource and verify that its contents exist.
953 input = new PoxPayloadIn(res.getEntity());
954 LocationauthoritiesCommon updatedLocationAuthority =
955 (LocationauthoritiesCommon) extractPart(input,
956 client.getCommonPartName(), LocationauthoritiesCommon.class);
957 Assert.assertNotNull(updatedLocationAuthority);
959 // Verify that the updated resource received the correct data.
960 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
961 locationAuthority.getDisplayName(),
962 "Data in updated object did not match submitted data.");
964 res.releaseConnection();
971 * @param testName the test name
972 * @throws Exception the exception
974 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
975 groups = {"update"}, dependsOnMethods = {"update"})
976 public void updateItem(String testName) throws Exception {
978 if (logger.isDebugEnabled()) {
979 logger.debug(testBanner(testName, CLASS_NAME));
984 // Retrieve the contents of a resource to update.
985 LocationAuthorityClient client = new LocationAuthorityClient();
986 ClientResponse<String> res =
987 client.readItem(knownResourceId, knownItemResourceId);
989 if(logger.isDebugEnabled()){
990 logger.debug(testName + ": read status = " + res.getStatus());
992 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
994 if(logger.isDebugEnabled()){
995 logger.debug("got Location to update with ID: " +
996 knownItemResourceId +
997 " in LocationAuthority: " + knownResourceId );
999 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
1000 LocationsCommon location = (LocationsCommon) extractPart(input,
1001 client.getItemCommonPartName(), LocationsCommon.class);
1002 Assert.assertNotNull(location);
1004 // Update the contents of this resource.
1005 location.setCsid(null);
1006 location.setName("updated-" + location.getName());
1007 if(logger.isDebugEnabled()){
1008 logger.debug("to be updated Location");
1009 logger.debug(objectAsXmlString(location,
1010 LocationsCommon.class));
1013 // Submit the updated resource to the service and store the response.
1014 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1015 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1016 commonPart.setLabel(client.getItemCommonPartName());
1017 res.releaseConnection();
1018 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1019 int statusCode = res.getStatus();
1021 // Check the status code of the response: does it match the expected response(s)?
1022 if(logger.isDebugEnabled()){
1023 logger.debug(testName + ": status = " + statusCode);
1025 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1026 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1027 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1029 // Retrieve the updated resource and verify that its contents exist.
1030 input = new PoxPayloadIn(res.getEntity());
1031 LocationsCommon updatedLocation =
1032 (LocationsCommon) extractPart(input,
1033 client.getItemCommonPartName(), LocationsCommon.class);
1034 Assert.assertNotNull(updatedLocation);
1036 // Verify that the updated resource received the correct data.
1037 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1038 "Data in updated Location did not match submitted data.");
1040 res.releaseConnection();
1045 // Placeholders until the three tests below can be uncommented.
1046 // See Issue CSPACE-401.
1048 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1051 public void updateWithEmptyEntityBody(String testName) throws Exception {
1055 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1058 public void updateWithMalformedXml(String testName) throws Exception {
1062 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1065 public void updateWithWrongXmlSchema(String testName) throws Exception {
1070 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1073 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1074 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1075 public void updateNonExistent(String testName) throws Exception {
1077 if (logger.isDebugEnabled()) {
1078 logger.debug(testBanner(testName, CLASS_NAME));
1081 setupUpdateNonExistent();
1083 // Submit the request to the service and store the response.
1084 // Note: The ID(s) used when creating the request payload may be arbitrary.
1085 // The only relevant ID may be the one used in update(), below.
1086 LocationAuthorityClient client = new LocationAuthorityClient();
1087 String displayName = "displayName-NON_EXISTENT_ID";
1088 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1089 displayName, "nonEx", client.getCommonPartName());
1090 ClientResponse<String> res =
1091 client.update(NON_EXISTENT_ID, multipart);
1093 int statusCode = res.getStatus();
1095 // Check the status code of the response: does it match
1096 // the expected response(s)?
1097 if(logger.isDebugEnabled()){
1098 logger.debug(testName + ": status = " + statusCode);
1100 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1101 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1102 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1104 res.releaseConnection();
1109 * Update non existent item.
1111 * @param testName the test name
1112 * @throws Exception the exception
1114 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1115 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1116 public void updateNonExistentItem(String testName) throws Exception {
1118 if (logger.isDebugEnabled()) {
1119 logger.debug(testBanner(testName, CLASS_NAME));
1122 setupUpdateNonExistent();
1124 // Submit the request to the service and store the response.
1125 // Note: The ID used in this 'create' call may be arbitrary.
1126 // The only relevant ID may be the one used in update(), below.
1127 LocationAuthorityClient client = new LocationAuthorityClient();
1128 Map<String, String> nonexMap = new HashMap<String,String>();
1129 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1130 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1131 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1132 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1133 PoxPayloadOut multipart =
1134 LocationAuthorityClientUtils.createLocationInstance(
1135 LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1136 nonexMap, client.getItemCommonPartName() );
1137 ClientResponse<String> res =
1138 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1140 int statusCode = res.getStatus();
1142 // Check the status code of the response: does it match
1143 // the expected response(s)?
1144 if(logger.isDebugEnabled()){
1145 logger.debug(testName + ": status = " + statusCode);
1147 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1148 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1149 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1151 res.releaseConnection();
1155 // ---------------------------------------------------------------
1156 // CRUD tests : DELETE tests
1157 // ---------------------------------------------------------------
1160 // Note: delete sub-resources in ascending hierarchical order,
1161 // before deleting their parents.
1166 * @param testName the test name
1167 * @throws Exception the exception
1169 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1170 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1171 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1172 public void deleteItem(String testName) throws Exception {
1174 if (logger.isDebugEnabled()) {
1175 logger.debug(testBanner(testName, CLASS_NAME));
1180 if(logger.isDebugEnabled()){
1181 logger.debug("parentcsid =" + knownResourceId +
1182 " itemcsid = " + knownItemResourceId);
1185 // Submit the request to the service and store the response.
1186 LocationAuthorityClient client = new LocationAuthorityClient();
1187 ClientResponse<Response> res =
1188 client.deleteItem(knownResourceId, knownItemResourceId);
1190 int statusCode = res.getStatus();
1192 // Check the status code of the response: does it match
1193 // the expected response(s)?
1194 if(logger.isDebugEnabled()){
1195 logger.debug(testName + ": status = " + statusCode);
1197 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1198 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1199 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1201 res.releaseConnection();
1206 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1209 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1210 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1211 public void delete(String testName) throws Exception {
1213 if (logger.isDebugEnabled()) {
1214 logger.debug(testBanner(testName, CLASS_NAME));
1219 if(logger.isDebugEnabled()){
1220 logger.debug("parentcsid =" + knownResourceId);
1223 // Submit the request to the service and store the response.
1224 LocationAuthorityClient client = new LocationAuthorityClient();
1225 ClientResponse<Response> res = client.delete(knownResourceId);
1227 int statusCode = res.getStatus();
1229 // Check the status code of the response: does it match
1230 // the expected response(s)?
1231 if(logger.isDebugEnabled()){
1232 logger.debug(testName + ": status = " + statusCode);
1234 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1235 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1236 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1238 res.releaseConnection();
1244 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1247 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1248 groups = {"delete"}, dependsOnMethods = {"delete"})
1249 public void deleteNonExistent(String testName) throws Exception {
1251 if (logger.isDebugEnabled()) {
1252 logger.debug(testBanner(testName, CLASS_NAME));
1255 setupDeleteNonExistent();
1257 // Submit the request to the service and store the response.
1258 LocationAuthorityClient client = new LocationAuthorityClient();
1259 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1261 int statusCode = res.getStatus();
1263 // Check the status code of the response: does it match
1264 // the expected response(s)?
1265 if(logger.isDebugEnabled()){
1266 logger.debug(testName + ": status = " + statusCode);
1268 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1269 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1270 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1272 res.releaseConnection();
1277 * Delete non existent item.
1279 * @param testName the test name
1281 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1282 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1283 public void deleteNonExistentItem(String testName) {
1285 if (logger.isDebugEnabled()) {
1286 logger.debug(testBanner(testName, CLASS_NAME));
1289 setupDeleteNonExistent();
1291 // Submit the request to the service and store the response.
1292 LocationAuthorityClient client = new LocationAuthorityClient();
1293 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1295 int statusCode = res.getStatus();
1297 // Check the status code of the response: does it match
1298 // the expected response(s)?
1299 if(logger.isDebugEnabled()){
1300 logger.debug(testName + ": status = " + statusCode);
1302 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1303 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1304 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1306 res.releaseConnection();
1310 // ---------------------------------------------------------------
1311 // Utility tests : tests of code used in tests above
1312 // ---------------------------------------------------------------
1314 * Tests the code for manually submitting data that is used by several
1315 * of the methods above.
1317 @Test(dependsOnMethods = {"create", "read"})
1318 public void testSubmitRequest() {
1320 // Expected status code: 200 OK
1321 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1323 // Submit the request to the service and store the response.
1324 String method = ServiceRequestType.READ.httpMethodName();
1325 String url = getResourceURL(knownResourceId);
1326 int statusCode = submitRequest(method, url);
1328 // Check the status code of the response: does it match
1329 // the expected response(s)?
1330 if(logger.isDebugEnabled()){
1331 logger.debug("testSubmitRequest: url=" + url +
1332 " status=" + statusCode);
1334 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1339 * Test item submit request.
1341 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1342 public void testItemSubmitRequest() {
1344 // Expected status code: 200 OK
1345 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1347 // Submit the request to the service and store the response.
1348 String method = ServiceRequestType.READ.httpMethodName();
1349 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1350 int statusCode = submitRequest(method, url);
1352 // Check the status code of the response: does it match
1353 // the expected response(s)?
1354 if(logger.isDebugEnabled()){
1355 logger.debug("testItemSubmitRequest: url=" + url +
1356 " status=" + statusCode);
1358 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1362 // ---------------------------------------------------------------
1363 // Cleanup of resources created during testing
1364 // ---------------------------------------------------------------
1367 * Deletes all resources created by tests, after all tests have been run.
1369 * This cleanup method will always be run, even if one or more tests fail.
1370 * For this reason, it attempts to remove all resources created
1371 * at any point during testing, even if some of those resources
1372 * may be expected to be deleted by certain tests.
1375 @AfterClass(alwaysRun=true)
1376 public void cleanUp() {
1377 String noTest = System.getProperty("noTestCleanup");
1378 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1379 if (logger.isDebugEnabled()) {
1380 logger.debug("Skipping Cleanup phase ...");
1384 if (logger.isDebugEnabled()) {
1385 logger.debug("Cleaning up temporary resources created for testing ...");
1387 String parentResourceId;
1388 String itemResourceId;
1389 // Clean up contact resources.
1390 LocationAuthorityClient client = new LocationAuthorityClient();
1391 parentResourceId = knownResourceId;
1392 // Clean up item resources.
1393 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1394 itemResourceId = entry.getKey();
1395 parentResourceId = entry.getValue();
1396 // Note: Any non-success responses from the delete operation
1397 // below are ignored and not reported.
1398 ClientResponse<Response> res =
1399 client.deleteItem(parentResourceId, itemResourceId);
1400 res.releaseConnection();
1402 // Clean up parent resources.
1403 for (String resourceId : allResourceIdsCreated) {
1404 // Note: Any non-success responses from the delete operation
1405 // below are ignored and not reported.
1406 ClientResponse<Response> res = client.delete(resourceId);
1407 res.releaseConnection();
1411 // ---------------------------------------------------------------
1412 // Utility methods used by tests above
1413 // ---------------------------------------------------------------
1415 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1419 * Returns the root URL for the item service.
1421 * This URL consists of a base URL for all services, followed by
1422 * a path component for the owning parent, followed by the
1423 * path component for the items.
1425 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1426 * parent authority resource of the relevant item resource.
1428 * @return The root URL for the item service.
1430 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1431 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1435 * Returns the URL of a specific item resource managed by a service, and
1436 * designated by an identifier (such as a universally unique ID, or UUID).
1438 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1439 * parent authority resource of the relevant item resource.
1441 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1444 * @return The URL of a specific item resource managed by a service.
1446 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1447 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;