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.AuthorityClient;
32 import org.collectionspace.services.client.CollectionSpaceClient;
33 import org.collectionspace.services.client.PayloadOutputPart;
34 import org.collectionspace.services.client.PoxPayloadIn;
35 import org.collectionspace.services.client.PoxPayloadOut;
36 import org.collectionspace.services.common.AbstractCommonListUtils;
37 import org.collectionspace.services.client.LocationAuthorityClient;
38 import org.collectionspace.services.client.LocationAuthorityClientUtils;
39 import org.collectionspace.services.jaxb.AbstractCommonList;
40 import org.collectionspace.services.location.LocationauthoritiesCommon;
41 import org.collectionspace.services.location.LocationsCommon;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45 import org.jboss.resteasy.client.ClientResponse;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
50 import org.testng.Assert;
51 import org.testng.annotations.AfterClass;
52 import org.testng.annotations.Test;
55 * LocationAuthorityServiceTest, carries out tests against a
56 * deployed and running LocationAuthority Service.
58 * $LastChangedRevision: 753 $
59 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
61 public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
64 private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName();
65 private final Logger logger = LoggerFactory.getLogger(LocationAuthorityServiceTest.class);
66 private final String REFNAME = "refName";
67 private final String DISPLAYNAME = "displayName";
70 public String getServicePathComponent() {
71 return LocationAuthorityClient.SERVICE_PATH_COMPONENT;
75 protected String getServiceName() {
76 return LocationAuthorityClient.SERVICE_NAME;
79 public String getItemServicePathComponent() {
80 return AuthorityClient.ITEMS;
83 // Instance variables specific to this test.
85 // /** The SERVICE path component. */
86 // final String SERVICE_PATH_COMPONENT = "locationauthorities";
88 // /** The ITEM service path component. */
89 // final String ITEM_SERVICE_PATH_COMPONENT = "items";
91 // /** The CONTACT service path component. */
92 // final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
94 final String TEST_NAME = "Shelf 1";
95 final String TEST_SHORTID = "shelf1";
96 final String TEST_CONDITION_NOTE = "Basically clean";
97 final String TEST_CONDITION_NOTE_DATE = "June 11, 1979";
98 final String TEST_SECURITY_NOTE = "Kind of safe";
99 final String TEST_ACCESS_NOTE = "Only right-thinkers may see";
100 final String TEST_ADDRESS = "123 Main Street, Anytown USA";
101 // TODO Make loc type be a controlled vocab term.
102 final String TEST_LOCATION_TYPE = "Shelf";
103 // TODO Make status type be a controlled vocab term.
104 final String TEST_STATUS = "Approved";
106 /** The known resource id. */
107 private String knownResourceId = null;
108 private String knownResourceShortIdentifer = null;
109 private String knownResourceRefName = null;
110 private String knownLocationTypeRefName = null;
111 private String knownItemResourceId = null;
112 private String knownItemResourceShortIdentifer = null;
113 private String knownContactResourceId = null;
115 /** The n items to create in list. */
116 private int nItemsToCreateInList = 3;
118 /** The all resource ids created. */
119 private List<String> allResourceIdsCreated = new ArrayList<String>();
121 /** The all item resource ids created. */
122 private Map<String, String> allItemResourceIdsCreated =
123 new HashMap<String, String>();
125 protected void setKnownResource( String id, String shortIdentifer,
127 knownResourceId = id;
128 knownResourceShortIdentifer = shortIdentifer;
129 knownResourceRefName = refName;
132 protected void setKnownItemResource( String id, String shortIdentifer ) {
133 knownItemResourceId = id;
134 knownItemResourceShortIdentifer = shortIdentifer;
138 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
141 protected CollectionSpaceClient getClientInstance() {
142 return new LocationAuthorityClient();
146 protected PoxPayloadOut createInstance(String identifier) {
147 LocationAuthorityClient client = new LocationAuthorityClient();
148 String shortId = identifier;
149 String displayName = "displayName-" + shortId;
151 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
152 PoxPayloadOut multipart =
153 LocationAuthorityClientUtils.createLocationAuthorityInstance(
154 displayName, shortId, client.getCommonPartName());
158 // ---------------------------------------------------------------
159 // CRUD tests : CREATE tests
160 // ---------------------------------------------------------------
163 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
166 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
168 public void create(String testName) throws Exception {
170 if (logger.isDebugEnabled()) {
171 logger.debug(testBanner(testName, CLASS_NAME));
173 // Perform setup, such as initializing the type of service request
174 // (e.g. CREATE, DELETE), its valid and expected status codes, and
175 // its associated HTTP method name (e.g. POST, DELETE).
178 // Submit the request to the service and store the response.
179 LocationAuthorityClient client = new LocationAuthorityClient();
180 String shortId = createIdentifier();
181 String displayName = "displayName-" + shortId;
183 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
185 PoxPayloadOut multipart =
186 LocationAuthorityClientUtils.createLocationAuthorityInstance(
187 displayName, shortId, client.getCommonPartName());
189 ClientResponse<Response> res = client.create(multipart);
191 int statusCode = res.getStatus();
193 // Check the status code of the response: does it match
194 // the expected response(s)?
197 // Does it fall within the set of valid status codes?
198 // Does it exactly match the expected status code?
199 if(logger.isDebugEnabled()){
200 logger.debug(testName + ": status = " + statusCode);
202 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
203 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
204 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
206 newID = LocationAuthorityClientUtils.extractId(res);
208 res.releaseConnection();
210 // Store the ID returned from the first resource created
211 // for additional tests below.
212 if (knownResourceId == null){
213 setKnownResource( newID, shortId, baseRefName );
214 if (logger.isDebugEnabled()) {
215 logger.debug(testName + ": knownResourceId=" + knownResourceId);
218 // Store the IDs from every resource created by tests,
219 // so they can be deleted after tests have been run.
220 allResourceIdsCreated.add(newID);
226 * @param testName the test name
228 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
229 groups = {"create"}, dependsOnMethods = {"create"})
230 public void createItem(String testName) {
231 if(logger.isDebugEnabled()){
232 logger.debug(testBanner(testName, CLASS_NAME));
235 createItemInAuthority(knownResourceId, knownResourceRefName);
239 * Creates the item in authority.
241 * @param vcsid the vcsid
242 * @param authRefName the auth ref name
245 private String createItemInAuthority(String vcsid, String authRefName) {
247 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
248 if(logger.isDebugEnabled()){
249 logger.debug(testBanner(testName, CLASS_NAME));
252 // Submit the request to the service and store the response.
253 LocationAuthorityClient client = new LocationAuthorityClient();
254 Map<String, String> shelf1Map = new HashMap<String,String>();
255 // TODO Make loc type and status be controlled vocabs.
256 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
257 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
258 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
259 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
260 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
261 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
262 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
263 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
264 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
266 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
267 authRefName, shelf1Map, client );
269 // Store the ID returned from the first item resource created
270 // for additional tests below.
271 if (knownItemResourceId == null){
272 setKnownItemResource(newID, TEST_SHORTID);
273 if (logger.isDebugEnabled()) {
274 logger.debug(testName + ": knownItemResourceId=" + newID);
278 // Store the IDs from any item resources created
279 // by tests, along with the IDs of their parents, so these items
280 // can be deleted after all tests have been run.
281 allItemResourceIdsCreated.put(newID, vcsid);
290 // Placeholders until the three tests below can be uncommented.
291 // See Issue CSPACE-401.
293 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
296 public void createWithEmptyEntityBody(String testName) throws Exception {
300 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
303 public void createWithMalformedXml(String testName) throws Exception {
307 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
310 public void createWithWrongXmlSchema(String testName) throws Exception {
314 // ---------------------------------------------------------------
315 // CRUD tests : CREATE LIST tests
316 // ---------------------------------------------------------------
319 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
322 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
323 groups = {"createList"}, dependsOnGroups = {"create"})
324 public void createList(String testName) throws Exception {
325 for (int i = 0; i < nItemsToCreateInList; i++) {
331 * Creates the item list.
333 * @param testName the test name
334 * @throws Exception the exception
336 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
337 groups = {"createList"}, dependsOnMethods = {"createList"})
338 public void createItemList(String testName) throws Exception {
339 // Add items to the initially-created, known parent record.
340 for (int j = 0; j < nItemsToCreateInList; j++) {
341 createItem(testName);
345 // ---------------------------------------------------------------
346 // CRUD tests : READ tests
347 // ---------------------------------------------------------------
350 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
353 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
354 groups = {"read"}, dependsOnGroups = {"create"})
355 public void read(String testName) throws Exception {
357 if (logger.isDebugEnabled()) {
358 logger.debug(testBanner(testName, CLASS_NAME));
363 // Submit the request to the service and store the response.
364 LocationAuthorityClient client = new LocationAuthorityClient();
366 ClientResponse<String> res = client.read(knownResourceId);
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);
378 //FIXME: remove the following try catch once Aron fixes signatures
380 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
381 LocationauthoritiesCommon locationAuthority =
382 (LocationauthoritiesCommon) extractPart(input,
383 client.getCommonPartName(), LocationauthoritiesCommon.class);
384 Assert.assertNotNull(locationAuthority);
385 Assert.assertNotNull(locationAuthority.getDisplayName());
386 Assert.assertNotNull(locationAuthority.getShortIdentifier());
387 Assert.assertNotNull(locationAuthority.getRefName());
388 } catch (Exception e) {
389 throw new RuntimeException(e);
392 res.releaseConnection();
399 * @param testName the test name
400 * @throws Exception the exception
402 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
403 groups = {"read"}, dependsOnGroups = {"create"})
404 public void readByName(String testName) throws Exception {
406 if (logger.isDebugEnabled()) {
407 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
412 // Submit the request to the service and store the response.
413 LocationAuthorityClient client = new LocationAuthorityClient();
414 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
416 int statusCode = res.getStatus();
418 // Check the status code of the response: does it match
419 // the expected response(s)?
420 if(logger.isDebugEnabled()){
421 logger.debug(testName + ": status = " + statusCode);
423 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
424 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
425 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
426 //FIXME: remove the following try catch once Aron fixes signatures
428 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
429 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
430 client.getCommonPartName(), LocationauthoritiesCommon.class);
431 Assert.assertNotNull(locationAuthority);
432 } catch (Exception e) {
433 throw new RuntimeException(e);
436 res.releaseConnection();
444 * @param testName the test name
445 * @throws Exception the exception
447 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
448 groups = {"read"}, dependsOnMethods = {"read"})
449 public void readItem(String testName) throws Exception {
451 if (logger.isDebugEnabled()) {
452 logger.debug(testBanner(testName, CLASS_NAME));
457 // Submit the request to the service and store the response.
458 LocationAuthorityClient client = new LocationAuthorityClient();
459 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
461 int statusCode = res.getStatus();
463 // Check the status code of the response: does it match
464 // the expected response(s)?
465 if(logger.isDebugEnabled()){
466 logger.debug(testName + ": status = " + statusCode);
468 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
469 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
470 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
472 // Check whether we've received a location.
473 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
474 LocationsCommon location = (LocationsCommon) extractPart(input,
475 client.getItemCommonPartName(), LocationsCommon.class);
476 Assert.assertNotNull(location);
477 boolean showFull = true;
478 if(showFull && logger.isDebugEnabled()){
479 logger.debug(testName + ": returned payload:");
480 logger.debug(objectAsXmlString(location, LocationsCommon.class));
482 Assert.assertEquals(location.getInAuthority(), knownResourceId);
484 res.releaseConnection();
490 * Verify item display name.
492 * @param testName the test name
493 * @throws Exception the exception
495 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
496 dependsOnMethods = {"readItem", "updateItem"})
497 public void verifyItemDisplayName(String testName) throws Exception {
499 if (logger.isDebugEnabled()) {
500 logger.debug(testBanner(testName, CLASS_NAME));
505 // Submit the request to the service and store the response.
506 LocationAuthorityClient client = new LocationAuthorityClient();
507 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
509 int statusCode = res.getStatus();
511 // Check the status code of the response: does it match
512 // the expected response(s)?
513 if(logger.isDebugEnabled()){
514 logger.debug(testName + ": status = " + statusCode);
516 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
517 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
518 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
520 // Check whether location has expected displayName.
521 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
522 LocationsCommon location = (LocationsCommon) extractPart(input,
523 client.getItemCommonPartName(), LocationsCommon.class);
524 Assert.assertNotNull(location);
525 String displayName = location.getDisplayName();
526 // Make sure displayName matches computed form
527 String expectedDisplayName =
528 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
529 Assert.assertNotNull(displayName, expectedDisplayName);
531 // Update the shortName and verify the computed name is updated.
532 location.setCsid(null);
533 location.setDisplayNameComputed(true);
534 location.setName("updated-" + TEST_NAME);
535 expectedDisplayName =
536 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
538 // Submit the updated resource to the service and store the response.
539 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
540 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
541 commonPart.setLabel(client.getItemCommonPartName());
542 res.releaseConnection();
543 res = client.updateItem(knownResourceId, knownItemResourceId, output);
544 statusCode = res.getStatus();
546 // Check the status code of the response: does it match the expected response(s)?
547 if(logger.isDebugEnabled()){
548 logger.debug("updateItem: status = " + statusCode);
550 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
551 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
552 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
554 // Retrieve the updated resource and verify that its contents exist.
555 input = new PoxPayloadIn(res.getEntity());
556 LocationsCommon updatedLocation =
557 (LocationsCommon) extractPart(input,
558 client.getItemCommonPartName(), LocationsCommon.class);
559 Assert.assertNotNull(updatedLocation);
561 // Verify that the updated resource received the correct data.
562 Assert.assertEquals(updatedLocation.getName(), location.getName(),
563 "Updated ForeName in Location did not match submitted data.");
564 // Verify that the updated resource computes the right displayName.
565 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
566 "Updated ForeName in Location not reflected in computed DisplayName.");
568 // Now Update the displayName, not computed and verify the computed name is overriden.
569 location.setDisplayNameComputed(false);
570 expectedDisplayName = "TestName";
571 location.setDisplayName(expectedDisplayName);
573 // Submit the updated resource to the service and store the response.
574 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
575 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
576 commonPart.setLabel(client.getItemCommonPartName());
577 res.releaseConnection();
578 res = client.updateItem(knownResourceId, knownItemResourceId, output);
579 statusCode = res.getStatus();
581 // Check the status code of the response: does it match the expected response(s)?
582 if(logger.isDebugEnabled()){
583 logger.debug("updateItem: status = " + statusCode);
585 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
586 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
587 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
589 // Retrieve the updated resource and verify that its contents exist.
590 input = new PoxPayloadIn(res.getEntity());
592 (LocationsCommon) extractPart(input,
593 client.getItemCommonPartName(), LocationsCommon.class);
594 Assert.assertNotNull(updatedLocation);
596 // Verify that the updated resource received the correct data.
597 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
598 "Updated displayNameComputed in Location did not match submitted data.");
599 // Verify that the updated resource computes the right displayName.
600 Assert.assertEquals(updatedLocation.getDisplayName(),
602 "Updated DisplayName (not computed) in Location not stored.");
604 res.releaseConnection();
609 * Verify illegal item display name.
611 * @param testName the test name
612 * @throws Exception the exception
614 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
615 dependsOnMethods = {"verifyItemDisplayName"})
616 public void verifyIllegalItemDisplayName(String testName) throws Exception {
618 if (logger.isDebugEnabled()) {
619 logger.debug(testBanner(testName, CLASS_NAME));
622 // FIXME: create a setup configuration for this operation.
623 setupUpdateWithWrongXmlSchema();
625 // Submit the request to the service and store the response.
626 LocationAuthorityClient client = new LocationAuthorityClient();
627 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
629 int statusCode = res.getStatus();
631 // Check the status code of the response: does it match
632 // the expected response(s)?
633 if(logger.isDebugEnabled()){
634 logger.debug(testName + ": status = " + statusCode);
636 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
637 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
638 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
640 // Check whether Location has expected displayName.
641 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
642 LocationsCommon location = (LocationsCommon) extractPart(input,
643 client.getItemCommonPartName(), LocationsCommon.class);
644 Assert.assertNotNull(location);
645 // Try to Update with computed false and no displayName
646 location.setDisplayNameComputed(false);
647 location.setDisplayName(null);
649 // Submit the updated resource to the service and store the response.
650 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
651 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
652 commonPart.setLabel(client.getItemCommonPartName());
653 res.releaseConnection();
654 res = client.updateItem(knownResourceId, knownItemResourceId, output);
655 statusCode = res.getStatus();
657 // Check the status code of the response: does it match the expected response(s)?
658 if(logger.isDebugEnabled()){
659 logger.debug("updateItem: status = " + statusCode);
661 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
662 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
663 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
665 res.releaseConnection();
672 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
675 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
676 groups = {"read"}, dependsOnMethods = {"read"})
677 public void readNonExistent(String testName) {
679 if (logger.isDebugEnabled()) {
680 logger.debug(testBanner(testName, CLASS_NAME));
683 setupReadNonExistent();
685 // Submit the request to the service and store the response.
686 LocationAuthorityClient client = new LocationAuthorityClient();
687 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
689 int statusCode = res.getStatus();
691 // Check the status code of the response: does it match
692 // the expected response(s)?
693 if(logger.isDebugEnabled()){
694 logger.debug(testName + ": status = " + statusCode);
696 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
697 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
698 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
700 res.releaseConnection();
705 * Read item non existent.
707 * @param testName the test name
709 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
710 groups = {"read"}, dependsOnMethods = {"readItem"})
711 public void readItemNonExistent(String testName) {
713 if (logger.isDebugEnabled()) {
714 logger.debug(testBanner(testName, CLASS_NAME));
717 setupReadNonExistent();
719 // Submit the request to the service and store the response.
720 LocationAuthorityClient client = new LocationAuthorityClient();
721 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
723 int statusCode = res.getStatus();
725 // Check the status code of the response: does it match
726 // the expected response(s)?
727 if(logger.isDebugEnabled()){
728 logger.debug(testName + ": status = " + statusCode);
730 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
731 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
732 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
734 res.releaseConnection();
739 // ---------------------------------------------------------------
740 // CRUD tests : READ_LIST tests
741 // ---------------------------------------------------------------
745 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
748 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
749 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
750 public void readList(String testName) throws Exception {
752 if (logger.isDebugEnabled()) {
753 logger.debug(testBanner(testName, CLASS_NAME));
758 // Submit the request to the service and store the response.
759 LocationAuthorityClient client = new LocationAuthorityClient();
760 ClientResponse<AbstractCommonList> res = client.readList();
762 AbstractCommonList list = res.getEntity();
763 int statusCode = res.getStatus();
765 // Check the status code of the response: does it match
766 // the expected response(s)?
767 if(logger.isDebugEnabled()){
768 logger.debug(testName + ": status = " + statusCode);
770 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
771 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
772 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
774 // Optionally output additional data about list members for debugging.
775 if(logger.isTraceEnabled()){
776 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
779 res.releaseConnection();
786 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
787 public void readItemList() {
788 String testName = "readItemList";
789 if (logger.isDebugEnabled()) {
790 logger.debug(testBanner(testName, CLASS_NAME));
792 readItemList(knownResourceId, null);
796 * Read item list by authority name.
798 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
799 public void readItemListByAuthorityName() {
800 String testName = "readItemListByAuthorityName";
801 if (logger.isDebugEnabled()) {
802 logger.debug(testBanner(testName, CLASS_NAME));
804 readItemList(null, knownResourceShortIdentifer);
810 * @param vcsid the vcsid
811 * @param name the name
813 private void readItemList(String vcsid, String shortId) {
815 String testName = "readItemList";
820 // Submit the request to the service and store the response.
821 LocationAuthorityClient client = new LocationAuthorityClient();
822 ClientResponse<AbstractCommonList> res = null;
824 res = client.readItemList(vcsid, null, null);
825 } else if(shortId!= null) {
826 res = client.readItemListForNamedAuthority(shortId, null, null);
828 Assert.fail("readItemList passed null csid and name!");
831 AbstractCommonList list = res.getEntity();
832 int statusCode = res.getStatus();
834 // Check the status code of the response: does it match
835 // the expected response(s)?
836 if(logger.isDebugEnabled()){
837 logger.debug(testName + ": status = " + statusCode);
839 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
840 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
841 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
843 List<AbstractCommonList.ListItem> items =
845 int nItemsReturned = items.size();
846 // There will be one item created, associated with a
847 // known parent resource, by the createItem test.
849 // In addition, there will be 'nItemsToCreateInList'
850 // additional items created by the createItemList test,
851 // all associated with the same parent resource.
852 int nExpectedItems = nItemsToCreateInList + 1;
853 if(logger.isDebugEnabled()){
854 logger.debug(testName + ": Expected "
855 + nExpectedItems +" items; got: "+nItemsReturned);
857 Assert.assertEquals(nItemsReturned, nExpectedItems);
859 for (AbstractCommonList.ListItem item : items) {
861 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
862 Assert.assertTrue((null != value), "Item refName is null!");
864 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
865 Assert.assertTrue((null != value), "Item displayName is null!");
867 if(logger.isTraceEnabled()){
868 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
871 res.releaseConnection();
879 // ---------------------------------------------------------------
880 // CRUD tests : UPDATE tests
881 // ---------------------------------------------------------------
884 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
887 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
888 groups = {"update"}, dependsOnGroups = {"read", "readList"})
889 public void update(String testName) throws Exception {
891 if (logger.isDebugEnabled()) {
892 logger.debug(testBanner(testName, CLASS_NAME));
897 // Retrieve the contents of a resource to update.
898 LocationAuthorityClient client = new LocationAuthorityClient();
899 ClientResponse<String> res = client.read(knownResourceId);
901 if(logger.isDebugEnabled()){
902 logger.debug(testName + ": read status = " + res.getStatus());
904 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
906 if(logger.isDebugEnabled()){
907 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
909 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
910 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
911 client.getCommonPartName(), LocationauthoritiesCommon.class);
912 Assert.assertNotNull(locationAuthority);
914 // Update the contents of this resource.
915 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
916 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
917 if(logger.isDebugEnabled()){
918 logger.debug("to be updated LocationAuthority");
919 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
922 // Submit the updated resource to the service and store the response.
923 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
924 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
925 commonPart.setLabel(client.getCommonPartName());
926 res.releaseConnection();
927 res = client.update(knownResourceId, output);
928 int statusCode = res.getStatus();
930 // Check the status code of the response: does it match the expected response(s)?
931 if(logger.isDebugEnabled()){
932 logger.debug(testName + ": status = " + statusCode);
934 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
935 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
936 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
938 // Retrieve the updated resource and verify that its contents exist.
939 input = new PoxPayloadIn(res.getEntity());
940 LocationauthoritiesCommon updatedLocationAuthority =
941 (LocationauthoritiesCommon) extractPart(input,
942 client.getCommonPartName(), LocationauthoritiesCommon.class);
943 Assert.assertNotNull(updatedLocationAuthority);
945 // Verify that the updated resource received the correct data.
946 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
947 locationAuthority.getDisplayName(),
948 "Data in updated object did not match submitted data.");
950 res.releaseConnection();
957 * @param testName the test name
958 * @throws Exception the exception
960 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
961 groups = {"update"}, dependsOnMethods = {"update"})
962 public void updateItem(String testName) throws Exception {
964 if (logger.isDebugEnabled()) {
965 logger.debug(testBanner(testName, CLASS_NAME));
970 // Retrieve the contents of a resource to update.
971 LocationAuthorityClient client = new LocationAuthorityClient();
972 ClientResponse<String> res =
973 client.readItem(knownResourceId, knownItemResourceId);
975 if(logger.isDebugEnabled()){
976 logger.debug(testName + ": read status = " + res.getStatus());
978 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
980 if(logger.isDebugEnabled()){
981 logger.debug("got Location to update with ID: " +
982 knownItemResourceId +
983 " in LocationAuthority: " + knownResourceId );
985 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
986 LocationsCommon location = (LocationsCommon) extractPart(input,
987 client.getItemCommonPartName(), LocationsCommon.class);
988 Assert.assertNotNull(location);
990 // Update the contents of this resource.
991 location.setCsid(null);
992 location.setName("updated-" + location.getName());
993 if(logger.isDebugEnabled()){
994 logger.debug("to be updated Location");
995 logger.debug(objectAsXmlString(location,
996 LocationsCommon.class));
999 // Submit the updated resource to the service and store the response.
1000 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1001 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1002 commonPart.setLabel(client.getItemCommonPartName());
1003 res.releaseConnection();
1004 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1005 int statusCode = res.getStatus();
1007 // Check the status code of the response: does it match the expected response(s)?
1008 if(logger.isDebugEnabled()){
1009 logger.debug(testName + ": status = " + statusCode);
1011 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1012 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1013 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1015 // Retrieve the updated resource and verify that its contents exist.
1016 input = new PoxPayloadIn(res.getEntity());
1017 LocationsCommon updatedLocation =
1018 (LocationsCommon) extractPart(input,
1019 client.getItemCommonPartName(), LocationsCommon.class);
1020 Assert.assertNotNull(updatedLocation);
1022 // Verify that the updated resource received the correct data.
1023 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1024 "Data in updated Location did not match submitted data.");
1026 res.releaseConnection();
1031 // Placeholders until the three tests below can be uncommented.
1032 // See Issue CSPACE-401.
1034 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1037 public void updateWithEmptyEntityBody(String testName) throws Exception {
1041 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1044 public void updateWithMalformedXml(String testName) throws Exception {
1048 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1051 public void updateWithWrongXmlSchema(String testName) throws Exception {
1056 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1059 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1060 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1061 public void updateNonExistent(String testName) throws Exception {
1063 if (logger.isDebugEnabled()) {
1064 logger.debug(testBanner(testName, CLASS_NAME));
1067 setupUpdateNonExistent();
1069 // Submit the request to the service and store the response.
1070 // Note: The ID(s) used when creating the request payload may be arbitrary.
1071 // The only relevant ID may be the one used in update(), below.
1072 LocationAuthorityClient client = new LocationAuthorityClient();
1073 String displayName = "displayName-NON_EXISTENT_ID";
1074 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1075 displayName, "nonEx", client.getCommonPartName());
1076 ClientResponse<String> res =
1077 client.update(NON_EXISTENT_ID, multipart);
1079 int statusCode = res.getStatus();
1081 // Check the status code of the response: does it match
1082 // the expected response(s)?
1083 if(logger.isDebugEnabled()){
1084 logger.debug(testName + ": status = " + statusCode);
1086 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1087 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1088 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1090 res.releaseConnection();
1095 * Update non existent item.
1097 * @param testName the test name
1098 * @throws Exception the exception
1100 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1101 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1102 public void updateNonExistentItem(String testName) throws Exception {
1104 if (logger.isDebugEnabled()) {
1105 logger.debug(testBanner(testName, CLASS_NAME));
1108 setupUpdateNonExistent();
1110 // Submit the request to the service and store the response.
1111 // Note: The ID used in this 'create' call may be arbitrary.
1112 // The only relevant ID may be the one used in update(), below.
1113 LocationAuthorityClient client = new LocationAuthorityClient();
1114 Map<String, String> nonexMap = new HashMap<String,String>();
1115 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1116 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1117 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1118 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1119 PoxPayloadOut multipart =
1120 LocationAuthorityClientUtils.createLocationInstance(
1121 LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1122 nonexMap, client.getItemCommonPartName() );
1123 ClientResponse<String> res =
1124 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1126 int statusCode = res.getStatus();
1128 // Check the status code of the response: does it match
1129 // the expected response(s)?
1130 if(logger.isDebugEnabled()){
1131 logger.debug(testName + ": status = " + statusCode);
1133 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1134 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1135 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1137 res.releaseConnection();
1141 // ---------------------------------------------------------------
1142 // CRUD tests : DELETE tests
1143 // ---------------------------------------------------------------
1146 // Note: delete sub-resources in ascending hierarchical order,
1147 // before deleting their parents.
1152 * @param testName the test name
1153 * @throws Exception the exception
1155 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1156 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1157 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1158 public void deleteItem(String testName) throws Exception {
1160 if (logger.isDebugEnabled()) {
1161 logger.debug(testBanner(testName, CLASS_NAME));
1166 if(logger.isDebugEnabled()){
1167 logger.debug("parentcsid =" + knownResourceId +
1168 " itemcsid = " + knownItemResourceId);
1171 // Submit the request to the service and store the response.
1172 LocationAuthorityClient client = new LocationAuthorityClient();
1173 ClientResponse<Response> res =
1174 client.deleteItem(knownResourceId, knownItemResourceId);
1176 int statusCode = res.getStatus();
1178 // Check the status code of the response: does it match
1179 // the expected response(s)?
1180 if(logger.isDebugEnabled()){
1181 logger.debug(testName + ": status = " + statusCode);
1183 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1184 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1185 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1187 res.releaseConnection();
1192 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1195 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1196 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1197 public void delete(String testName) throws Exception {
1199 if (logger.isDebugEnabled()) {
1200 logger.debug(testBanner(testName, CLASS_NAME));
1205 if(logger.isDebugEnabled()){
1206 logger.debug("parentcsid =" + knownResourceId);
1209 // Submit the request to the service and store the response.
1210 LocationAuthorityClient client = new LocationAuthorityClient();
1211 ClientResponse<Response> res = client.delete(knownResourceId);
1213 int statusCode = res.getStatus();
1215 // Check the status code of the response: does it match
1216 // the expected response(s)?
1217 if(logger.isDebugEnabled()){
1218 logger.debug(testName + ": status = " + statusCode);
1220 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1221 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1222 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1224 res.releaseConnection();
1230 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1233 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1234 groups = {"delete"}, dependsOnMethods = {"delete"})
1235 public void deleteNonExistent(String testName) throws Exception {
1237 if (logger.isDebugEnabled()) {
1238 logger.debug(testBanner(testName, CLASS_NAME));
1241 setupDeleteNonExistent();
1243 // Submit the request to the service and store the response.
1244 LocationAuthorityClient client = new LocationAuthorityClient();
1245 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1247 int statusCode = res.getStatus();
1249 // Check the status code of the response: does it match
1250 // the expected response(s)?
1251 if(logger.isDebugEnabled()){
1252 logger.debug(testName + ": status = " + statusCode);
1254 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1255 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1256 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1258 res.releaseConnection();
1263 * Delete non existent item.
1265 * @param testName the test name
1267 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1268 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1269 public void deleteNonExistentItem(String testName) {
1271 if (logger.isDebugEnabled()) {
1272 logger.debug(testBanner(testName, CLASS_NAME));
1275 setupDeleteNonExistent();
1277 // Submit the request to the service and store the response.
1278 LocationAuthorityClient client = new LocationAuthorityClient();
1279 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1281 int statusCode = res.getStatus();
1283 // Check the status code of the response: does it match
1284 // the expected response(s)?
1285 if(logger.isDebugEnabled()){
1286 logger.debug(testName + ": status = " + statusCode);
1288 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1289 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1290 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1292 res.releaseConnection();
1296 // ---------------------------------------------------------------
1297 // Utility tests : tests of code used in tests above
1298 // ---------------------------------------------------------------
1300 * Tests the code for manually submitting data that is used by several
1301 * of the methods above.
1303 @Test(dependsOnMethods = {"create", "read"})
1304 public void testSubmitRequest() {
1306 // Expected status code: 200 OK
1307 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1309 // Submit the request to the service and store the response.
1310 String method = ServiceRequestType.READ.httpMethodName();
1311 String url = getResourceURL(knownResourceId);
1312 int statusCode = submitRequest(method, url);
1314 // Check the status code of the response: does it match
1315 // the expected response(s)?
1316 if(logger.isDebugEnabled()){
1317 logger.debug("testSubmitRequest: url=" + url +
1318 " status=" + statusCode);
1320 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1325 * Test item submit request.
1327 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1328 public void testItemSubmitRequest() {
1330 // Expected status code: 200 OK
1331 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1333 // Submit the request to the service and store the response.
1334 String method = ServiceRequestType.READ.httpMethodName();
1335 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1336 int statusCode = submitRequest(method, url);
1338 // Check the status code of the response: does it match
1339 // the expected response(s)?
1340 if(logger.isDebugEnabled()){
1341 logger.debug("testItemSubmitRequest: url=" + url +
1342 " status=" + statusCode);
1344 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1348 // ---------------------------------------------------------------
1349 // Cleanup of resources created during testing
1350 // ---------------------------------------------------------------
1353 * Deletes all resources created by tests, after all tests have been run.
1355 * This cleanup method will always be run, even if one or more tests fail.
1356 * For this reason, it attempts to remove all resources created
1357 * at any point during testing, even if some of those resources
1358 * may be expected to be deleted by certain tests.
1361 @AfterClass(alwaysRun=true)
1362 public void cleanUp() {
1363 String noTest = System.getProperty("noTestCleanup");
1364 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1365 if (logger.isDebugEnabled()) {
1366 logger.debug("Skipping Cleanup phase ...");
1370 if (logger.isDebugEnabled()) {
1371 logger.debug("Cleaning up temporary resources created for testing ...");
1373 String parentResourceId;
1374 String itemResourceId;
1375 // Clean up contact resources.
1376 LocationAuthorityClient client = new LocationAuthorityClient();
1377 parentResourceId = knownResourceId;
1378 // Clean up item resources.
1379 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1380 itemResourceId = entry.getKey();
1381 parentResourceId = entry.getValue();
1382 // Note: Any non-success responses from the delete operation
1383 // below are ignored and not reported.
1384 ClientResponse<Response> res =
1385 client.deleteItem(parentResourceId, itemResourceId);
1386 res.releaseConnection();
1388 // Clean up parent resources.
1389 for (String resourceId : allResourceIdsCreated) {
1390 // Note: Any non-success responses from the delete operation
1391 // below are ignored and not reported.
1392 ClientResponse<Response> res = client.delete(resourceId);
1393 res.releaseConnection();
1397 // ---------------------------------------------------------------
1398 // Utility methods used by tests above
1399 // ---------------------------------------------------------------
1401 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1405 * Returns the root URL for the item service.
1407 * This URL consists of a base URL for all services, followed by
1408 * a path component for the owning parent, followed by the
1409 * path component for the items.
1411 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1412 * parent authority resource of the relevant item resource.
1414 * @return The root URL for the item service.
1416 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1417 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1421 * Returns the URL of a specific item resource managed by a service, and
1422 * designated by an identifier (such as a universally unique ID, or UUID).
1424 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1425 * parent authority resource of the relevant item resource.
1427 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1430 * @return The URL of a specific item resource managed by a service.
1432 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1433 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;