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;
150 // String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
151 PoxPayloadOut multipart =
152 LocationAuthorityClientUtils.createLocationAuthorityInstance(
153 displayName, shortId, client.getCommonPartName());
157 // ---------------------------------------------------------------
158 // CRUD tests : CREATE tests
159 // ---------------------------------------------------------------
162 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
165 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
167 public void create(String testName) throws Exception {
169 if (logger.isDebugEnabled()) {
170 logger.debug(testBanner(testName, CLASS_NAME));
172 // Perform setup, such as initializing the type of service request
173 // (e.g. CREATE, DELETE), its valid and expected status codes, and
174 // its associated HTTP method name (e.g. POST, DELETE).
177 // Submit the request to the service and store the response.
178 LocationAuthorityClient client = new LocationAuthorityClient();
179 String shortId = createIdentifier();
180 String displayName = "displayName-" + shortId;
181 // String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
183 PoxPayloadOut multipart =
184 LocationAuthorityClientUtils.createLocationAuthorityInstance(
185 displayName, shortId, client.getCommonPartName());
187 ClientResponse<Response> res = client.create(multipart);
189 int statusCode = res.getStatus();
191 // Check the status code of the response: does it match
192 // the expected response(s)?
195 // Does it fall within the set of valid status codes?
196 // Does it exactly match the expected status code?
197 if(logger.isDebugEnabled()){
198 logger.debug(testName + ": status = " + statusCode);
200 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
201 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
202 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
204 newID = LocationAuthorityClientUtils.extractId(res);
206 res.releaseConnection();
208 // Store the ID returned from the first resource created
209 // for additional tests below.
210 final String EMPTY_REFNAME = "";
211 if (knownResourceId == null){
212 setKnownResource( newID, shortId, EMPTY_REFNAME );
213 if (logger.isDebugEnabled()) {
214 logger.debug(testName + ": knownResourceId=" + knownResourceId);
217 // Store the IDs from every resource created by tests,
218 // so they can be deleted after tests have been run.
219 allResourceIdsCreated.add(newID);
225 * @param testName the test name
227 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
228 groups = {"create"}, dependsOnMethods = {"create"})
229 public void createItem(String testName) {
230 if(logger.isDebugEnabled()){
231 logger.debug(testBanner(testName, CLASS_NAME));
234 createItemInAuthority(knownResourceId, knownResourceRefName);
238 * Creates the item in authority.
240 * @param vcsid the vcsid
241 * @param authRefName the auth ref name
244 private String createItemInAuthority(String vcsid, String authRefName) {
246 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
247 if(logger.isDebugEnabled()){
248 logger.debug(testBanner(testName, CLASS_NAME));
251 // Submit the request to the service and store the response.
252 LocationAuthorityClient client = new LocationAuthorityClient();
253 Map<String, String> shelf1Map = new HashMap<String,String>();
254 // TODO Make loc type and status be controlled vocabs.
255 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
256 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
257 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
258 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
259 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
260 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
261 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
262 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
263 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
265 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
266 authRefName, shelf1Map, client );
268 // Store the ID returned from the first item resource created
269 // for additional tests below.
270 if (knownItemResourceId == null){
271 setKnownItemResource(newID, TEST_SHORTID);
272 if (logger.isDebugEnabled()) {
273 logger.debug(testName + ": knownItemResourceId=" + newID);
277 // Store the IDs from any item resources created
278 // by tests, along with the IDs of their parents, so these items
279 // can be deleted after all tests have been run.
280 allItemResourceIdsCreated.put(newID, vcsid);
289 // Placeholders until the three tests below can be uncommented.
290 // See Issue CSPACE-401.
292 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
295 public void createWithEmptyEntityBody(String testName) throws Exception {
299 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
302 public void createWithMalformedXml(String testName) throws Exception {
306 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
309 public void createWithWrongXmlSchema(String testName) throws Exception {
313 // ---------------------------------------------------------------
314 // CRUD tests : CREATE LIST tests
315 // ---------------------------------------------------------------
318 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
321 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
322 groups = {"createList"}, dependsOnGroups = {"create"})
323 public void createList(String testName) throws Exception {
324 for (int i = 0; i < nItemsToCreateInList; i++) {
330 * Creates the item list.
332 * @param testName the test name
333 * @throws Exception the exception
335 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
336 groups = {"createList"}, dependsOnMethods = {"createList"})
337 public void createItemList(String testName) throws Exception {
338 // Add items to the initially-created, known parent record.
339 for (int j = 0; j < nItemsToCreateInList; j++) {
340 createItem(testName);
344 // ---------------------------------------------------------------
345 // CRUD tests : READ tests
346 // ---------------------------------------------------------------
349 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
352 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
353 groups = {"read"}, dependsOnGroups = {"create"})
354 public void read(String testName) throws Exception {
356 if (logger.isDebugEnabled()) {
357 logger.debug(testBanner(testName, CLASS_NAME));
362 // Submit the request to the service and store the response.
363 LocationAuthorityClient client = new LocationAuthorityClient();
365 ClientResponse<String> res = client.read(knownResourceId);
367 int statusCode = res.getStatus();
369 // Check the status code of the response: does it match
370 // the expected response(s)?
371 if(logger.isDebugEnabled()){
372 logger.debug(testName + ": status = " + statusCode);
374 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
375 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
376 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
377 //FIXME: remove the following try catch once Aron fixes signatures
379 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
380 LocationauthoritiesCommon locationAuthority =
381 (LocationauthoritiesCommon) extractPart(input,
382 client.getCommonPartName(), LocationauthoritiesCommon.class);
383 Assert.assertNotNull(locationAuthority);
384 Assert.assertNotNull(locationAuthority.getDisplayName());
385 Assert.assertNotNull(locationAuthority.getShortIdentifier());
386 Assert.assertNotNull(locationAuthority.getRefName());
387 } catch (Exception e) {
388 throw new RuntimeException(e);
391 res.releaseConnection();
398 * @param testName the test name
399 * @throws Exception the exception
401 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
402 groups = {"read"}, dependsOnGroups = {"create"})
403 public void readByName(String testName) throws Exception {
405 if (logger.isDebugEnabled()) {
406 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
411 // Submit the request to the service and store the response.
412 LocationAuthorityClient client = new LocationAuthorityClient();
413 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
415 int statusCode = res.getStatus();
417 // Check the status code of the response: does it match
418 // the expected response(s)?
419 if(logger.isDebugEnabled()){
420 logger.debug(testName + ": status = " + statusCode);
422 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
423 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
424 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
425 //FIXME: remove the following try catch once Aron fixes signatures
427 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
428 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
429 client.getCommonPartName(), LocationauthoritiesCommon.class);
430 Assert.assertNotNull(locationAuthority);
431 } catch (Exception e) {
432 throw new RuntimeException(e);
435 res.releaseConnection();
443 * @param testName the test name
444 * @throws Exception the exception
446 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
447 groups = {"read"}, dependsOnMethods = {"read"})
448 public void readItem(String testName) throws Exception {
450 if (logger.isDebugEnabled()) {
451 logger.debug(testBanner(testName, CLASS_NAME));
456 // Submit the request to the service and store the response.
457 LocationAuthorityClient client = new LocationAuthorityClient();
458 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
460 int statusCode = res.getStatus();
462 // Check the status code of the response: does it match
463 // the expected response(s)?
464 if(logger.isDebugEnabled()){
465 logger.debug(testName + ": status = " + statusCode);
467 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
468 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
469 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
471 // Check whether we've received a location.
472 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
473 LocationsCommon location = (LocationsCommon) extractPart(input,
474 client.getItemCommonPartName(), LocationsCommon.class);
475 Assert.assertNotNull(location);
476 boolean showFull = true;
477 if(showFull && logger.isDebugEnabled()){
478 logger.debug(testName + ": returned payload:");
479 logger.debug(objectAsXmlString(location, LocationsCommon.class));
481 Assert.assertEquals(location.getInAuthority(), knownResourceId);
483 res.releaseConnection();
489 * Verify item display name.
491 * @param testName the test name
492 * @throws Exception the exception
494 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
495 dependsOnMethods = {"readItem", "updateItem"})
496 public void verifyItemDisplayName(String testName) throws Exception {
498 if (logger.isDebugEnabled()) {
499 logger.debug(testBanner(testName, CLASS_NAME));
504 // Submit the request to the service and store the response.
505 LocationAuthorityClient client = new LocationAuthorityClient();
506 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
508 int statusCode = res.getStatus();
510 // Check the status code of the response: does it match
511 // the expected response(s)?
512 if(logger.isDebugEnabled()){
513 logger.debug(testName + ": status = " + statusCode);
515 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
516 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
517 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
519 // Check whether location has expected displayName.
520 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
521 LocationsCommon location = (LocationsCommon) extractPart(input,
522 client.getItemCommonPartName(), LocationsCommon.class);
523 Assert.assertNotNull(location);
524 String displayName = location.getDisplayName();
525 // Make sure displayName matches computed form
526 String expectedDisplayName =
527 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
528 Assert.assertNotNull(displayName, expectedDisplayName);
530 // Update the shortName and verify the computed name is updated.
531 location.setCsid(null);
532 location.setDisplayNameComputed(true);
533 location.setName("updated-" + TEST_NAME);
534 expectedDisplayName =
535 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
537 // Submit the updated resource to the service and store the response.
538 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
539 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
540 commonPart.setLabel(client.getItemCommonPartName());
541 res.releaseConnection();
542 res = client.updateItem(knownResourceId, knownItemResourceId, output);
543 statusCode = res.getStatus();
545 // Check the status code of the response: does it match the expected response(s)?
546 if(logger.isDebugEnabled()){
547 logger.debug("updateItem: status = " + statusCode);
549 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
550 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
551 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
553 // Retrieve the updated resource and verify that its contents exist.
554 input = new PoxPayloadIn(res.getEntity());
555 LocationsCommon updatedLocation =
556 (LocationsCommon) extractPart(input,
557 client.getItemCommonPartName(), LocationsCommon.class);
558 Assert.assertNotNull(updatedLocation);
560 // Verify that the updated resource received the correct data.
561 Assert.assertEquals(updatedLocation.getName(), location.getName(),
562 "Updated ForeName in Location did not match submitted data.");
563 // Verify that the updated resource computes the right displayName.
564 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
565 "Updated ForeName in Location not reflected in computed DisplayName.");
567 // Now Update the displayName, not computed and verify the computed name is overriden.
568 location.setDisplayNameComputed(false);
569 expectedDisplayName = "TestName";
570 location.setDisplayName(expectedDisplayName);
572 // Submit the updated resource to the service and store the response.
573 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
574 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
575 commonPart.setLabel(client.getItemCommonPartName());
576 res.releaseConnection();
577 res = client.updateItem(knownResourceId, knownItemResourceId, output);
578 statusCode = res.getStatus();
580 // Check the status code of the response: does it match the expected response(s)?
581 if(logger.isDebugEnabled()){
582 logger.debug("updateItem: status = " + statusCode);
584 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
585 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
586 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
588 // Retrieve the updated resource and verify that its contents exist.
589 input = new PoxPayloadIn(res.getEntity());
591 (LocationsCommon) extractPart(input,
592 client.getItemCommonPartName(), LocationsCommon.class);
593 Assert.assertNotNull(updatedLocation);
595 // Verify that the updated resource received the correct data.
596 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
597 "Updated displayNameComputed in Location did not match submitted data.");
598 // Verify that the updated resource computes the right displayName.
599 Assert.assertEquals(updatedLocation.getDisplayName(),
601 "Updated DisplayName (not computed) in Location not stored.");
603 res.releaseConnection();
608 * Verify illegal item display name.
610 * @param testName the test name
611 * @throws Exception the exception
613 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
614 dependsOnMethods = {"verifyItemDisplayName"})
615 public void verifyIllegalItemDisplayName(String testName) throws Exception {
617 if (logger.isDebugEnabled()) {
618 logger.debug(testBanner(testName, CLASS_NAME));
621 // FIXME: create a setup configuration for this operation.
622 setupUpdateWithWrongXmlSchema();
624 // Submit the request to the service and store the response.
625 LocationAuthorityClient client = new LocationAuthorityClient();
626 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
628 int statusCode = res.getStatus();
630 // Check the status code of the response: does it match
631 // the expected response(s)?
632 if(logger.isDebugEnabled()){
633 logger.debug(testName + ": status = " + statusCode);
635 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
636 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
637 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
639 // Check whether Location has expected displayName.
640 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
641 LocationsCommon location = (LocationsCommon) extractPart(input,
642 client.getItemCommonPartName(), LocationsCommon.class);
643 Assert.assertNotNull(location);
644 // Try to Update with computed false and no displayName
645 location.setDisplayNameComputed(false);
646 location.setDisplayName(null);
648 // Submit the updated resource to the service and store the response.
649 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
650 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
651 commonPart.setLabel(client.getItemCommonPartName());
652 res.releaseConnection();
653 res = client.updateItem(knownResourceId, knownItemResourceId, output);
654 statusCode = res.getStatus();
656 // Check the status code of the response: does it match the expected response(s)?
657 if(logger.isDebugEnabled()){
658 logger.debug("updateItem: status = " + statusCode);
660 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
661 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
662 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
664 res.releaseConnection();
671 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
674 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
675 groups = {"read"}, dependsOnMethods = {"read"})
676 public void readNonExistent(String testName) {
678 if (logger.isDebugEnabled()) {
679 logger.debug(testBanner(testName, CLASS_NAME));
682 setupReadNonExistent();
684 // Submit the request to the service and store the response.
685 LocationAuthorityClient client = new LocationAuthorityClient();
686 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
688 int statusCode = res.getStatus();
690 // Check the status code of the response: does it match
691 // the expected response(s)?
692 if(logger.isDebugEnabled()){
693 logger.debug(testName + ": status = " + statusCode);
695 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
696 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
697 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
699 res.releaseConnection();
704 * Read item non existent.
706 * @param testName the test name
708 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
709 groups = {"read"}, dependsOnMethods = {"readItem"})
710 public void readItemNonExistent(String testName) {
712 if (logger.isDebugEnabled()) {
713 logger.debug(testBanner(testName, CLASS_NAME));
716 setupReadNonExistent();
718 // Submit the request to the service and store the response.
719 LocationAuthorityClient client = new LocationAuthorityClient();
720 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
722 int statusCode = res.getStatus();
724 // Check the status code of the response: does it match
725 // the expected response(s)?
726 if(logger.isDebugEnabled()){
727 logger.debug(testName + ": status = " + statusCode);
729 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
730 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
731 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
733 res.releaseConnection();
738 // ---------------------------------------------------------------
739 // CRUD tests : READ_LIST tests
740 // ---------------------------------------------------------------
744 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
747 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
748 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
749 public void readList(String testName) throws Exception {
751 if (logger.isDebugEnabled()) {
752 logger.debug(testBanner(testName, CLASS_NAME));
757 // Submit the request to the service and store the response.
758 LocationAuthorityClient client = new LocationAuthorityClient();
759 ClientResponse<AbstractCommonList> res = client.readList();
761 AbstractCommonList list = res.getEntity();
762 int statusCode = res.getStatus();
764 // Check the status code of the response: does it match
765 // the expected response(s)?
766 if(logger.isDebugEnabled()){
767 logger.debug(testName + ": status = " + statusCode);
769 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
770 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
771 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
773 // Optionally output additional data about list members for debugging.
774 if(logger.isTraceEnabled()){
775 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
778 res.releaseConnection();
785 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
786 public void readItemList() {
787 String testName = "readItemList";
788 if (logger.isDebugEnabled()) {
789 logger.debug(testBanner(testName, CLASS_NAME));
791 readItemList(knownResourceId, null);
795 * Read item list by authority name.
797 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
798 public void readItemListByAuthorityName() {
799 String testName = "readItemListByAuthorityName";
800 if (logger.isDebugEnabled()) {
801 logger.debug(testBanner(testName, CLASS_NAME));
803 readItemList(null, knownResourceShortIdentifer);
809 * @param vcsid the vcsid
810 * @param name the name
812 private void readItemList(String vcsid, String shortId) {
814 String testName = "readItemList";
819 // Submit the request to the service and store the response.
820 LocationAuthorityClient client = new LocationAuthorityClient();
821 ClientResponse<AbstractCommonList> res = null;
823 res = client.readItemList(vcsid, null, null);
824 } else if(shortId!= null) {
825 res = client.readItemListForNamedAuthority(shortId, null, null);
827 Assert.fail("readItemList passed null csid and name!");
830 AbstractCommonList list = res.getEntity();
831 int statusCode = res.getStatus();
833 // Check the status code of the response: does it match
834 // the expected response(s)?
835 if(logger.isDebugEnabled()){
836 logger.debug(testName + ": status = " + statusCode);
838 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
839 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
840 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
842 List<AbstractCommonList.ListItem> items =
844 int nItemsReturned = items.size();
845 // There will be one item created, associated with a
846 // known parent resource, by the createItem test.
848 // In addition, there will be 'nItemsToCreateInList'
849 // additional items created by the createItemList test,
850 // all associated with the same parent resource.
851 int nExpectedItems = nItemsToCreateInList + 1;
852 if(logger.isDebugEnabled()){
853 logger.debug(testName + ": Expected "
854 + nExpectedItems +" items; got: "+nItemsReturned);
856 Assert.assertEquals(nItemsReturned, nExpectedItems);
858 for (AbstractCommonList.ListItem item : items) {
860 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
861 Assert.assertTrue((null != value), "Item refName is null!");
863 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
864 Assert.assertTrue((null != value), "Item displayName is null!");
866 if(logger.isTraceEnabled()){
867 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
870 res.releaseConnection();
878 // ---------------------------------------------------------------
879 // CRUD tests : UPDATE tests
880 // ---------------------------------------------------------------
883 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
886 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
887 groups = {"update"}, dependsOnGroups = {"read", "readList"})
888 public void update(String testName) throws Exception {
890 if (logger.isDebugEnabled()) {
891 logger.debug(testBanner(testName, CLASS_NAME));
896 // Retrieve the contents of a resource to update.
897 LocationAuthorityClient client = new LocationAuthorityClient();
898 ClientResponse<String> res = client.read(knownResourceId);
900 if(logger.isDebugEnabled()){
901 logger.debug(testName + ": read status = " + res.getStatus());
903 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
905 if(logger.isDebugEnabled()){
906 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
908 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
909 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
910 client.getCommonPartName(), LocationauthoritiesCommon.class);
911 Assert.assertNotNull(locationAuthority);
913 // Update the contents of this resource.
914 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
915 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
916 if(logger.isDebugEnabled()){
917 logger.debug("to be updated LocationAuthority");
918 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
921 // Submit the updated resource to the service and store the response.
922 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
923 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
924 commonPart.setLabel(client.getCommonPartName());
925 res.releaseConnection();
926 res = client.update(knownResourceId, output);
927 int statusCode = res.getStatus();
929 // Check the status code of the response: does it match the expected response(s)?
930 if(logger.isDebugEnabled()){
931 logger.debug(testName + ": status = " + statusCode);
933 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
934 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
935 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
937 // Retrieve the updated resource and verify that its contents exist.
938 input = new PoxPayloadIn(res.getEntity());
939 LocationauthoritiesCommon updatedLocationAuthority =
940 (LocationauthoritiesCommon) extractPart(input,
941 client.getCommonPartName(), LocationauthoritiesCommon.class);
942 Assert.assertNotNull(updatedLocationAuthority);
944 // Verify that the updated resource received the correct data.
945 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
946 locationAuthority.getDisplayName(),
947 "Data in updated object did not match submitted data.");
949 res.releaseConnection();
956 * @param testName the test name
957 * @throws Exception the exception
959 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
960 groups = {"update"}, dependsOnMethods = {"update"})
961 public void updateItem(String testName) throws Exception {
963 if (logger.isDebugEnabled()) {
964 logger.debug(testBanner(testName, CLASS_NAME));
969 // Retrieve the contents of a resource to update.
970 LocationAuthorityClient client = new LocationAuthorityClient();
971 ClientResponse<String> res =
972 client.readItem(knownResourceId, knownItemResourceId);
974 if(logger.isDebugEnabled()){
975 logger.debug(testName + ": read status = " + res.getStatus());
977 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
979 if(logger.isDebugEnabled()){
980 logger.debug("got Location to update with ID: " +
981 knownItemResourceId +
982 " in LocationAuthority: " + knownResourceId );
984 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
985 LocationsCommon location = (LocationsCommon) extractPart(input,
986 client.getItemCommonPartName(), LocationsCommon.class);
987 Assert.assertNotNull(location);
989 // Update the contents of this resource.
990 location.setCsid(null);
991 location.setName("updated-" + location.getName());
992 if(logger.isDebugEnabled()){
993 logger.debug("to be updated Location");
994 logger.debug(objectAsXmlString(location,
995 LocationsCommon.class));
998 // Submit the updated resource to the service and store the response.
999 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1000 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1001 commonPart.setLabel(client.getItemCommonPartName());
1002 res.releaseConnection();
1003 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1004 int statusCode = res.getStatus();
1006 // Check the status code of the response: does it match the expected response(s)?
1007 if(logger.isDebugEnabled()){
1008 logger.debug(testName + ": status = " + statusCode);
1010 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1011 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1012 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1014 // Retrieve the updated resource and verify that its contents exist.
1015 input = new PoxPayloadIn(res.getEntity());
1016 LocationsCommon updatedLocation =
1017 (LocationsCommon) extractPart(input,
1018 client.getItemCommonPartName(), LocationsCommon.class);
1019 Assert.assertNotNull(updatedLocation);
1021 // Verify that the updated resource received the correct data.
1022 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1023 "Data in updated Location did not match submitted data.");
1025 res.releaseConnection();
1030 // Placeholders until the three tests below can be uncommented.
1031 // See Issue CSPACE-401.
1033 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1036 public void updateWithEmptyEntityBody(String testName) throws Exception {
1040 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1043 public void updateWithMalformedXml(String testName) throws Exception {
1047 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1050 public void updateWithWrongXmlSchema(String testName) throws Exception {
1055 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1058 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1059 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1060 public void updateNonExistent(String testName) throws Exception {
1062 if (logger.isDebugEnabled()) {
1063 logger.debug(testBanner(testName, CLASS_NAME));
1066 setupUpdateNonExistent();
1068 // Submit the request to the service and store the response.
1069 // Note: The ID(s) used when creating the request payload may be arbitrary.
1070 // The only relevant ID may be the one used in update(), below.
1071 LocationAuthorityClient client = new LocationAuthorityClient();
1072 String displayName = "displayName-NON_EXISTENT_ID";
1073 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1074 displayName, "nonEx", client.getCommonPartName());
1075 ClientResponse<String> res =
1076 client.update(NON_EXISTENT_ID, multipart);
1078 int statusCode = res.getStatus();
1080 // Check the status code of the response: does it match
1081 // the expected response(s)?
1082 if(logger.isDebugEnabled()){
1083 logger.debug(testName + ": status = " + statusCode);
1085 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1086 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1087 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1089 res.releaseConnection();
1094 * Update non existent item.
1096 * @param testName the test name
1097 * @throws Exception the exception
1099 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1100 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1101 public void updateNonExistentItem(String testName) throws Exception {
1103 if (logger.isDebugEnabled()) {
1104 logger.debug(testBanner(testName, CLASS_NAME));
1107 setupUpdateNonExistent();
1109 // Submit the request to the service and store the response.
1110 // Note: The ID used in this 'create' call may be arbitrary.
1111 // The only relevant ID may be the one used in update(), below.
1112 LocationAuthorityClient client = new LocationAuthorityClient();
1113 Map<String, String> nonexMap = new HashMap<String,String>();
1114 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1115 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1116 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1117 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1118 // PoxPayloadOut multipart =
1119 // LocationAuthorityClientUtils.createLocationInstance(
1120 // LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1121 // nonexMap, client.getItemCommonPartName() );
1122 final String EMPTY_REFNAME = "";
1123 PoxPayloadOut multipart =
1124 LocationAuthorityClientUtils.createLocationInstance(EMPTY_REFNAME,
1125 nonexMap, client.getItemCommonPartName() );
1126 ClientResponse<String> res =
1127 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1129 int statusCode = res.getStatus();
1131 // Check the status code of the response: does it match
1132 // the expected response(s)?
1133 if(logger.isDebugEnabled()){
1134 logger.debug(testName + ": status = " + statusCode);
1136 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1137 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1138 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1140 res.releaseConnection();
1144 // ---------------------------------------------------------------
1145 // CRUD tests : DELETE tests
1146 // ---------------------------------------------------------------
1149 // Note: delete sub-resources in ascending hierarchical order,
1150 // before deleting their parents.
1155 * @param testName the test name
1156 * @throws Exception the exception
1158 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1159 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1160 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1161 public void deleteItem(String testName) throws Exception {
1163 if (logger.isDebugEnabled()) {
1164 logger.debug(testBanner(testName, CLASS_NAME));
1169 if(logger.isDebugEnabled()){
1170 logger.debug("parentcsid =" + knownResourceId +
1171 " itemcsid = " + knownItemResourceId);
1174 // Submit the request to the service and store the response.
1175 LocationAuthorityClient client = new LocationAuthorityClient();
1176 ClientResponse<Response> res =
1177 client.deleteItem(knownResourceId, knownItemResourceId);
1179 int statusCode = res.getStatus();
1181 // Check the status code of the response: does it match
1182 // the expected response(s)?
1183 if(logger.isDebugEnabled()){
1184 logger.debug(testName + ": status = " + statusCode);
1186 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1187 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1188 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1190 res.releaseConnection();
1195 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1198 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1199 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1200 public void delete(String testName) throws Exception {
1202 if (logger.isDebugEnabled()) {
1203 logger.debug(testBanner(testName, CLASS_NAME));
1208 if(logger.isDebugEnabled()){
1209 logger.debug("parentcsid =" + knownResourceId);
1212 // Submit the request to the service and store the response.
1213 LocationAuthorityClient client = new LocationAuthorityClient();
1214 ClientResponse<Response> res = client.delete(knownResourceId);
1216 int statusCode = res.getStatus();
1218 // Check the status code of the response: does it match
1219 // the expected response(s)?
1220 if(logger.isDebugEnabled()){
1221 logger.debug(testName + ": status = " + statusCode);
1223 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1224 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1225 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1227 res.releaseConnection();
1233 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1236 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1237 groups = {"delete"}, dependsOnMethods = {"delete"})
1238 public void deleteNonExistent(String testName) throws Exception {
1240 if (logger.isDebugEnabled()) {
1241 logger.debug(testBanner(testName, CLASS_NAME));
1244 setupDeleteNonExistent();
1246 // Submit the request to the service and store the response.
1247 LocationAuthorityClient client = new LocationAuthorityClient();
1248 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1250 int statusCode = res.getStatus();
1252 // Check the status code of the response: does it match
1253 // the expected response(s)?
1254 if(logger.isDebugEnabled()){
1255 logger.debug(testName + ": status = " + statusCode);
1257 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1258 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1259 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1261 res.releaseConnection();
1266 * Delete non existent item.
1268 * @param testName the test name
1270 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1271 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1272 public void deleteNonExistentItem(String testName) {
1274 if (logger.isDebugEnabled()) {
1275 logger.debug(testBanner(testName, CLASS_NAME));
1278 setupDeleteNonExistent();
1280 // Submit the request to the service and store the response.
1281 LocationAuthorityClient client = new LocationAuthorityClient();
1282 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1284 int statusCode = res.getStatus();
1286 // Check the status code of the response: does it match
1287 // the expected response(s)?
1288 if(logger.isDebugEnabled()){
1289 logger.debug(testName + ": status = " + statusCode);
1291 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1292 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1293 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1295 res.releaseConnection();
1299 // ---------------------------------------------------------------
1300 // Utility tests : tests of code used in tests above
1301 // ---------------------------------------------------------------
1303 * Tests the code for manually submitting data that is used by several
1304 * of the methods above.
1306 @Test(dependsOnMethods = {"create", "read"})
1307 public void testSubmitRequest() {
1309 // Expected status code: 200 OK
1310 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1312 // Submit the request to the service and store the response.
1313 String method = ServiceRequestType.READ.httpMethodName();
1314 String url = getResourceURL(knownResourceId);
1315 int statusCode = submitRequest(method, url);
1317 // Check the status code of the response: does it match
1318 // the expected response(s)?
1319 if(logger.isDebugEnabled()){
1320 logger.debug("testSubmitRequest: url=" + url +
1321 " status=" + statusCode);
1323 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1328 * Test item submit request.
1330 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1331 public void testItemSubmitRequest() {
1333 // Expected status code: 200 OK
1334 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1336 // Submit the request to the service and store the response.
1337 String method = ServiceRequestType.READ.httpMethodName();
1338 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1339 int statusCode = submitRequest(method, url);
1341 // Check the status code of the response: does it match
1342 // the expected response(s)?
1343 if(logger.isDebugEnabled()){
1344 logger.debug("testItemSubmitRequest: url=" + url +
1345 " status=" + statusCode);
1347 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1351 // ---------------------------------------------------------------
1352 // Cleanup of resources created during testing
1353 // ---------------------------------------------------------------
1356 * Deletes all resources created by tests, after all tests have been run.
1358 * This cleanup method will always be run, even if one or more tests fail.
1359 * For this reason, it attempts to remove all resources created
1360 * at any point during testing, even if some of those resources
1361 * may be expected to be deleted by certain tests.
1364 @AfterClass(alwaysRun=true)
1365 public void cleanUp() {
1366 String noTest = System.getProperty("noTestCleanup");
1367 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1368 if (logger.isDebugEnabled()) {
1369 logger.debug("Skipping Cleanup phase ...");
1373 if (logger.isDebugEnabled()) {
1374 logger.debug("Cleaning up temporary resources created for testing ...");
1376 String parentResourceId;
1377 String itemResourceId;
1378 // Clean up contact resources.
1379 LocationAuthorityClient client = new LocationAuthorityClient();
1380 parentResourceId = knownResourceId;
1381 // Clean up item resources.
1382 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1383 itemResourceId = entry.getKey();
1384 parentResourceId = entry.getValue();
1385 // Note: Any non-success responses from the delete operation
1386 // below are ignored and not reported.
1387 ClientResponse<Response> res =
1388 client.deleteItem(parentResourceId, itemResourceId);
1389 res.releaseConnection();
1391 // Clean up parent resources.
1392 for (String resourceId : allResourceIdsCreated) {
1393 // Note: Any non-success responses from the delete operation
1394 // below are ignored and not reported.
1395 ClientResponse<Response> res = client.delete(resourceId);
1396 res.releaseConnection();
1400 // ---------------------------------------------------------------
1401 // Utility methods used by tests above
1402 // ---------------------------------------------------------------
1404 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1408 * Returns the root URL for the item service.
1410 * This URL consists of a base URL for all services, followed by
1411 * a path component for the owning parent, followed by the
1412 * path component for the items.
1414 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1415 * parent authority resource of the relevant item resource.
1417 * @return The root URL for the item service.
1419 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1420 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1424 * Returns the URL of a specific item resource managed by a service, and
1425 * designated by an identifier (such as a universally unique ID, or UUID).
1427 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1428 * parent authority resource of the relevant item resource.
1430 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1433 * @return The URL of a specific item resource managed by a service.
1435 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1436 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;