1 package org.collectionspace.services.client.test;
3 import java.util.HashMap;
7 import javax.ws.rs.core.Response;
9 import org.collectionspace.services.client.AbstractCommonListUtils;
10 import org.collectionspace.services.client.AuthorityClient;
11 import org.collectionspace.services.client.AuthorityClientImpl;
12 import org.collectionspace.services.client.AuthorityProxy;
13 import org.collectionspace.services.client.CollectionSpaceClient;
14 import org.collectionspace.services.client.PayloadInputPart;
15 import org.collectionspace.services.client.PayloadOutputPart;
16 import org.collectionspace.services.client.PoxPayloadOut;
17 import org.collectionspace.services.jaxb.AbstractCommonList;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.testng.Assert;
21 import org.testng.annotations.Test;
27 * @param <AUTHORITY_COMMON_TYPE>
28 * @param <AUTHORITY_ITEM_TYPE>
30 * All CRUD related authority test classes should extend this class.
33 public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE>
34 extends AbstractPoxServiceTestImpl<AbstractCommonList, AUTHORITY_COMMON_TYPE> {
36 private final Logger logger = LoggerFactory.getLogger(AbstractAuthorityServiceTest.class);
38 protected String knownResourceShortIdentifer = null;
39 protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems";
40 protected String knownAuthorityWithItems = null;
42 protected static final String SAS_IDENTIFIER = "SAS";
43 protected String knownSASAuthorityResourceId = null;
44 protected String knownSASItemResourceId = null;
45 protected HashMap<String, String> allSASResourceItemIdsCreated = new HashMap<String, String>(); /* itemURN, parentURN */;
47 protected String knownResourceRefName = null;
48 protected String knownItemResourceId = null;
49 protected String knownItemResourceShortIdentifer = null;
50 protected int nItemsToCreateInList = 5;
51 protected String TEST_SHORTID = "johnWayneActor";
54 * Abstract methods that subclasses must override/implement
61 public abstract void authorityTests(String testName);
69 abstract protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId);
74 * @param authorityItem
77 protected abstract AUTHORITY_ITEM_TYPE updateItemInstance(final AUTHORITY_ITEM_TYPE authorityItem);
85 protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original, AUTHORITY_ITEM_TYPE updated) throws Exception;
90 * @param shortIdentifer
92 protected void setKnownItemResource(String id, String shortIdentifer ) {
93 knownItemResourceId = id;
94 knownItemResourceShortIdentifer = shortIdentifer;
100 * @param shortIdentifer
103 protected void setKnownResource(String id, String shortIdentifer,
105 knownResourceId = id;
106 knownResourceShortIdentifer = shortIdentifer;
107 knownResourceRefName = refName;
114 protected String getSASAuthorityIdentifier() {
115 // TODO Auto-generated method stub
116 return this.getKnowResourceIdentifier() + this.SAS_IDENTIFIER;
124 protected String getUrnIdentifier(String shortId) {
125 return String.format("urn:cspace:name(%s)", shortId);
129 * Sets up create tests.
131 protected void setupSync() {
132 testExpectedStatusCode = this.STATUS_OK;
133 testRequestType = ServiceRequestType.SYNC;
134 testSetup(testExpectedStatusCode, testRequestType);
138 * Gets a client to the SAS (Shared Authority Server)
142 protected AuthorityClient getSASClientInstance() {
143 return (AuthorityClient) this.getClientInstance(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
147 * Returns the root URL for a service.
149 * This URL consists of a base URL for all services, followed by
150 * a path component for the owning vocabulary, followed by the
151 * path component for the items.
153 * @return The root URL for a service.
155 protected String getItemServiceRootURL(String parentResourceIdentifier) {
156 return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
160 * Returns the URL of a specific resource managed by a service, and
161 * designated by an identifier (such as a universally unique ID, or UUID).
163 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
165 * @return The URL of a specific resource managed by a service.
167 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
168 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
172 * For authorities we override this method so we can save the shortid.
175 protected String createWithIdentifier(String testName, String identifier) throws Exception {
176 String csid = createResource(testName, identifier);
177 // Store the ID returned from the first resource created
178 // for additional tests below.
179 if (getKnowResourceId() == null) {
180 setKnownResource(csid, identifier /*shortId*/, null /*refname*/ );
181 if (logger.isDebugEnabled()) {
182 logger.debug(testName + ": Setting knownResourceId=" + getKnowResourceId());
189 @Test(dependsOnMethods = {"readItem", "CRUDTests"})
190 public void testItemSubmitRequest() {
192 // Expected status code: 200 OK
193 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
195 // Submit the request to the service and store the response.
196 String method = ServiceRequestType.READ.httpMethodName();
197 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
198 int statusCode = submitRequest(method, url);
200 // Check the status code of the response: does it match
201 // the expected response(s)?
202 if (logger.isDebugEnabled()) {
203 logger.debug("testItemSubmitRequest: url=" + url
204 + " status=" + statusCode);
206 Assert.assertEquals(statusCode, EXPECTED_STATUS);
210 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
211 dependsOnMethods = {"readItem"})
212 public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
216 // Submit the request to the service and store the response.
217 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
218 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
219 Response res = client.readItem(knownResourceId, knownItemResourceId);
220 AUTHORITY_ITEM_TYPE vitem = null;
222 int statusCode = res.getStatus();
224 // Check the status code of the response: does it match
225 // the expected response(s)?
226 if (logger.isDebugEnabled()) {
227 logger.debug(testName + " read authority:" + knownResourceId + "/Item:"
228 + knownItemResourceId + " status = " + statusCode);
230 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
231 invalidStatusCodeMessage(testRequestType, statusCode));
232 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
234 vitem = extractItemCommonPartValue(res);
235 Assert.assertNotNull(vitem);
236 // Try to Update with new parent vocab (use self, for test).
237 Assert.assertEquals(client.getInAuthority(vitem), knownResourceId,
238 "VocabularyItem inAuthority does not match knownResourceId.");
239 client.setInAuthority(vitem, knownItemResourceId);
245 // Submit the updated resource to the service and store the response.
246 PoxPayloadOut output = this.createItemRequestTypeInstance(vitem);
247 res = client.updateItem(knownResourceId, knownItemResourceId, output);
249 int statusCode = res.getStatus();
251 // Check the status code of the response: does it match the expected response(s)?
252 if (logger.isDebugEnabled()) {
253 logger.debug(testName + ": status = " + statusCode);
255 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
256 invalidStatusCodeMessage(testRequestType, statusCode));
257 Assert.assertEquals(statusCode, testExpectedStatusCode);
262 res = client.readItem(knownResourceId, knownItemResourceId);
264 // Retrieve the updated resource and verify that the parent did not change
265 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
266 Assert.assertNotNull(updatedVocabularyItem);
268 // Verify that the updated resource received the correct data.
269 Assert.assertEquals(client.getInAuthority(updatedVocabularyItem),
271 "VocabularyItem allowed update to the parent (inAuthority).");
277 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
278 public void createItem(String testName) {
282 String newID = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId, getTestAuthorityItemShortId());
284 // Store the ID returned from the first item resource created
285 // for additional tests below.
286 if (knownItemResourceId == null) {
287 knownItemResourceId = newID;
288 if (null != testName && logger.isDebugEnabled()) {
289 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
295 * Sync the local with the SAS
297 @Test(dataProvider = "testName", dependsOnMethods = {"createSASItem", "CRUDTests"})
298 public void syncWithSAS(String testName) {
300 // First create an empty instance of the authority, so we can sync items with it. We're
301 // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
303 AuthorityClient client = (AuthorityClient) this.getClientInstance();
304 String localAuthorityId = null;
306 localAuthorityId = createResource(client, testName, getSASAuthorityIdentifier());
307 } catch (Exception e) {
308 Assert.assertNotNull(localAuthorityId);
312 // Now we can try to sync the SAS authority with the local one we just created.
315 Response response = client.syncByName(getSASAuthorityIdentifier()); // Notice we're using the Short ID (short ID is the same on the local and SAS)
317 int statusCode = response.getStatus();
318 if (logger.isDebugEnabled()) {
319 logger.debug(testName + ": HTTP status = " + statusCode);
321 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
322 invalidStatusCodeMessage(testRequestType, statusCode));
323 Assert.assertEquals(statusCode, testExpectedStatusCode);
330 * SAS - Create a new authority on the SAS server.
333 @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
334 public void createSASAuthority(String testName) {
339 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier());
340 knownSASAuthorityResourceId = newID;
341 if (logger.isDebugEnabled()) {
342 String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
344 } catch (Exception e) {
345 logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
350 * SAS - Create an item in the SAS authority on the SAS server.
353 @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
354 public void createSASItem(String testName) {
358 String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
359 String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
361 // Store the ID returned from the first item resource created
362 // for additional tests below.
363 if (knownSASItemResourceId == null) {
364 knownSASItemResourceId = newID;
365 if (null != testName && logger.isDebugEnabled()) {
366 logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
370 // Keep track of the SAS authority items we create, so we can delete them from
371 // the *local* authority after we perform a sync operation. We need to keep track
372 // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
374 this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
377 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
378 dependsOnMethods = {"createItem"})
379 public void createItemList(String testName) throws Exception {
380 knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
381 for (int j = 0; j < nItemsToCreateInList; j++) {
382 createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems, this.getTestAuthorityItemShortId(true));
389 * @param testName the test name
390 * @throws Exception the exception
392 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
393 dependsOnMethods = {"CRUDTests"})
394 public void readByName(String testName) throws Exception {
398 // Submit the request to the service and store the response.
399 AuthorityClient client = (AuthorityClient) this.getClientInstance();
400 Response res = client.readByName(getKnowResourceIdentifier());
402 int statusCode = res.getStatus();
404 // Check the status code of the response: does it match
405 // the expected response(s)?
406 if (logger.isDebugEnabled()) {
407 logger.debug(testName + ": status = " + statusCode);
409 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
410 invalidStatusCodeMessage(testRequestType, statusCode));
411 Assert.assertEquals(statusCode, testExpectedStatusCode);
413 AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res);
414 Assert.assertNotNull(commonPart);
421 * Extracts the common part item from a service's item payload.
427 public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception {
428 AUTHORITY_ITEM_TYPE result = null;
430 AuthorityClient client = (AuthorityClient) getClientInstance();
431 PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName());
432 if (payloadInputPart != null) {
433 result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody();
435 Assert.assertNotNull(result,
436 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
441 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
442 dependsOnMethods = {"readItem"})
443 public void readItemNonExistent(String testName) {
445 setupReadNonExistent();
447 // Submit the request to the service and store the response.
448 AuthorityClient client = (AuthorityClient) getClientInstance();
449 Response res = client.readItem(knownResourceId, NON_EXISTENT_ID);
451 int statusCode = res.getStatus();
453 // Check the status code of the response: does it match
454 // the expected response(s)?
455 if (logger.isDebugEnabled()) {
456 logger.debug(testName + ": status = " + statusCode);
458 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
459 invalidStatusCodeMessage(testRequestType, statusCode));
460 Assert.assertEquals(statusCode, testExpectedStatusCode);
466 @Test(dataProvider = "testName",
467 dependsOnMethods = {"createItem"})
468 public void readItem(String testName) throws Exception {
472 // Submit the request to the service and store the response.
473 AuthorityClient client = (AuthorityClient) getClientInstance();
474 Response res = client.readItem(knownResourceId, knownItemResourceId);
476 int statusCode = res.getStatus();
478 // Check the status code of the response: does it match
479 // the expected response(s)?
480 if (logger.isDebugEnabled()) {
481 logger.debug(testName + ": status = " + statusCode);
483 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
484 invalidStatusCodeMessage(testRequestType, statusCode));
485 Assert.assertEquals(statusCode, testExpectedStatusCode);
487 AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res);
488 Assert.assertNotNull(itemCommonPart);
489 Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId);
490 verifyReadItemInstance(itemCommonPart);
496 protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception;
498 @Test(dataProvider = "testName",
499 dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"})
500 public void deleteItem(String testName) throws Exception {
504 // Submit the request to the service and store the response.
505 AuthorityClient client = (AuthorityClient) getClientInstance();
506 Response res = client.deleteItem(knownResourceId, knownItemResourceId);
509 statusCode = res.getStatus();
514 // Check the status code of the response: does it match
515 // the expected response(s)?
516 if (logger.isDebugEnabled()) {
517 logger.debug("delete: status = " + statusCode);
519 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
520 invalidStatusCodeMessage(testRequestType, statusCode));
521 Assert.assertEquals(statusCode, testExpectedStatusCode);
524 protected void readItemListInt(String vcsid, String shortId, String testName) {
528 // Submit the request to the service and store the response.
529 AuthorityClient client = (AuthorityClient) getClientInstance();
532 res = client.readItemList(vcsid, null, null);
533 } else if (shortId != null) {
534 res = client.readItemListForNamedAuthority(shortId, null, null);
536 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
539 int statusCode = res.getStatus();
541 // Check the status code of the response: does it match
542 // the expected response(s)?
543 if (logger.isDebugEnabled()) {
544 logger.debug(" " + testName + ": status = " + statusCode);
546 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
547 invalidStatusCodeMessage(testRequestType, statusCode));
548 Assert.assertEquals(statusCode, testExpectedStatusCode);
550 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
551 List<AbstractCommonList.ListItem> items = list.getListItem();
552 int nItemsReturned = items.size();
553 long nItemsTotal = list.getTotalItems();
554 if (logger.isDebugEnabled()) {
555 logger.debug(" " + testName + ": Expected "
556 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
558 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
560 if(logger.isTraceEnabled()){
561 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
568 @Test(dataProvider = "testName",
569 dependsOnMethods = {"createItemList"})
570 public void readItemList(String testName) {
571 readItemListInt(knownAuthorityWithItems, null, testName);
574 @Test(dataProvider = "testName",
575 dependsOnMethods = {"readItem"})
576 public void readItemListByName(String testName) {
577 readItemListInt(null, READITEMS_SHORT_IDENTIFIER, testName);
580 @Test(dataProvider = "testName",
581 dependsOnMethods = {"deleteItem"})
582 public void deleteNonExistentItem(String testName) {
584 setupDeleteNonExistent();
586 // Submit the request to the service and store the response.
587 AuthorityClient client = (AuthorityClient) getClientInstance();
588 Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
591 statusCode = res.getStatus();
596 // Check the status code of the response: does it match
597 // the expected response(s)?
598 if (logger.isDebugEnabled()) {
599 logger.debug(testName + ": status = " + statusCode);
601 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
602 invalidStatusCodeMessage(testRequestType, statusCode));
603 Assert.assertEquals(statusCode, testExpectedStatusCode);
606 protected String getServicePathItemsComponent() {
607 return AuthorityClient.ITEMS;
610 public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) {
611 PoxPayloadOut result = null;
613 AuthorityClient client = (AuthorityClient) getClientInstance();
614 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
615 PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
622 * Update an Authority item.
627 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
628 dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"})
629 public void updateItem(String testName) throws Exception {
632 AUTHORITY_ITEM_TYPE theUpdate = null;
634 // Retrieve the contents of a resource to update.
635 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
636 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
637 Response res = client.readItem(knownResourceId, knownItemResourceId);
639 if (logger.isDebugEnabled()) {
640 logger.debug(testName + ": read status = " + res.getStatus());
642 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
644 if (logger.isDebugEnabled()) {
645 logger.debug("got Authority item to update with ID: "
646 + knownItemResourceId
647 + " in authority: " + knownResourceId);
649 AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res);
650 Assert.assertNotNull(authorityItem);
652 // Update the contents of this resource.
653 theUpdate = updateItemInstance(authorityItem);
654 if (logger.isDebugEnabled()) {
655 logger.debug("\n\nTo be updated fields: CSID = " + knownItemResourceId + "\n"
656 + objectAsXmlString(theUpdate));
662 // Submit the updated resource to the service and store the response.
663 PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
664 res = client.updateItem(knownResourceId, knownItemResourceId, output);
666 int statusCode = res.getStatus();
668 // Check the status code of the response: does it match the expected response(s)?
669 if (logger.isDebugEnabled()) {
670 logger.debug("updateItem: status = " + statusCode);
672 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
673 invalidStatusCodeMessage(testRequestType, statusCode));
674 Assert.assertEquals(statusCode, testExpectedStatusCode);
676 // Retrieve the updated resource and verify that its contents exist.
677 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
678 Assert.assertNotNull(updatedVocabularyItem);
680 compareUpdatedItemInstances(theUpdate, updatedVocabularyItem);
686 protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
689 * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
691 @Test(dataProvider = "testName",
692 dependsOnMethods = {"create", "update", "updateNonExistent"})
693 public void updateNonExistentItem(String testName) throws Exception {
695 setupUpdateNonExistent();
697 // Submit the request to the service and store the response.
698 // Note: The ID used in this 'create' call may be arbitrary.
699 // The only relevant ID may be the one used in update(), below.
700 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
701 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
702 PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
703 Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
705 int statusCode = res.getStatus();
707 // Check the status code of the response: does it match
708 // the expected response(s)?
709 if (logger.isDebugEnabled()) {
710 logger.debug(testName + ": status = " + statusCode);
712 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
713 invalidStatusCodeMessage(testRequestType, statusCode));
714 Assert.assertEquals(statusCode, testExpectedStatusCode);
721 // Methods to persuade TestNG to follow the correct test dependency path
724 @Test(dataProvider = "testName",
725 dependsOnMethods = {"createItem"})
726 public void baseAuthorityTests(String testName) {
727 // Do nothing. Here just to setup a test dependency chain.
731 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
732 * refer to this method in their @Test annotation declarations.
735 @Test(dataProvider = "testName",
737 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
738 public void CRUDTests(String testName) {
739 // TODO Auto-generated method stub
743 public void cleanUp() {
744 String noTest = System.getProperty("noTestCleanup");
745 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
746 if (logger.isDebugEnabled()) {
747 logger.debug("Skipping Cleanup phase ...");
752 AuthorityClient client = (AuthorityClient) this.getClientInstance();
753 String parentResourceId;
754 String itemResourceId;
756 // Clean up all authority item resources.
758 for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
759 itemResourceId = entry.getKey();
760 parentResourceId = entry.getValue();
761 Response response = client.deleteItem(parentResourceId, itemResourceId);
763 int status = response.getStatus();
764 if (status != Response.Status.OK.getStatusCode()) {
765 logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
766 itemResourceId, parentResourceId));
773 // Clean up authority items that were the result of a sync with the SAS
774 // all the IDs are URN (not CSIDs). The URNs work for the local items as well
777 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
778 itemResourceId = entry.getKey();
779 parentResourceId = entry.getValue();
780 // Note: Any non-success responses from the delete operation
781 // below are ignored and not reported.
782 client.deleteItem(parentResourceId, itemResourceId).close();
785 // Clean up authority items on the SAS using the SAS client.
787 client = (AuthorityClient) this.getSASClientInstance();
788 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
789 itemResourceId = entry.getKey();
790 parentResourceId = entry.getValue();
791 client.deleteItem(parentResourceId, itemResourceId).close();
794 // Finally, call out superclass's cleanUp method to deleted the local authorities
798 // Call out superclass's cleanUp method to delete the SAS authorities
800 super.cleanUp(client);
803 protected String getTestAuthorityItemShortId() {
804 return getTestAuthorityItemShortId(false);
807 protected String getTestAuthorityItemShortId(boolean makeUnique) {
808 String result = TEST_SHORTID;
810 if (makeUnique == true) {
811 result = result + System.currentTimeMillis() + Math.abs(random.nextInt());