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.ContactClient;
34 import org.collectionspace.services.client.ContactClientUtils;
35 import org.collectionspace.services.client.PayloadOutputPart;
36 import org.collectionspace.services.client.PoxPayloadIn;
37 import org.collectionspace.services.client.PoxPayloadOut;
38 import org.collectionspace.services.common.AbstractCommonListUtils;
39 import org.collectionspace.services.contact.ContactsCommon;
40 import org.collectionspace.services.contact.ContactsCommonList;
41 import org.collectionspace.services.client.LocationAuthorityClient;
42 import org.collectionspace.services.client.LocationAuthorityClientUtils;
43 import org.collectionspace.services.jaxb.AbstractCommonList;
44 import org.collectionspace.services.location.LocationauthoritiesCommon;
45 import org.collectionspace.services.location.LocationsCommon;
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);
70 private final String REFNAME = "refName";
71 private final String DISPLAYNAME = "displayName";
74 public String getServicePathComponent() {
75 return LocationAuthorityClient.SERVICE_PATH_COMPONENT;
79 protected String getServiceName() {
80 return LocationAuthorityClient.SERVICE_NAME;
83 public String getItemServicePathComponent() {
84 return AuthorityClient.ITEMS;
87 // Instance variables specific to this test.
89 // /** The SERVICE path component. */
90 // final String SERVICE_PATH_COMPONENT = "locationauthorities";
92 // /** The ITEM service path component. */
93 // final String ITEM_SERVICE_PATH_COMPONENT = "items";
95 // /** The CONTACT service path component. */
96 // final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
98 final String TEST_NAME = "Shelf 1";
99 final String TEST_SHORTID = "shelf1";
100 final String TEST_CONDITION_NOTE = "Basically clean";
101 final String TEST_CONDITION_NOTE_DATE = "June 11, 1979";
102 final String TEST_SECURITY_NOTE = "Kind of safe";
103 final String TEST_ACCESS_NOTE = "Only right-thinkers may see";
104 final String TEST_ADDRESS = "123 Main Street, Anytown USA";
105 // TODO Make loc type be a controlled vocab term.
106 final String TEST_LOCATION_TYPE = "Shelf";
107 // TODO Make status type be a controlled vocab term.
108 final String TEST_STATUS = "Approved";
110 /** The known resource id. */
111 private String knownResourceId = null;
112 private String knownResourceShortIdentifer = null;
113 private String knownResourceRefName = null;
114 private String knownLocationTypeRefName = null;
115 private String knownItemResourceId = null;
116 private String knownItemResourceShortIdentifer = null;
117 private String knownContactResourceId = null;
119 /** The n items to create in list. */
120 private int nItemsToCreateInList = 3;
122 /** The all resource ids created. */
123 private List<String> allResourceIdsCreated = new ArrayList<String>();
125 /** The all item resource ids created. */
126 private Map<String, String> allItemResourceIdsCreated =
127 new HashMap<String, String>();
129 protected void setKnownResource( String id, String shortIdentifer,
131 knownResourceId = id;
132 knownResourceShortIdentifer = shortIdentifer;
133 knownResourceRefName = refName;
136 protected void setKnownItemResource( String id, String shortIdentifer ) {
137 knownItemResourceId = id;
138 knownItemResourceShortIdentifer = shortIdentifer;
142 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
145 protected CollectionSpaceClient getClientInstance() {
146 return new LocationAuthorityClient();
150 protected PoxPayloadOut createInstance(String identifier) {
151 LocationAuthorityClient client = new LocationAuthorityClient();
152 String shortId = identifier;
153 String displayName = "displayName-" + shortId;
155 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
156 PoxPayloadOut multipart =
157 LocationAuthorityClientUtils.createLocationAuthorityInstance(
158 displayName, shortId, client.getCommonPartName());
162 // ---------------------------------------------------------------
163 // CRUD tests : CREATE tests
164 // ---------------------------------------------------------------
167 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
170 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
172 public void create(String testName) throws Exception {
174 if (logger.isDebugEnabled()) {
175 logger.debug(testBanner(testName, CLASS_NAME));
177 // Perform setup, such as initializing the type of service request
178 // (e.g. CREATE, DELETE), its valid and expected status codes, and
179 // its associated HTTP method name (e.g. POST, DELETE).
182 // Submit the request to the service and store the response.
183 LocationAuthorityClient client = new LocationAuthorityClient();
184 String shortId = createIdentifier();
185 String displayName = "displayName-" + shortId;
187 LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
189 PoxPayloadOut multipart =
190 LocationAuthorityClientUtils.createLocationAuthorityInstance(
191 displayName, shortId, client.getCommonPartName());
193 ClientResponse<Response> res = client.create(multipart);
195 int statusCode = res.getStatus();
197 // Check the status code of the response: does it match
198 // the expected response(s)?
201 // Does it fall within the set of valid status codes?
202 // Does it exactly match the expected status code?
203 if(logger.isDebugEnabled()){
204 logger.debug(testName + ": status = " + statusCode);
206 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
207 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
208 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
210 newID = LocationAuthorityClientUtils.extractId(res);
212 res.releaseConnection();
214 // Store the ID returned from the first resource created
215 // for additional tests below.
216 if (knownResourceId == null){
217 setKnownResource( newID, shortId, baseRefName );
218 if (logger.isDebugEnabled()) {
219 logger.debug(testName + ": knownResourceId=" + knownResourceId);
222 // Store the IDs from every resource created by tests,
223 // so they can be deleted after tests have been run.
224 allResourceIdsCreated.add(newID);
230 * @param testName the test name
232 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
233 groups = {"create"}, dependsOnMethods = {"create"})
234 public void createItem(String testName) {
235 if(logger.isDebugEnabled()){
236 logger.debug(testBanner(testName, CLASS_NAME));
239 createItemInAuthority(knownResourceId, knownResourceRefName);
243 * Creates the item in authority.
245 * @param vcsid the vcsid
246 * @param authRefName the auth ref name
249 private String createItemInAuthority(String vcsid, String authRefName) {
251 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
252 if(logger.isDebugEnabled()){
253 logger.debug(testBanner(testName, CLASS_NAME));
256 // Submit the request to the service and store the response.
257 LocationAuthorityClient client = new LocationAuthorityClient();
258 Map<String, String> shelf1Map = new HashMap<String,String>();
259 // TODO Make loc type and status be controlled vocabs.
260 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
261 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
262 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
263 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
264 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
265 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
266 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
267 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
268 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
270 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
271 authRefName, shelf1Map, client );
273 // Store the ID returned from the first item resource created
274 // for additional tests below.
275 if (knownItemResourceId == null){
276 setKnownItemResource(newID, TEST_SHORTID);
277 if (logger.isDebugEnabled()) {
278 logger.debug(testName + ": knownItemResourceId=" + newID);
282 // Store the IDs from any item resources created
283 // by tests, along with the IDs of their parents, so these items
284 // can be deleted after all tests have been run.
285 allItemResourceIdsCreated.put(newID, vcsid);
294 // Placeholders until the three tests below can be uncommented.
295 // See Issue CSPACE-401.
297 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
300 public void createWithEmptyEntityBody(String testName) throws Exception {
304 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
307 public void createWithMalformedXml(String testName) throws Exception {
311 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
314 public void createWithWrongXmlSchema(String testName) throws Exception {
318 // ---------------------------------------------------------------
319 // CRUD tests : CREATE LIST tests
320 // ---------------------------------------------------------------
323 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
326 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
327 groups = {"createList"}, dependsOnGroups = {"create"})
328 public void createList(String testName) throws Exception {
329 for (int i = 0; i < nItemsToCreateInList; i++) {
335 * Creates the item list.
337 * @param testName the test name
338 * @throws Exception the exception
340 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
341 groups = {"createList"}, dependsOnMethods = {"createList"})
342 public void createItemList(String testName) throws Exception {
343 // Add items to the initially-created, known parent record.
344 for (int j = 0; j < nItemsToCreateInList; j++) {
345 createItem(testName);
349 // ---------------------------------------------------------------
350 // CRUD tests : READ tests
351 // ---------------------------------------------------------------
354 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
357 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
358 groups = {"read"}, dependsOnGroups = {"create"})
359 public void read(String testName) throws Exception {
361 if (logger.isDebugEnabled()) {
362 logger.debug(testBanner(testName, CLASS_NAME));
367 // Submit the request to the service and store the response.
368 LocationAuthorityClient client = new LocationAuthorityClient();
370 ClientResponse<String> res = client.read(knownResourceId);
372 int statusCode = res.getStatus();
374 // Check the status code of the response: does it match
375 // the expected response(s)?
376 if(logger.isDebugEnabled()){
377 logger.debug(testName + ": status = " + statusCode);
379 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
380 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
381 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
382 //FIXME: remove the following try catch once Aron fixes signatures
384 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
385 LocationauthoritiesCommon locationAuthority =
386 (LocationauthoritiesCommon) extractPart(input,
387 client.getCommonPartName(), LocationauthoritiesCommon.class);
388 Assert.assertNotNull(locationAuthority);
389 Assert.assertNotNull(locationAuthority.getDisplayName());
390 Assert.assertNotNull(locationAuthority.getShortIdentifier());
391 Assert.assertNotNull(locationAuthority.getRefName());
392 } catch (Exception e) {
393 throw new RuntimeException(e);
396 res.releaseConnection();
403 * @param testName the test name
404 * @throws Exception the exception
406 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
407 groups = {"read"}, dependsOnGroups = {"create"})
408 public void readByName(String testName) throws Exception {
410 if (logger.isDebugEnabled()) {
411 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
416 // Submit the request to the service and store the response.
417 LocationAuthorityClient client = new LocationAuthorityClient();
418 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
420 int statusCode = res.getStatus();
422 // Check the status code of the response: does it match
423 // the expected response(s)?
424 if(logger.isDebugEnabled()){
425 logger.debug(testName + ": status = " + statusCode);
427 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
428 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
429 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
430 //FIXME: remove the following try catch once Aron fixes signatures
432 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
433 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
434 client.getCommonPartName(), LocationauthoritiesCommon.class);
435 Assert.assertNotNull(locationAuthority);
436 } catch (Exception e) {
437 throw new RuntimeException(e);
440 res.releaseConnection();
448 * @param testName the test name
449 * @throws Exception the exception
451 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
452 groups = {"read"}, dependsOnMethods = {"read"})
453 public void readItem(String testName) throws Exception {
455 if (logger.isDebugEnabled()) {
456 logger.debug(testBanner(testName, CLASS_NAME));
461 // Submit the request to the service and store the response.
462 LocationAuthorityClient client = new LocationAuthorityClient();
463 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
465 int statusCode = res.getStatus();
467 // Check the status code of the response: does it match
468 // the expected response(s)?
469 if(logger.isDebugEnabled()){
470 logger.debug(testName + ": status = " + statusCode);
472 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
473 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
474 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
476 // Check whether we've received a location.
477 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
478 LocationsCommon location = (LocationsCommon) extractPart(input,
479 client.getItemCommonPartName(), LocationsCommon.class);
480 Assert.assertNotNull(location);
481 boolean showFull = true;
482 if(showFull && logger.isDebugEnabled()){
483 logger.debug(testName + ": returned payload:");
484 logger.debug(objectAsXmlString(location, LocationsCommon.class));
486 Assert.assertEquals(location.getInAuthority(), knownResourceId);
488 res.releaseConnection();
494 * Verify item display name.
496 * @param testName the test name
497 * @throws Exception the exception
499 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
500 dependsOnMethods = {"readItem", "updateItem"})
501 public void verifyItemDisplayName(String testName) throws Exception {
503 if (logger.isDebugEnabled()) {
504 logger.debug(testBanner(testName, CLASS_NAME));
509 // Submit the request to the service and store the response.
510 LocationAuthorityClient client = new LocationAuthorityClient();
511 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
513 int statusCode = res.getStatus();
515 // Check the status code of the response: does it match
516 // the expected response(s)?
517 if(logger.isDebugEnabled()){
518 logger.debug(testName + ": status = " + statusCode);
520 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
521 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
522 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
524 // Check whether location has expected displayName.
525 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
526 LocationsCommon location = (LocationsCommon) extractPart(input,
527 client.getItemCommonPartName(), LocationsCommon.class);
528 Assert.assertNotNull(location);
529 String displayName = location.getDisplayName();
530 // Make sure displayName matches computed form
531 String expectedDisplayName =
532 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
533 Assert.assertNotNull(displayName, expectedDisplayName);
535 // Update the shortName and verify the computed name is updated.
536 location.setCsid(null);
537 location.setDisplayNameComputed(true);
538 location.setName("updated-" + TEST_NAME);
539 expectedDisplayName =
540 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
542 // Submit the updated resource to the service and store the response.
543 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
544 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
545 commonPart.setLabel(client.getItemCommonPartName());
546 res.releaseConnection();
547 res = client.updateItem(knownResourceId, knownItemResourceId, output);
548 statusCode = res.getStatus();
550 // Check the status code of the response: does it match the expected response(s)?
551 if(logger.isDebugEnabled()){
552 logger.debug("updateItem: status = " + statusCode);
554 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
555 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
556 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
558 // Retrieve the updated resource and verify that its contents exist.
559 input = new PoxPayloadIn(res.getEntity());
560 LocationsCommon updatedLocation =
561 (LocationsCommon) extractPart(input,
562 client.getItemCommonPartName(), LocationsCommon.class);
563 Assert.assertNotNull(updatedLocation);
565 // Verify that the updated resource received the correct data.
566 Assert.assertEquals(updatedLocation.getName(), location.getName(),
567 "Updated ForeName in Location did not match submitted data.");
568 // Verify that the updated resource computes the right displayName.
569 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
570 "Updated ForeName in Location not reflected in computed DisplayName.");
572 // Now Update the displayName, not computed and verify the computed name is overriden.
573 location.setDisplayNameComputed(false);
574 expectedDisplayName = "TestName";
575 location.setDisplayName(expectedDisplayName);
577 // Submit the updated resource to the service and store the response.
578 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
579 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
580 commonPart.setLabel(client.getItemCommonPartName());
581 res.releaseConnection();
582 res = client.updateItem(knownResourceId, knownItemResourceId, output);
583 statusCode = res.getStatus();
585 // Check the status code of the response: does it match the expected response(s)?
586 if(logger.isDebugEnabled()){
587 logger.debug("updateItem: status = " + statusCode);
589 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
590 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
591 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
593 // Retrieve the updated resource and verify that its contents exist.
594 input = new PoxPayloadIn(res.getEntity());
596 (LocationsCommon) extractPart(input,
597 client.getItemCommonPartName(), LocationsCommon.class);
598 Assert.assertNotNull(updatedLocation);
600 // Verify that the updated resource received the correct data.
601 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
602 "Updated displayNameComputed in Location did not match submitted data.");
603 // Verify that the updated resource computes the right displayName.
604 Assert.assertEquals(updatedLocation.getDisplayName(),
606 "Updated DisplayName (not computed) in Location not stored.");
608 res.releaseConnection();
613 * Verify illegal item display name.
615 * @param testName the test name
616 * @throws Exception the exception
618 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
619 dependsOnMethods = {"verifyItemDisplayName"})
620 public void verifyIllegalItemDisplayName(String testName) throws Exception {
622 if (logger.isDebugEnabled()) {
623 logger.debug(testBanner(testName, CLASS_NAME));
626 // FIXME: create a setup configuration for this operation.
627 setupUpdateWithWrongXmlSchema();
629 // Submit the request to the service and store the response.
630 LocationAuthorityClient client = new LocationAuthorityClient();
631 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
633 int statusCode = res.getStatus();
635 // Check the status code of the response: does it match
636 // the expected response(s)?
637 if(logger.isDebugEnabled()){
638 logger.debug(testName + ": status = " + statusCode);
640 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
641 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
642 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
644 // Check whether Location has expected displayName.
645 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
646 LocationsCommon location = (LocationsCommon) extractPart(input,
647 client.getItemCommonPartName(), LocationsCommon.class);
648 Assert.assertNotNull(location);
649 // Try to Update with computed false and no displayName
650 location.setDisplayNameComputed(false);
651 location.setDisplayName(null);
653 // Submit the updated resource to the service and store the response.
654 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
655 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
656 commonPart.setLabel(client.getItemCommonPartName());
657 res.releaseConnection();
658 res = client.updateItem(knownResourceId, knownItemResourceId, output);
659 statusCode = res.getStatus();
661 // Check the status code of the response: does it match the expected response(s)?
662 if(logger.isDebugEnabled()){
663 logger.debug("updateItem: status = " + statusCode);
665 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
666 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
667 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
669 res.releaseConnection();
676 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
679 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
680 groups = {"read"}, dependsOnMethods = {"read"})
681 public void readNonExistent(String testName) {
683 if (logger.isDebugEnabled()) {
684 logger.debug(testBanner(testName, CLASS_NAME));
687 setupReadNonExistent();
689 // Submit the request to the service and store the response.
690 LocationAuthorityClient client = new LocationAuthorityClient();
691 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
693 int statusCode = res.getStatus();
695 // Check the status code of the response: does it match
696 // the expected response(s)?
697 if(logger.isDebugEnabled()){
698 logger.debug(testName + ": status = " + statusCode);
700 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
701 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
702 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
704 res.releaseConnection();
709 * Read item non existent.
711 * @param testName the test name
713 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
714 groups = {"read"}, dependsOnMethods = {"readItem"})
715 public void readItemNonExistent(String testName) {
717 if (logger.isDebugEnabled()) {
718 logger.debug(testBanner(testName, CLASS_NAME));
721 setupReadNonExistent();
723 // Submit the request to the service and store the response.
724 LocationAuthorityClient client = new LocationAuthorityClient();
725 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
727 int statusCode = res.getStatus();
729 // Check the status code of the response: does it match
730 // the expected response(s)?
731 if(logger.isDebugEnabled()){
732 logger.debug(testName + ": status = " + statusCode);
734 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
735 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
736 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
738 res.releaseConnection();
743 // ---------------------------------------------------------------
744 // CRUD tests : READ_LIST tests
745 // ---------------------------------------------------------------
749 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
752 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
753 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
754 public void readList(String testName) throws Exception {
756 if (logger.isDebugEnabled()) {
757 logger.debug(testBanner(testName, CLASS_NAME));
762 // Submit the request to the service and store the response.
763 LocationAuthorityClient client = new LocationAuthorityClient();
764 ClientResponse<AbstractCommonList> res = client.readList();
766 AbstractCommonList list = res.getEntity();
767 int statusCode = res.getStatus();
769 // Check the status code of the response: does it match
770 // the expected response(s)?
771 if(logger.isDebugEnabled()){
772 logger.debug(testName + ": status = " + statusCode);
774 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
775 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
776 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
778 // Optionally output additional data about list members for debugging.
779 if(logger.isTraceEnabled()){
780 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
783 res.releaseConnection();
790 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
791 public void readItemList() {
792 String testName = "readItemList";
793 if (logger.isDebugEnabled()) {
794 logger.debug(testBanner(testName, CLASS_NAME));
796 readItemList(knownResourceId, null);
800 * Read item list by authority name.
802 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
803 public void readItemListByAuthorityName() {
804 String testName = "readItemListByAuthorityName";
805 if (logger.isDebugEnabled()) {
806 logger.debug(testBanner(testName, CLASS_NAME));
808 readItemList(null, knownResourceShortIdentifer);
814 * @param vcsid the vcsid
815 * @param name the name
817 private void readItemList(String vcsid, String shortId) {
819 String testName = "readItemList";
824 // Submit the request to the service and store the response.
825 LocationAuthorityClient client = new LocationAuthorityClient();
826 ClientResponse<AbstractCommonList> res = null;
828 res = client.readItemList(vcsid, null, null);
829 } else if(shortId!= null) {
830 res = client.readItemListForNamedAuthority(shortId, null, null);
832 Assert.fail("readItemList passed null csid and name!");
835 AbstractCommonList list = res.getEntity();
836 int statusCode = res.getStatus();
838 // Check the status code of the response: does it match
839 // the expected response(s)?
840 if(logger.isDebugEnabled()){
841 logger.debug(testName + ": status = " + statusCode);
843 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
844 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
845 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
847 List<AbstractCommonList.ListItem> items =
849 int nItemsReturned = items.size();
850 // There will be one item created, associated with a
851 // known parent resource, by the createItem test.
853 // In addition, there will be 'nItemsToCreateInList'
854 // additional items created by the createItemList test,
855 // all associated with the same parent resource.
856 int nExpectedItems = nItemsToCreateInList + 1;
857 if(logger.isDebugEnabled()){
858 logger.debug(testName + ": Expected "
859 + nExpectedItems +" items; got: "+nItemsReturned);
861 Assert.assertEquals(nItemsReturned, nExpectedItems);
863 for (AbstractCommonList.ListItem item : items) {
865 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
866 Assert.assertTrue((null != value), "Item refName is null!");
868 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
869 Assert.assertTrue((null != value), "Item displayName is null!");
871 if(logger.isTraceEnabled()){
872 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
875 res.releaseConnection();
883 // ---------------------------------------------------------------
884 // CRUD tests : UPDATE tests
885 // ---------------------------------------------------------------
888 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
891 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
892 groups = {"update"}, dependsOnGroups = {"read", "readList"})
893 public void update(String testName) throws Exception {
895 if (logger.isDebugEnabled()) {
896 logger.debug(testBanner(testName, CLASS_NAME));
901 // Retrieve the contents of a resource to update.
902 LocationAuthorityClient client = new LocationAuthorityClient();
903 ClientResponse<String> res = client.read(knownResourceId);
905 if(logger.isDebugEnabled()){
906 logger.debug(testName + ": read status = " + res.getStatus());
908 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
910 if(logger.isDebugEnabled()){
911 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
913 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
914 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
915 client.getCommonPartName(), LocationauthoritiesCommon.class);
916 Assert.assertNotNull(locationAuthority);
918 // Update the contents of this resource.
919 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
920 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
921 if(logger.isDebugEnabled()){
922 logger.debug("to be updated LocationAuthority");
923 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
926 // Submit the updated resource to the service and store the response.
927 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
928 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
929 commonPart.setLabel(client.getCommonPartName());
930 res.releaseConnection();
931 res = client.update(knownResourceId, output);
932 int statusCode = res.getStatus();
934 // Check the status code of the response: does it match the expected response(s)?
935 if(logger.isDebugEnabled()){
936 logger.debug(testName + ": status = " + statusCode);
938 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
939 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
940 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
942 // Retrieve the updated resource and verify that its contents exist.
943 input = new PoxPayloadIn(res.getEntity());
944 LocationauthoritiesCommon updatedLocationAuthority =
945 (LocationauthoritiesCommon) extractPart(input,
946 client.getCommonPartName(), LocationauthoritiesCommon.class);
947 Assert.assertNotNull(updatedLocationAuthority);
949 // Verify that the updated resource received the correct data.
950 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
951 locationAuthority.getDisplayName(),
952 "Data in updated object did not match submitted data.");
954 res.releaseConnection();
961 * @param testName the test name
962 * @throws Exception the exception
964 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
965 groups = {"update"}, dependsOnMethods = {"update"})
966 public void updateItem(String testName) throws Exception {
968 if (logger.isDebugEnabled()) {
969 logger.debug(testBanner(testName, CLASS_NAME));
974 // Retrieve the contents of a resource to update.
975 LocationAuthorityClient client = new LocationAuthorityClient();
976 ClientResponse<String> res =
977 client.readItem(knownResourceId, knownItemResourceId);
979 if(logger.isDebugEnabled()){
980 logger.debug(testName + ": read status = " + res.getStatus());
982 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
984 if(logger.isDebugEnabled()){
985 logger.debug("got Location to update with ID: " +
986 knownItemResourceId +
987 " in LocationAuthority: " + knownResourceId );
989 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
990 LocationsCommon location = (LocationsCommon) extractPart(input,
991 client.getItemCommonPartName(), LocationsCommon.class);
992 Assert.assertNotNull(location);
994 // Update the contents of this resource.
995 location.setCsid(null);
996 location.setName("updated-" + location.getName());
997 if(logger.isDebugEnabled()){
998 logger.debug("to be updated Location");
999 logger.debug(objectAsXmlString(location,
1000 LocationsCommon.class));
1003 // Submit the updated resource to the service and store the response.
1004 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1005 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1006 commonPart.setLabel(client.getItemCommonPartName());
1007 res.releaseConnection();
1008 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1009 int statusCode = res.getStatus();
1011 // Check the status code of the response: does it match the expected response(s)?
1012 if(logger.isDebugEnabled()){
1013 logger.debug(testName + ": status = " + statusCode);
1015 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1016 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1017 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1019 // Retrieve the updated resource and verify that its contents exist.
1020 input = new PoxPayloadIn(res.getEntity());
1021 LocationsCommon updatedLocation =
1022 (LocationsCommon) extractPart(input,
1023 client.getItemCommonPartName(), LocationsCommon.class);
1024 Assert.assertNotNull(updatedLocation);
1026 // Verify that the updated resource received the correct data.
1027 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1028 "Data in updated Location did not match submitted data.");
1030 res.releaseConnection();
1035 // Placeholders until the three tests below can be uncommented.
1036 // See Issue CSPACE-401.
1038 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1041 public void updateWithEmptyEntityBody(String testName) throws Exception {
1045 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1048 public void updateWithMalformedXml(String testName) throws Exception {
1052 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1055 public void updateWithWrongXmlSchema(String testName) throws Exception {
1060 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1063 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1064 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1065 public void updateNonExistent(String testName) throws Exception {
1067 if (logger.isDebugEnabled()) {
1068 logger.debug(testBanner(testName, CLASS_NAME));
1071 setupUpdateNonExistent();
1073 // Submit the request to the service and store the response.
1074 // Note: The ID(s) used when creating the request payload may be arbitrary.
1075 // The only relevant ID may be the one used in update(), below.
1076 LocationAuthorityClient client = new LocationAuthorityClient();
1077 String displayName = "displayName-NON_EXISTENT_ID";
1078 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1079 displayName, "nonEx", client.getCommonPartName());
1080 ClientResponse<String> res =
1081 client.update(NON_EXISTENT_ID, multipart);
1083 int statusCode = res.getStatus();
1085 // Check the status code of the response: does it match
1086 // the expected response(s)?
1087 if(logger.isDebugEnabled()){
1088 logger.debug(testName + ": status = " + statusCode);
1090 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1091 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1092 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1094 res.releaseConnection();
1099 * Update non existent item.
1101 * @param testName the test name
1102 * @throws Exception the exception
1104 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1105 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1106 public void updateNonExistentItem(String testName) throws Exception {
1108 if (logger.isDebugEnabled()) {
1109 logger.debug(testBanner(testName, CLASS_NAME));
1112 setupUpdateNonExistent();
1114 // Submit the request to the service and store the response.
1115 // Note: The ID used in this 'create' call may be arbitrary.
1116 // The only relevant ID may be the one used in update(), below.
1117 LocationAuthorityClient client = new LocationAuthorityClient();
1118 Map<String, String> nonexMap = new HashMap<String,String>();
1119 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1120 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1121 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1122 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1123 PoxPayloadOut multipart =
1124 LocationAuthorityClientUtils.createLocationInstance(
1125 LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1126 nonexMap, client.getItemCommonPartName() );
1127 ClientResponse<String> res =
1128 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1130 int statusCode = res.getStatus();
1132 // Check the status code of the response: does it match
1133 // the expected response(s)?
1134 if(logger.isDebugEnabled()){
1135 logger.debug(testName + ": status = " + statusCode);
1137 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1138 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1139 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1141 res.releaseConnection();
1145 // ---------------------------------------------------------------
1146 // CRUD tests : DELETE tests
1147 // ---------------------------------------------------------------
1150 // Note: delete sub-resources in ascending hierarchical order,
1151 // before deleting their parents.
1156 * @param testName the test name
1157 * @throws Exception the exception
1159 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1160 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1161 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1162 public void deleteItem(String testName) throws Exception {
1164 if (logger.isDebugEnabled()) {
1165 logger.debug(testBanner(testName, CLASS_NAME));
1170 if(logger.isDebugEnabled()){
1171 logger.debug("parentcsid =" + knownResourceId +
1172 " itemcsid = " + knownItemResourceId);
1175 // Submit the request to the service and store the response.
1176 LocationAuthorityClient client = new LocationAuthorityClient();
1177 ClientResponse<Response> res =
1178 client.deleteItem(knownResourceId, knownItemResourceId);
1180 int statusCode = res.getStatus();
1182 // Check the status code of the response: does it match
1183 // the expected response(s)?
1184 if(logger.isDebugEnabled()){
1185 logger.debug(testName + ": status = " + statusCode);
1187 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1188 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1189 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1191 res.releaseConnection();
1196 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1199 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1200 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1201 public void delete(String testName) throws Exception {
1203 if (logger.isDebugEnabled()) {
1204 logger.debug(testBanner(testName, CLASS_NAME));
1209 if(logger.isDebugEnabled()){
1210 logger.debug("parentcsid =" + knownResourceId);
1213 // Submit the request to the service and store the response.
1214 LocationAuthorityClient client = new LocationAuthorityClient();
1215 ClientResponse<Response> res = client.delete(knownResourceId);
1217 int statusCode = res.getStatus();
1219 // Check the status code of the response: does it match
1220 // the expected response(s)?
1221 if(logger.isDebugEnabled()){
1222 logger.debug(testName + ": status = " + statusCode);
1224 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1225 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1226 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1228 res.releaseConnection();
1234 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1237 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1238 groups = {"delete"}, dependsOnMethods = {"delete"})
1239 public void deleteNonExistent(String testName) throws Exception {
1241 if (logger.isDebugEnabled()) {
1242 logger.debug(testBanner(testName, CLASS_NAME));
1245 setupDeleteNonExistent();
1247 // Submit the request to the service and store the response.
1248 LocationAuthorityClient client = new LocationAuthorityClient();
1249 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1251 int statusCode = res.getStatus();
1253 // Check the status code of the response: does it match
1254 // the expected response(s)?
1255 if(logger.isDebugEnabled()){
1256 logger.debug(testName + ": status = " + statusCode);
1258 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1259 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1260 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1262 res.releaseConnection();
1267 * Delete non existent item.
1269 * @param testName the test name
1271 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1272 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1273 public void deleteNonExistentItem(String testName) {
1275 if (logger.isDebugEnabled()) {
1276 logger.debug(testBanner(testName, CLASS_NAME));
1279 setupDeleteNonExistent();
1281 // Submit the request to the service and store the response.
1282 LocationAuthorityClient client = new LocationAuthorityClient();
1283 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1285 int statusCode = res.getStatus();
1287 // Check the status code of the response: does it match
1288 // the expected response(s)?
1289 if(logger.isDebugEnabled()){
1290 logger.debug(testName + ": status = " + statusCode);
1292 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1293 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1294 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1296 res.releaseConnection();
1300 // ---------------------------------------------------------------
1301 // Utility tests : tests of code used in tests above
1302 // ---------------------------------------------------------------
1304 * Tests the code for manually submitting data that is used by several
1305 * of the methods above.
1307 @Test(dependsOnMethods = {"create", "read"})
1308 public void testSubmitRequest() {
1310 // Expected status code: 200 OK
1311 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1313 // Submit the request to the service and store the response.
1314 String method = ServiceRequestType.READ.httpMethodName();
1315 String url = getResourceURL(knownResourceId);
1316 int statusCode = submitRequest(method, url);
1318 // Check the status code of the response: does it match
1319 // the expected response(s)?
1320 if(logger.isDebugEnabled()){
1321 logger.debug("testSubmitRequest: url=" + url +
1322 " status=" + statusCode);
1324 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1329 * Test item submit request.
1331 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1332 public void testItemSubmitRequest() {
1334 // Expected status code: 200 OK
1335 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1337 // Submit the request to the service and store the response.
1338 String method = ServiceRequestType.READ.httpMethodName();
1339 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1340 int statusCode = submitRequest(method, url);
1342 // Check the status code of the response: does it match
1343 // the expected response(s)?
1344 if(logger.isDebugEnabled()){
1345 logger.debug("testItemSubmitRequest: url=" + url +
1346 " status=" + statusCode);
1348 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1352 // ---------------------------------------------------------------
1353 // Cleanup of resources created during testing
1354 // ---------------------------------------------------------------
1357 * Deletes all resources created by tests, after all tests have been run.
1359 * This cleanup method will always be run, even if one or more tests fail.
1360 * For this reason, it attempts to remove all resources created
1361 * at any point during testing, even if some of those resources
1362 * may be expected to be deleted by certain tests.
1365 @AfterClass(alwaysRun=true)
1366 public void cleanUp() {
1367 String noTest = System.getProperty("noTestCleanup");
1368 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1369 if (logger.isDebugEnabled()) {
1370 logger.debug("Skipping Cleanup phase ...");
1374 if (logger.isDebugEnabled()) {
1375 logger.debug("Cleaning up temporary resources created for testing ...");
1377 String parentResourceId;
1378 String itemResourceId;
1379 // Clean up contact resources.
1380 LocationAuthorityClient client = new LocationAuthorityClient();
1381 parentResourceId = knownResourceId;
1382 // Clean up item resources.
1383 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1384 itemResourceId = entry.getKey();
1385 parentResourceId = entry.getValue();
1386 // Note: Any non-success responses from the delete operation
1387 // below are ignored and not reported.
1388 ClientResponse<Response> res =
1389 client.deleteItem(parentResourceId, itemResourceId);
1390 res.releaseConnection();
1392 // Clean up parent resources.
1393 for (String resourceId : allResourceIdsCreated) {
1394 // Note: Any non-success responses from the delete operation
1395 // below are ignored and not reported.
1396 ClientResponse<Response> res = client.delete(resourceId);
1397 res.releaseConnection();
1401 // ---------------------------------------------------------------
1402 // Utility methods used by tests above
1403 // ---------------------------------------------------------------
1405 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1409 * Returns the root URL for the item service.
1411 * This URL consists of a base URL for all services, followed by
1412 * a path component for the owning parent, followed by the
1413 * path component for the items.
1415 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1416 * parent authority resource of the relevant item resource.
1418 * @return The root URL for the item service.
1420 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1421 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1425 * Returns the URL of a specific item resource managed by a service, and
1426 * designated by an identifier (such as a universally unique ID, or UUID).
1428 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1429 * parent authority resource of the relevant item resource.
1431 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1434 * @return The URL of a specific item resource managed by a service.
1436 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1437 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;