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.common.datetime.GregorianCalendarDateTimeUtils;
38 import org.collectionspace.services.client.LocationAuthorityClient;
39 import org.collectionspace.services.client.LocationAuthorityClientUtils;
40 import org.collectionspace.services.jaxb.AbstractCommonList;
41 import org.collectionspace.services.location.LocationauthoritiesCommon;
42 import org.collectionspace.services.location.LocationsCommon;
44 import javax.ws.rs.core.MediaType;
45 import javax.ws.rs.core.Response;
46 import org.jboss.resteasy.client.ClientResponse;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
51 import org.testng.Assert;
52 import org.testng.annotations.AfterClass;
53 import org.testng.annotations.Test;
56 * LocationAuthorityServiceTest, carries out tests against a
57 * deployed and running LocationAuthority Service.
59 * $LastChangedRevision: 753 $
60 * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $
62 public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { //FIXME: Test classes for Vocab, Person, Org, and Location should have a base class!
65 private final String CLASS_NAME = LocationAuthorityServiceTest.class.getName();
66 private final Logger logger = LoggerFactory.getLogger(LocationAuthorityServiceTest.class);
67 private final String REFNAME = "refName";
68 private final String DISPLAYNAME = "displayName";
69 private final static String CURRENT_DATE_UTC =
70 GregorianCalendarDateTimeUtils.currentDateUTC();
73 public String getServicePathComponent() {
74 return LocationAuthorityClient.SERVICE_PATH_COMPONENT;
78 protected String getServiceName() {
79 return LocationAuthorityClient.SERVICE_NAME;
82 public String getItemServicePathComponent() {
83 return AuthorityClient.ITEMS;
86 // Instance variables specific to this test.
88 // /** The SERVICE path component. */
89 // final String SERVICE_PATH_COMPONENT = "locationauthorities";
91 // /** The ITEM service path component. */
92 // final String ITEM_SERVICE_PATH_COMPONENT = "items";
94 // /** The CONTACT service path component. */
95 // final String CONTACT_SERVICE_PATH_COMPONENT = "contacts";
97 final String TEST_NAME = "Shelf 1";
98 final String TEST_SHORTID = "shelf1";
99 final String TEST_CONDITION_NOTE = "Basically clean";
100 final String TEST_CONDITION_NOTE_DATE = CURRENT_DATE_UTC;
101 final String TEST_SECURITY_NOTE = "Kind of safe";
102 final String TEST_ACCESS_NOTE = "Only right-thinkers may see";
103 final String TEST_ADDRESS = "123 Main Street, Anytown USA";
104 // TODO Make loc type be a controlled vocab term.
105 final String TEST_LOCATION_TYPE = "Shelf";
106 // TODO Make status type be a controlled vocab term.
107 final String TEST_STATUS = "Approved";
109 /** The known resource id. */
110 private String knownResourceId = null;
111 private String knownResourceShortIdentifer = null;
112 private String knownResourceRefName = null;
113 private String knownLocationTypeRefName = null;
114 private String knownItemResourceId = null;
115 private String knownItemResourceShortIdentifer = null;
116 private String knownContactResourceId = null;
118 /** The n items to create in list. */
119 private int nItemsToCreateInList = 3;
121 /** The all resource ids created. */
122 private List<String> allResourceIdsCreated = new ArrayList<String>();
124 /** The all item resource ids created. */
125 private Map<String, String> allItemResourceIdsCreated =
126 new HashMap<String, String>();
128 protected void setKnownResource( String id, String shortIdentifer,
130 knownResourceId = id;
131 knownResourceShortIdentifer = shortIdentifer;
132 knownResourceRefName = refName;
135 protected void setKnownItemResource( String id, String shortIdentifer ) {
136 knownItemResourceId = id;
137 knownItemResourceShortIdentifer = shortIdentifer;
141 * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance()
144 protected CollectionSpaceClient getClientInstance() {
145 return new LocationAuthorityClient();
149 protected PoxPayloadOut createInstance(String identifier) {
150 LocationAuthorityClient client = new LocationAuthorityClient();
151 String shortId = identifier;
152 String displayName = "displayName-" + shortId;
153 // String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
154 PoxPayloadOut multipart =
155 LocationAuthorityClientUtils.createLocationAuthorityInstance(
156 displayName, shortId, client.getCommonPartName());
160 // ---------------------------------------------------------------
161 // CRUD tests : CREATE tests
162 // ---------------------------------------------------------------
165 * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
168 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
170 public void create(String testName) throws Exception {
172 if (logger.isDebugEnabled()) {
173 logger.debug(testBanner(testName, CLASS_NAME));
175 // Perform setup, such as initializing the type of service request
176 // (e.g. CREATE, DELETE), its valid and expected status codes, and
177 // its associated HTTP method name (e.g. POST, DELETE).
180 // Submit the request to the service and store the response.
181 LocationAuthorityClient client = new LocationAuthorityClient();
182 String shortId = createIdentifier();
183 String displayName = "displayName-" + shortId;
184 // String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(shortId, null);
186 PoxPayloadOut multipart =
187 LocationAuthorityClientUtils.createLocationAuthorityInstance(
188 displayName, shortId, client.getCommonPartName());
190 ClientResponse<Response> res = client.create(multipart);
192 int statusCode = res.getStatus();
194 // Check the status code of the response: does it match
195 // the expected response(s)?
198 // Does it fall within the set of valid status codes?
199 // Does it exactly match the expected status code?
200 if(logger.isDebugEnabled()){
201 logger.debug(testName + ": status = " + statusCode);
203 Assert.assertTrue(this.REQUEST_TYPE.isValidStatusCode(statusCode),
204 invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode));
205 Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE);
207 newID = LocationAuthorityClientUtils.extractId(res);
209 res.releaseConnection();
211 // Store the ID returned from the first resource created
212 // for additional tests below.
213 final String EMPTY_REFNAME = "";
214 if (knownResourceId == null){
215 setKnownResource( newID, shortId, EMPTY_REFNAME );
216 if (logger.isDebugEnabled()) {
217 logger.debug(testName + ": knownResourceId=" + knownResourceId);
220 // Store the IDs from every resource created by tests,
221 // so they can be deleted after tests have been run.
222 allResourceIdsCreated.add(newID);
228 * @param testName the test name
230 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
231 groups = {"create"}, dependsOnMethods = {"create"})
232 public void createItem(String testName) {
233 if(logger.isDebugEnabled()){
234 logger.debug(testBanner(testName, CLASS_NAME));
237 createItemInAuthority(knownResourceId, knownResourceRefName);
241 * Creates the item in authority.
243 * @param vcsid the vcsid
244 * @param authRefName the auth ref name
247 private String createItemInAuthority(String vcsid, String authRefName) {
249 final String testName = "createItemInAuthority("+vcsid+","+authRefName+")";
250 if(logger.isDebugEnabled()){
251 logger.debug(testBanner(testName, CLASS_NAME));
254 // Submit the request to the service and store the response.
255 LocationAuthorityClient client = new LocationAuthorityClient();
256 Map<String, String> shelf1Map = new HashMap<String,String>();
257 // TODO Make loc type and status be controlled vocabs.
258 shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME);
259 shelf1Map.put(LocationJAXBSchema.SHORT_IDENTIFIER, TEST_SHORTID);
260 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE);
261 shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE);
262 shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE);
263 shelf1Map.put(LocationJAXBSchema.ACCESS_NOTE, TEST_ACCESS_NOTE);
264 shelf1Map.put(LocationJAXBSchema.ADDRESS, TEST_ADDRESS);
265 shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
266 shelf1Map.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
268 String newID = LocationAuthorityClientUtils.createItemInAuthority(vcsid,
269 authRefName, shelf1Map, client );
271 // Store the ID returned from the first item resource created
272 // for additional tests below.
273 if (knownItemResourceId == null){
274 setKnownItemResource(newID, TEST_SHORTID);
275 if (logger.isDebugEnabled()) {
276 logger.debug(testName + ": knownItemResourceId=" + newID);
280 // Store the IDs from any item resources created
281 // by tests, along with the IDs of their parents, so these items
282 // can be deleted after all tests have been run.
283 allItemResourceIdsCreated.put(newID, vcsid);
292 // Placeholders until the three tests below can be uncommented.
293 // See Issue CSPACE-401.
295 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String)
298 public void createWithEmptyEntityBody(String testName) throws Exception {
302 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String)
305 public void createWithMalformedXml(String testName) throws Exception {
309 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String)
312 public void createWithWrongXmlSchema(String testName) throws Exception {
316 // ---------------------------------------------------------------
317 // CRUD tests : CREATE LIST tests
318 // ---------------------------------------------------------------
321 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String)
324 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
325 groups = {"createList"}, dependsOnGroups = {"create"})
326 public void createList(String testName) throws Exception {
327 for (int i = 0; i < nItemsToCreateInList; i++) {
333 * Creates the item list.
335 * @param testName the test name
336 * @throws Exception the exception
338 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
339 groups = {"createList"}, dependsOnMethods = {"createList"})
340 public void createItemList(String testName) throws Exception {
341 // Add items to the initially-created, known parent record.
342 for (int j = 0; j < nItemsToCreateInList; j++) {
343 createItem(testName);
347 // ---------------------------------------------------------------
348 // CRUD tests : READ tests
349 // ---------------------------------------------------------------
352 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
355 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
356 groups = {"read"}, dependsOnGroups = {"create"})
357 public void read(String testName) throws Exception {
359 if (logger.isDebugEnabled()) {
360 logger.debug(testBanner(testName, CLASS_NAME));
365 // Submit the request to the service and store the response.
366 LocationAuthorityClient client = new LocationAuthorityClient();
368 ClientResponse<String> res = client.read(knownResourceId);
370 int statusCode = res.getStatus();
372 // Check the status code of the response: does it match
373 // the expected response(s)?
374 if(logger.isDebugEnabled()){
375 logger.debug(testName + ": status = " + statusCode);
377 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
378 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
379 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
380 //FIXME: remove the following try catch once Aron fixes signatures
382 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
383 LocationauthoritiesCommon locationAuthority =
384 (LocationauthoritiesCommon) extractPart(input,
385 client.getCommonPartName(), LocationauthoritiesCommon.class);
386 Assert.assertNotNull(locationAuthority);
387 Assert.assertNotNull(locationAuthority.getDisplayName());
388 Assert.assertNotNull(locationAuthority.getShortIdentifier());
389 Assert.assertNotNull(locationAuthority.getRefName());
390 } catch (Exception e) {
391 throw new RuntimeException(e);
394 res.releaseConnection();
401 * @param testName the test name
402 * @throws Exception the exception
404 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
405 groups = {"read"}, dependsOnGroups = {"create"})
406 public void readByName(String testName) throws Exception {
408 if (logger.isDebugEnabled()) {
409 logger.debug(testBanner(testName+"("+knownResourceShortIdentifer+")", CLASS_NAME));
414 // Submit the request to the service and store the response.
415 LocationAuthorityClient client = new LocationAuthorityClient();
416 ClientResponse<String> res = client.readByName(knownResourceShortIdentifer);
418 int statusCode = res.getStatus();
420 // Check the status code of the response: does it match
421 // the expected response(s)?
422 if(logger.isDebugEnabled()){
423 logger.debug(testName + ": status = " + statusCode);
425 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
426 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
427 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
428 //FIXME: remove the following try catch once Aron fixes signatures
430 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
431 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
432 client.getCommonPartName(), LocationauthoritiesCommon.class);
433 Assert.assertNotNull(locationAuthority);
434 } catch (Exception e) {
435 throw new RuntimeException(e);
438 res.releaseConnection();
446 * @param testName the test name
447 * @throws Exception the exception
449 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
450 groups = {"read"}, dependsOnMethods = {"read"})
451 public void readItem(String testName) throws Exception {
453 if (logger.isDebugEnabled()) {
454 logger.debug(testBanner(testName, CLASS_NAME));
459 // Submit the request to the service and store the response.
460 LocationAuthorityClient client = new LocationAuthorityClient();
461 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
463 int statusCode = res.getStatus();
465 // Check the status code of the response: does it match
466 // the expected response(s)?
467 if(logger.isDebugEnabled()){
468 logger.debug(testName + ": status = " + statusCode);
470 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
471 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
472 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
474 // Check whether we've received a location.
475 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
476 LocationsCommon location = (LocationsCommon) extractPart(input,
477 client.getItemCommonPartName(), LocationsCommon.class);
478 Assert.assertNotNull(location);
479 boolean showFull = true;
480 if(showFull && logger.isDebugEnabled()){
481 logger.debug(testName + ": returned payload:");
482 logger.debug(objectAsXmlString(location, LocationsCommon.class));
484 Assert.assertEquals(location.getInAuthority(), knownResourceId);
486 res.releaseConnection();
492 * Verify item display name.
494 * @param testName the test name
495 * @throws Exception the exception
497 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
498 dependsOnMethods = {"readItem", "updateItem"})
499 public void verifyItemDisplayName(String testName) throws Exception {
501 if (logger.isDebugEnabled()) {
502 logger.debug(testBanner(testName, CLASS_NAME));
507 // Submit the request to the service and store the response.
508 LocationAuthorityClient client = new LocationAuthorityClient();
509 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
511 int statusCode = res.getStatus();
513 // Check the status code of the response: does it match
514 // the expected response(s)?
515 if(logger.isDebugEnabled()){
516 logger.debug(testName + ": status = " + statusCode);
518 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
519 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
520 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
522 // Check whether location has expected displayName.
523 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
524 LocationsCommon location = (LocationsCommon) extractPart(input,
525 client.getItemCommonPartName(), LocationsCommon.class);
526 Assert.assertNotNull(location);
527 String displayName = location.getDisplayName();
528 // Make sure displayName matches computed form
529 String expectedDisplayName =
530 LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME);
531 Assert.assertNotNull(displayName, expectedDisplayName);
533 // Update the shortName and verify the computed name is updated.
534 location.setCsid(null);
535 location.setDisplayNameComputed(true);
536 location.setName("updated-" + TEST_NAME);
537 expectedDisplayName =
538 LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME);
540 // Submit the updated resource to the service and store the response.
541 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
542 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
543 commonPart.setLabel(client.getItemCommonPartName());
544 res.releaseConnection();
545 res = client.updateItem(knownResourceId, knownItemResourceId, output);
546 statusCode = res.getStatus();
548 // Check the status code of the response: does it match the expected response(s)?
549 if(logger.isDebugEnabled()){
550 logger.debug("updateItem: status = " + statusCode);
552 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
553 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
554 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
556 // Retrieve the updated resource and verify that its contents exist.
557 input = new PoxPayloadIn(res.getEntity());
558 LocationsCommon updatedLocation =
559 (LocationsCommon) extractPart(input,
560 client.getItemCommonPartName(), LocationsCommon.class);
561 Assert.assertNotNull(updatedLocation);
563 // Verify that the updated resource received the correct data.
564 Assert.assertEquals(updatedLocation.getName(), location.getName(),
565 "Updated ForeName in Location did not match submitted data.");
566 // Verify that the updated resource computes the right displayName.
567 Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName,
568 "Updated ForeName in Location not reflected in computed DisplayName.");
570 // Now Update the displayName, not computed and verify the computed name is overriden.
571 location.setDisplayNameComputed(false);
572 expectedDisplayName = "TestName";
573 location.setDisplayName(expectedDisplayName);
575 // Submit the updated resource to the service and store the response.
576 output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
577 commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
578 commonPart.setLabel(client.getItemCommonPartName());
579 res.releaseConnection();
580 res = client.updateItem(knownResourceId, knownItemResourceId, output);
581 statusCode = res.getStatus();
583 // Check the status code of the response: does it match the expected response(s)?
584 if(logger.isDebugEnabled()){
585 logger.debug("updateItem: status = " + statusCode);
587 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
588 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
589 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
591 // Retrieve the updated resource and verify that its contents exist.
592 input = new PoxPayloadIn(res.getEntity());
594 (LocationsCommon) extractPart(input,
595 client.getItemCommonPartName(), LocationsCommon.class);
596 Assert.assertNotNull(updatedLocation);
598 // Verify that the updated resource received the correct data.
599 Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false,
600 "Updated displayNameComputed in Location did not match submitted data.");
601 // Verify that the updated resource computes the right displayName.
602 Assert.assertEquals(updatedLocation.getDisplayName(),
604 "Updated DisplayName (not computed) in Location not stored.");
606 res.releaseConnection();
611 * Verify illegal item display name.
613 * @param testName the test name
614 * @throws Exception the exception
616 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
617 dependsOnMethods = {"verifyItemDisplayName"})
618 public void verifyIllegalItemDisplayName(String testName) throws Exception {
620 if (logger.isDebugEnabled()) {
621 logger.debug(testBanner(testName, CLASS_NAME));
624 // FIXME: create a setup configuration for this operation.
625 setupUpdateWithWrongXmlSchema();
627 // Submit the request to the service and store the response.
628 LocationAuthorityClient client = new LocationAuthorityClient();
629 ClientResponse<String> res = client.readItem(knownResourceId, knownItemResourceId);
631 int statusCode = res.getStatus();
633 // Check the status code of the response: does it match
634 // the expected response(s)?
635 if(logger.isDebugEnabled()){
636 logger.debug(testName + ": status = " + statusCode);
638 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
639 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
640 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
642 // Check whether Location has expected displayName.
643 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
644 LocationsCommon location = (LocationsCommon) extractPart(input,
645 client.getItemCommonPartName(), LocationsCommon.class);
646 Assert.assertNotNull(location);
647 // Try to Update with computed false and no displayName
648 location.setDisplayNameComputed(false);
649 location.setDisplayName(null);
651 // Submit the updated resource to the service and store the response.
652 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
653 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
654 commonPart.setLabel(client.getItemCommonPartName());
655 res.releaseConnection();
656 res = client.updateItem(knownResourceId, knownItemResourceId, output);
657 statusCode = res.getStatus();
659 // Check the status code of the response: does it match the expected response(s)?
660 if(logger.isDebugEnabled()){
661 logger.debug("updateItem: status = " + statusCode);
663 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
664 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
665 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
667 res.releaseConnection();
674 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String)
677 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
678 groups = {"read"}, dependsOnMethods = {"read"})
679 public void readNonExistent(String testName) {
681 if (logger.isDebugEnabled()) {
682 logger.debug(testBanner(testName, CLASS_NAME));
685 setupReadNonExistent();
687 // Submit the request to the service and store the response.
688 LocationAuthorityClient client = new LocationAuthorityClient();
689 ClientResponse<String> res = client.read(NON_EXISTENT_ID);
691 int statusCode = res.getStatus();
693 // Check the status code of the response: does it match
694 // the expected response(s)?
695 if(logger.isDebugEnabled()){
696 logger.debug(testName + ": status = " + statusCode);
698 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
699 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
700 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
702 res.releaseConnection();
707 * Read item non existent.
709 * @param testName the test name
711 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
712 groups = {"read"}, dependsOnMethods = {"readItem"})
713 public void readItemNonExistent(String testName) {
715 if (logger.isDebugEnabled()) {
716 logger.debug(testBanner(testName, CLASS_NAME));
719 setupReadNonExistent();
721 // Submit the request to the service and store the response.
722 LocationAuthorityClient client = new LocationAuthorityClient();
723 ClientResponse<String> res = client.readItem(knownResourceId, NON_EXISTENT_ID);
725 int statusCode = res.getStatus();
727 // Check the status code of the response: does it match
728 // the expected response(s)?
729 if(logger.isDebugEnabled()){
730 logger.debug(testName + ": status = " + statusCode);
732 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
733 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
734 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
736 res.releaseConnection();
741 // ---------------------------------------------------------------
742 // CRUD tests : READ_LIST tests
743 // ---------------------------------------------------------------
747 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
750 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
751 groups = {"readList"}, dependsOnGroups = {"createList", "read"})
752 public void readList(String testName) throws Exception {
754 if (logger.isDebugEnabled()) {
755 logger.debug(testBanner(testName, CLASS_NAME));
760 // Submit the request to the service and store the response.
761 LocationAuthorityClient client = new LocationAuthorityClient();
762 ClientResponse<AbstractCommonList> res = client.readList();
764 AbstractCommonList list = res.getEntity();
765 int statusCode = res.getStatus();
767 // Check the status code of the response: does it match
768 // the expected response(s)?
769 if(logger.isDebugEnabled()){
770 logger.debug(testName + ": status = " + statusCode);
772 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
773 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
774 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
776 // Optionally output additional data about list members for debugging.
777 if(logger.isTraceEnabled()){
778 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
781 res.releaseConnection();
788 @Test(groups = {"readList"}, dependsOnMethods = {"readList"})
789 public void readItemList() {
790 String testName = "readItemList";
791 if (logger.isDebugEnabled()) {
792 logger.debug(testBanner(testName, CLASS_NAME));
794 readItemList(knownResourceId, null);
798 * Read item list by authority name.
800 @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"})
801 public void readItemListByAuthorityName() {
802 String testName = "readItemListByAuthorityName";
803 if (logger.isDebugEnabled()) {
804 logger.debug(testBanner(testName, CLASS_NAME));
806 readItemList(null, knownResourceShortIdentifer);
812 * @param vcsid the vcsid
813 * @param name the name
815 private void readItemList(String vcsid, String shortId) {
817 String testName = "readItemList";
822 // Submit the request to the service and store the response.
823 LocationAuthorityClient client = new LocationAuthorityClient();
824 ClientResponse<AbstractCommonList> res = null;
826 res = client.readItemList(vcsid, null, null);
827 } else if(shortId!= null) {
828 res = client.readItemListForNamedAuthority(shortId, null, null);
830 Assert.fail("readItemList passed null csid and name!");
833 AbstractCommonList list = res.getEntity();
834 int statusCode = res.getStatus();
836 // Check the status code of the response: does it match
837 // the expected response(s)?
838 if(logger.isDebugEnabled()){
839 logger.debug(testName + ": status = " + statusCode);
841 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
842 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
843 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
845 List<AbstractCommonList.ListItem> items =
847 int nItemsReturned = items.size();
848 // There will be one item created, associated with a
849 // known parent resource, by the createItem test.
851 // In addition, there will be 'nItemsToCreateInList'
852 // additional items created by the createItemList test,
853 // all associated with the same parent resource.
854 int nExpectedItems = nItemsToCreateInList + 1;
855 if(logger.isDebugEnabled()){
856 logger.debug(testName + ": Expected "
857 + nExpectedItems +" items; got: "+nItemsReturned);
859 Assert.assertEquals(nItemsReturned, nExpectedItems);
861 for (AbstractCommonList.ListItem item : items) {
863 AbstractCommonListUtils.ListItemGetElementValue(item, REFNAME);
864 Assert.assertTrue((null != value), "Item refName is null!");
866 AbstractCommonListUtils.ListItemGetElementValue(item, DISPLAYNAME);
867 Assert.assertTrue((null != value), "Item displayName is null!");
869 if(logger.isTraceEnabled()){
870 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
873 res.releaseConnection();
881 // ---------------------------------------------------------------
882 // CRUD tests : UPDATE tests
883 // ---------------------------------------------------------------
886 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
889 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
890 groups = {"update"}, dependsOnGroups = {"read", "readList"})
891 public void update(String testName) throws Exception {
893 if (logger.isDebugEnabled()) {
894 logger.debug(testBanner(testName, CLASS_NAME));
899 // Retrieve the contents of a resource to update.
900 LocationAuthorityClient client = new LocationAuthorityClient();
901 ClientResponse<String> res = client.read(knownResourceId);
903 if(logger.isDebugEnabled()){
904 logger.debug(testName + ": read status = " + res.getStatus());
906 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
908 if(logger.isDebugEnabled()){
909 logger.debug("got LocationAuthority to update with ID: " + knownResourceId);
911 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
912 LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input,
913 client.getCommonPartName(), LocationauthoritiesCommon.class);
914 Assert.assertNotNull(locationAuthority);
916 // Update the contents of this resource.
917 locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName());
918 locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType());
919 if(logger.isDebugEnabled()){
920 logger.debug("to be updated LocationAuthority");
921 logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class));
924 // Submit the updated resource to the service and store the response.
925 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_PAYLOAD_NAME);
926 PayloadOutputPart commonPart = output.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE);
927 commonPart.setLabel(client.getCommonPartName());
928 res.releaseConnection();
929 res = client.update(knownResourceId, output);
930 int statusCode = res.getStatus();
932 // Check the status code of the response: does it match the expected response(s)?
933 if(logger.isDebugEnabled()){
934 logger.debug(testName + ": status = " + statusCode);
936 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
937 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
938 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
940 // Retrieve the updated resource and verify that its contents exist.
941 input = new PoxPayloadIn(res.getEntity());
942 LocationauthoritiesCommon updatedLocationAuthority =
943 (LocationauthoritiesCommon) extractPart(input,
944 client.getCommonPartName(), LocationauthoritiesCommon.class);
945 Assert.assertNotNull(updatedLocationAuthority);
947 // Verify that the updated resource received the correct data.
948 Assert.assertEquals(updatedLocationAuthority.getDisplayName(),
949 locationAuthority.getDisplayName(),
950 "Data in updated object did not match submitted data.");
952 res.releaseConnection();
959 * @param testName the test name
960 * @throws Exception the exception
962 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
963 groups = {"update"}, dependsOnMethods = {"update"})
964 public void updateItem(String testName) throws Exception {
966 if (logger.isDebugEnabled()) {
967 logger.debug(testBanner(testName, CLASS_NAME));
972 // Retrieve the contents of a resource to update.
973 LocationAuthorityClient client = new LocationAuthorityClient();
974 ClientResponse<String> res =
975 client.readItem(knownResourceId, knownItemResourceId);
977 if(logger.isDebugEnabled()){
978 logger.debug(testName + ": read status = " + res.getStatus());
980 Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE);
982 if(logger.isDebugEnabled()){
983 logger.debug("got Location to update with ID: " +
984 knownItemResourceId +
985 " in LocationAuthority: " + knownResourceId );
987 PoxPayloadIn input = new PoxPayloadIn(res.getEntity());
988 LocationsCommon location = (LocationsCommon) extractPart(input,
989 client.getItemCommonPartName(), LocationsCommon.class);
990 Assert.assertNotNull(location);
992 // Update the contents of this resource.
993 location.setCsid(null);
994 location.setName("updated-" + location.getName());
995 if(logger.isDebugEnabled()){
996 logger.debug("to be updated Location");
997 logger.debug(objectAsXmlString(location,
998 LocationsCommon.class));
1001 // Submit the updated resource to the service and store the response.
1002 PoxPayloadOut output = new PoxPayloadOut(LocationAuthorityClient.SERVICE_ITEM_PAYLOAD_NAME);
1003 PayloadOutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE);
1004 commonPart.setLabel(client.getItemCommonPartName());
1005 res.releaseConnection();
1006 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1007 int statusCode = res.getStatus();
1009 // Check the status code of the response: does it match the expected response(s)?
1010 if(logger.isDebugEnabled()){
1011 logger.debug(testName + ": status = " + statusCode);
1013 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1014 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1015 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1017 // Retrieve the updated resource and verify that its contents exist.
1018 input = new PoxPayloadIn(res.getEntity());
1019 LocationsCommon updatedLocation =
1020 (LocationsCommon) extractPart(input,
1021 client.getItemCommonPartName(), LocationsCommon.class);
1022 Assert.assertNotNull(updatedLocation);
1024 // Verify that the updated resource received the correct data.
1025 Assert.assertEquals(updatedLocation.getName(), location.getName(),
1026 "Data in updated Location did not match submitted data.");
1028 res.releaseConnection();
1033 // Placeholders until the three tests below can be uncommented.
1034 // See Issue CSPACE-401.
1036 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String)
1039 public void updateWithEmptyEntityBody(String testName) throws Exception {
1043 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String)
1046 public void updateWithMalformedXml(String testName) throws Exception {
1050 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String)
1053 public void updateWithWrongXmlSchema(String testName) throws Exception {
1058 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String)
1061 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1062 groups = {"update"}, dependsOnMethods = {"update", "testSubmitRequest"})
1063 public void updateNonExistent(String testName) throws Exception {
1065 if (logger.isDebugEnabled()) {
1066 logger.debug(testBanner(testName, CLASS_NAME));
1069 setupUpdateNonExistent();
1071 // Submit the request to the service and store the response.
1072 // Note: The ID(s) used when creating the request payload may be arbitrary.
1073 // The only relevant ID may be the one used in update(), below.
1074 LocationAuthorityClient client = new LocationAuthorityClient();
1075 String displayName = "displayName-NON_EXISTENT_ID";
1076 PoxPayloadOut multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance(
1077 displayName, "nonEx", client.getCommonPartName());
1078 ClientResponse<String> res =
1079 client.update(NON_EXISTENT_ID, multipart);
1081 int statusCode = res.getStatus();
1083 // Check the status code of the response: does it match
1084 // the expected response(s)?
1085 if(logger.isDebugEnabled()){
1086 logger.debug(testName + ": status = " + statusCode);
1088 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1089 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1090 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1092 res.releaseConnection();
1097 * Update non existent item.
1099 * @param testName the test name
1100 * @throws Exception the exception
1102 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1103 groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"})
1104 public void updateNonExistentItem(String testName) throws Exception {
1106 if (logger.isDebugEnabled()) {
1107 logger.debug(testBanner(testName, CLASS_NAME));
1110 setupUpdateNonExistent();
1112 // Submit the request to the service and store the response.
1113 // Note: The ID used in this 'create' call may be arbitrary.
1114 // The only relevant ID may be the one used in update(), below.
1115 LocationAuthorityClient client = new LocationAuthorityClient();
1116 Map<String, String> nonexMap = new HashMap<String,String>();
1117 nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME);
1118 nonexMap.put(LocationJAXBSchema.SHORT_IDENTIFIER, "nonEx");
1119 nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE);
1120 nonexMap.put(LocationJAXBSchema.TERM_STATUS, TEST_STATUS);
1121 // PoxPayloadOut multipart =
1122 // LocationAuthorityClientUtils.createLocationInstance(
1123 // LocationAuthorityClientUtils.createLocationRefName(knownResourceRefName, "nonEx", "Non Existent"),
1124 // nonexMap, client.getItemCommonPartName() );
1125 final String EMPTY_REFNAME = "";
1126 PoxPayloadOut multipart =
1127 LocationAuthorityClientUtils.createLocationInstance(EMPTY_REFNAME,
1128 nonexMap, client.getItemCommonPartName() );
1129 ClientResponse<String> res =
1130 client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1132 int statusCode = res.getStatus();
1134 // Check the status code of the response: does it match
1135 // the expected response(s)?
1136 if(logger.isDebugEnabled()){
1137 logger.debug(testName + ": status = " + statusCode);
1139 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1140 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1141 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1143 res.releaseConnection();
1147 // ---------------------------------------------------------------
1148 // CRUD tests : DELETE tests
1149 // ---------------------------------------------------------------
1152 // Note: delete sub-resources in ascending hierarchical order,
1153 // before deleting their parents.
1158 * @param testName the test name
1159 * @throws Exception the exception
1161 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1162 //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"})
1163 groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"})
1164 public void deleteItem(String testName) throws Exception {
1166 if (logger.isDebugEnabled()) {
1167 logger.debug(testBanner(testName, CLASS_NAME));
1172 if(logger.isDebugEnabled()){
1173 logger.debug("parentcsid =" + knownResourceId +
1174 " itemcsid = " + knownItemResourceId);
1177 // Submit the request to the service and store the response.
1178 LocationAuthorityClient client = new LocationAuthorityClient();
1179 ClientResponse<Response> res =
1180 client.deleteItem(knownResourceId, knownItemResourceId);
1182 int statusCode = res.getStatus();
1184 // Check the status code of the response: does it match
1185 // the expected response(s)?
1186 if(logger.isDebugEnabled()){
1187 logger.debug(testName + ": status = " + statusCode);
1189 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1190 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1191 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1193 res.releaseConnection();
1198 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String)
1201 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1202 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1203 public void delete(String testName) throws Exception {
1205 if (logger.isDebugEnabled()) {
1206 logger.debug(testBanner(testName, CLASS_NAME));
1211 if(logger.isDebugEnabled()){
1212 logger.debug("parentcsid =" + knownResourceId);
1215 // Submit the request to the service and store the response.
1216 LocationAuthorityClient client = new LocationAuthorityClient();
1217 ClientResponse<Response> res = client.delete(knownResourceId);
1219 int statusCode = res.getStatus();
1221 // Check the status code of the response: does it match
1222 // the expected response(s)?
1223 if(logger.isDebugEnabled()){
1224 logger.debug(testName + ": status = " + statusCode);
1226 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1227 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1228 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1230 res.releaseConnection();
1236 * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
1239 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1240 groups = {"delete"}, dependsOnMethods = {"delete"})
1241 public void deleteNonExistent(String testName) throws Exception {
1243 if (logger.isDebugEnabled()) {
1244 logger.debug(testBanner(testName, CLASS_NAME));
1247 setupDeleteNonExistent();
1249 // Submit the request to the service and store the response.
1250 LocationAuthorityClient client = new LocationAuthorityClient();
1251 ClientResponse<Response> res = client.delete(NON_EXISTENT_ID);
1253 int statusCode = res.getStatus();
1255 // Check the status code of the response: does it match
1256 // the expected response(s)?
1257 if(logger.isDebugEnabled()){
1258 logger.debug(testName + ": status = " + statusCode);
1260 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1261 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1262 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1264 res.releaseConnection();
1269 * Delete non existent item.
1271 * @param testName the test name
1273 @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class,
1274 groups = {"delete"}, dependsOnMethods = {"deleteItem"})
1275 public void deleteNonExistentItem(String testName) {
1277 if (logger.isDebugEnabled()) {
1278 logger.debug(testBanner(testName, CLASS_NAME));
1281 setupDeleteNonExistent();
1283 // Submit the request to the service and store the response.
1284 LocationAuthorityClient client = new LocationAuthorityClient();
1285 ClientResponse<Response> res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1287 int statusCode = res.getStatus();
1289 // Check the status code of the response: does it match
1290 // the expected response(s)?
1291 if(logger.isDebugEnabled()){
1292 logger.debug(testName + ": status = " + statusCode);
1294 Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode),
1295 invalidStatusCodeMessage(REQUEST_TYPE, statusCode));
1296 Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE);
1298 res.releaseConnection();
1302 // ---------------------------------------------------------------
1303 // Utility tests : tests of code used in tests above
1304 // ---------------------------------------------------------------
1306 * Tests the code for manually submitting data that is used by several
1307 * of the methods above.
1309 @Test(dependsOnMethods = {"create", "read"})
1310 public void testSubmitRequest() {
1312 // Expected status code: 200 OK
1313 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1315 // Submit the request to the service and store the response.
1316 String method = ServiceRequestType.READ.httpMethodName();
1317 String url = getResourceURL(knownResourceId);
1318 int statusCode = submitRequest(method, url);
1320 // Check the status code of the response: does it match
1321 // the expected response(s)?
1322 if(logger.isDebugEnabled()){
1323 logger.debug("testSubmitRequest: url=" + url +
1324 " status=" + statusCode);
1326 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1331 * Test item submit request.
1333 @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"})
1334 public void testItemSubmitRequest() {
1336 // Expected status code: 200 OK
1337 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
1339 // Submit the request to the service and store the response.
1340 String method = ServiceRequestType.READ.httpMethodName();
1341 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
1342 int statusCode = submitRequest(method, url);
1344 // Check the status code of the response: does it match
1345 // the expected response(s)?
1346 if(logger.isDebugEnabled()){
1347 logger.debug("testItemSubmitRequest: url=" + url +
1348 " status=" + statusCode);
1350 Assert.assertEquals(statusCode, EXPECTED_STATUS);
1354 // ---------------------------------------------------------------
1355 // Cleanup of resources created during testing
1356 // ---------------------------------------------------------------
1359 * Deletes all resources created by tests, after all tests have been run.
1361 * This cleanup method will always be run, even if one or more tests fail.
1362 * For this reason, it attempts to remove all resources created
1363 * at any point during testing, even if some of those resources
1364 * may be expected to be deleted by certain tests.
1367 @AfterClass(alwaysRun=true)
1368 public void cleanUp() {
1369 String noTest = System.getProperty("noTestCleanup");
1370 if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1371 if (logger.isDebugEnabled()) {
1372 logger.debug("Skipping Cleanup phase ...");
1376 if (logger.isDebugEnabled()) {
1377 logger.debug("Cleaning up temporary resources created for testing ...");
1379 String parentResourceId;
1380 String itemResourceId;
1381 // Clean up contact resources.
1382 LocationAuthorityClient client = new LocationAuthorityClient();
1383 parentResourceId = knownResourceId;
1384 // Clean up item resources.
1385 for (Map.Entry<String, String> entry : allItemResourceIdsCreated.entrySet()) {
1386 itemResourceId = entry.getKey();
1387 parentResourceId = entry.getValue();
1388 // Note: Any non-success responses from the delete operation
1389 // below are ignored and not reported.
1390 ClientResponse<Response> res =
1391 client.deleteItem(parentResourceId, itemResourceId);
1392 res.releaseConnection();
1394 // Clean up parent resources.
1395 for (String resourceId : allResourceIdsCreated) {
1396 // Note: Any non-success responses from the delete operation
1397 // below are ignored and not reported.
1398 ClientResponse<Response> res = client.delete(resourceId);
1399 res.releaseConnection();
1403 // ---------------------------------------------------------------
1404 // Utility methods used by tests above
1405 // ---------------------------------------------------------------
1407 * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent()
1411 * Returns the root URL for the item service.
1413 * This URL consists of a base URL for all services, followed by
1414 * a path component for the owning parent, followed by the
1415 * path component for the items.
1417 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1418 * parent authority resource of the relevant item resource.
1420 * @return The root URL for the item service.
1422 protected String getItemServiceRootURL(String parentResourceIdentifier) {
1423 return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent();
1427 * Returns the URL of a specific item resource managed by a service, and
1428 * designated by an identifier (such as a universally unique ID, or UUID).
1430 * @param parentResourceIdentifier An identifier (such as a UUID) for the
1431 * parent authority resource of the relevant item resource.
1433 * @param itemResourceIdentifier An identifier (such as a UUID) for an
1436 * @return The URL of a specific item resource managed by a service.
1438 protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) {
1439 return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier;