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" + random.nextInt(1000);
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() + 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 check to see if the authority supports synchronization.
302 AuthorityClient client = (AuthorityClient) this.getClientInstance();
303 if (client.supportsSync() == false) {
304 return; // Exit the test since this authority doesn't support synchronization
308 // Create an empty instance of the authority, so we can sync items with it. We're
309 // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
311 String localAuthorityId = null;
313 localAuthorityId = createResource(client, testName, getSASAuthorityIdentifier());
314 } catch (Exception e) {
315 Assert.assertNotNull(localAuthorityId);
319 // Now we can try to sync the SAS authority with the local one we just created.
322 Response response = client.syncByName(getSASAuthorityIdentifier()); // Notice we're using the Short ID (short ID is the same on the local and SAS)
324 int statusCode = response.getStatus();
325 if (logger.isDebugEnabled()) {
326 logger.debug(testName + ": HTTP status = " + statusCode);
328 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
329 invalidStatusCodeMessage(testRequestType, statusCode));
330 Assert.assertEquals(statusCode, testExpectedStatusCode);
337 * SAS - Create a new authority on the SAS server.
340 @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
341 public void createSASAuthority(String testName) {
343 // First check to see if the authority supports synchronization.
345 AuthorityClient client = (AuthorityClient) this.getClientInstance();
346 if (client.supportsSync() == false) {
347 return; // Exit the test since this authority doesn't support synchronization
354 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier());
355 knownSASAuthorityResourceId = newID;
356 if (logger.isDebugEnabled()) {
357 String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
359 } catch (Exception e) {
360 logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
365 * SAS - Create an item in the SAS authority on the SAS server.
368 @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
369 public void createSASItem(String testName) {
371 // First check to see if the authority supports synchronization.
373 AuthorityClient client = (AuthorityClient) this.getClientInstance();
374 if (client.supportsSync() == false) {
375 return; // Exit the test since this authority doesn't support synchronization
381 String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
382 String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
384 // Store the ID returned from the first item resource created
385 // for additional tests below.
386 if (knownSASItemResourceId == null) {
387 knownSASItemResourceId = newID;
388 if (null != testName && logger.isDebugEnabled()) {
389 logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
393 // Keep track of the SAS authority items we create, so we can delete them from
394 // the *local* authority after we perform a sync operation. We need to keep track
395 // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
397 this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
400 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
401 dependsOnMethods = {"createItem"})
402 public void createItemList(String testName) throws Exception {
403 knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
404 for (int j = 0; j < nItemsToCreateInList; j++) {
405 createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems, this.getTestAuthorityItemShortId(true));
412 * @param testName the test name
413 * @throws Exception the exception
415 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
416 dependsOnMethods = {"CRUDTests"})
417 public void readByName(String testName) throws Exception {
421 // Submit the request to the service and store the response.
422 AuthorityClient client = (AuthorityClient) this.getClientInstance();
423 Response res = client.readByName(getKnowResourceIdentifier());
425 int statusCode = res.getStatus();
427 // Check the status code of the response: does it match
428 // the expected response(s)?
429 if (logger.isDebugEnabled()) {
430 logger.debug(testName + ": status = " + statusCode);
432 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
433 invalidStatusCodeMessage(testRequestType, statusCode));
434 Assert.assertEquals(statusCode, testExpectedStatusCode);
436 AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res);
437 Assert.assertNotNull(commonPart);
444 * Extracts the common part item from a service's item payload.
450 public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception {
451 AUTHORITY_ITEM_TYPE result = null;
453 AuthorityClient client = (AuthorityClient) getClientInstance();
454 PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName());
455 if (payloadInputPart != null) {
456 result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody();
458 Assert.assertNotNull(result,
459 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
464 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
465 dependsOnMethods = {"readItem"})
466 public void readItemNonExistent(String testName) {
468 setupReadNonExistent();
470 // Submit the request to the service and store the response.
471 AuthorityClient client = (AuthorityClient) getClientInstance();
472 Response res = client.readItem(knownResourceId, NON_EXISTENT_ID);
474 int statusCode = res.getStatus();
476 // Check the status code of the response: does it match
477 // the expected response(s)?
478 if (logger.isDebugEnabled()) {
479 logger.debug(testName + ": status = " + statusCode);
481 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
482 invalidStatusCodeMessage(testRequestType, statusCode));
483 Assert.assertEquals(statusCode, testExpectedStatusCode);
489 @Test(dataProvider = "testName",
490 dependsOnMethods = {"createItem"})
491 public void readItem(String testName) throws Exception {
495 // Submit the request to the service and store the response.
496 AuthorityClient client = (AuthorityClient) getClientInstance();
497 Response res = client.readItem(knownResourceId, knownItemResourceId);
499 int statusCode = res.getStatus();
501 // Check the status code of the response: does it match
502 // the expected response(s)?
503 if (logger.isDebugEnabled()) {
504 logger.debug(testName + ": status = " + statusCode);
506 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
507 invalidStatusCodeMessage(testRequestType, statusCode));
508 Assert.assertEquals(statusCode, testExpectedStatusCode);
510 AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res);
511 Assert.assertNotNull(itemCommonPart);
512 Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId);
513 verifyReadItemInstance(itemCommonPart);
519 protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception;
521 @Test(dataProvider = "testName",
522 dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"})
523 public void deleteItem(String testName) throws Exception {
527 // Submit the request to the service and store the response.
528 AuthorityClient client = (AuthorityClient) getClientInstance();
529 Response res = client.deleteItem(knownResourceId, knownItemResourceId);
532 statusCode = res.getStatus();
537 // Check the status code of the response: does it match
538 // the expected response(s)?
539 if (logger.isDebugEnabled()) {
540 logger.debug("delete: status = " + statusCode);
542 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
543 invalidStatusCodeMessage(testRequestType, statusCode));
544 Assert.assertEquals(statusCode, testExpectedStatusCode);
547 protected void readItemListInt(String vcsid, String shortId, String testName) {
551 // Submit the request to the service and store the response.
552 AuthorityClient client = (AuthorityClient) getClientInstance();
555 res = client.readItemList(vcsid, null, null);
556 } else if (shortId != null) {
557 res = client.readItemListForNamedAuthority(shortId, null, null);
559 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
562 int statusCode = res.getStatus();
564 // Check the status code of the response: does it match
565 // the expected response(s)?
566 if (logger.isDebugEnabled()) {
567 logger.debug(" " + testName + ": status = " + statusCode);
569 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
570 invalidStatusCodeMessage(testRequestType, statusCode));
571 Assert.assertEquals(statusCode, testExpectedStatusCode);
573 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
574 List<AbstractCommonList.ListItem> items = list.getListItem();
575 int nItemsReturned = items.size();
576 long nItemsTotal = list.getTotalItems();
577 if (logger.isDebugEnabled()) {
578 logger.debug(" " + testName + ": Expected "
579 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
581 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
583 if(logger.isTraceEnabled()){
584 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
591 @Test(dataProvider = "testName",
592 dependsOnMethods = {"createItemList"})
593 public void readItemList(String testName) {
594 readItemListInt(knownAuthorityWithItems, null, testName);
597 @Test(dataProvider = "testName",
598 dependsOnMethods = {"readItem"})
599 public void readItemListByName(String testName) {
600 readItemListInt(null, READITEMS_SHORT_IDENTIFIER, testName);
603 @Test(dataProvider = "testName",
604 dependsOnMethods = {"deleteItem"})
605 public void deleteNonExistentItem(String testName) {
607 setupDeleteNonExistent();
609 // Submit the request to the service and store the response.
610 AuthorityClient client = (AuthorityClient) getClientInstance();
611 Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
614 statusCode = res.getStatus();
619 // Check the status code of the response: does it match
620 // the expected response(s)?
621 if (logger.isDebugEnabled()) {
622 logger.debug(testName + ": status = " + statusCode);
624 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
625 invalidStatusCodeMessage(testRequestType, statusCode));
626 Assert.assertEquals(statusCode, testExpectedStatusCode);
629 protected String getServicePathItemsComponent() {
630 return AuthorityClient.ITEMS;
633 public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) {
634 PoxPayloadOut result = null;
636 AuthorityClient client = (AuthorityClient) getClientInstance();
637 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
638 PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
645 * Update an Authority item.
650 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
651 dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"})
652 public void updateItem(String testName) throws Exception {
655 AUTHORITY_ITEM_TYPE theUpdate = null;
657 // Retrieve the contents of a resource to update.
658 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
659 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
660 Response res = client.readItem(knownResourceId, knownItemResourceId);
662 if (logger.isDebugEnabled()) {
663 logger.debug(testName + ": read status = " + res.getStatus());
665 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
667 if (logger.isDebugEnabled()) {
668 logger.debug("got Authority item to update with ID: "
669 + knownItemResourceId
670 + " in authority: " + knownResourceId);
672 AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res);
673 Assert.assertNotNull(authorityItem);
675 // Update the contents of this resource.
676 theUpdate = updateItemInstance(authorityItem);
677 if (logger.isDebugEnabled()) {
678 logger.debug("\n\nTo be updated fields: CSID = " + knownItemResourceId + "\n"
679 + objectAsXmlString(theUpdate));
685 // Submit the updated resource to the service and store the response.
686 PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
687 res = client.updateItem(knownResourceId, knownItemResourceId, output);
689 int statusCode = res.getStatus();
691 // Check the status code of the response: does it match the expected response(s)?
692 if (logger.isDebugEnabled()) {
693 logger.debug("updateItem: status = " + statusCode);
695 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
696 invalidStatusCodeMessage(testRequestType, statusCode));
697 Assert.assertEquals(statusCode, testExpectedStatusCode);
699 // Retrieve the updated resource and verify that its contents exist.
700 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
701 Assert.assertNotNull(updatedVocabularyItem);
703 compareUpdatedItemInstances(theUpdate, updatedVocabularyItem);
709 protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
712 * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
714 @Test(dataProvider = "testName",
715 dependsOnMethods = {"create", "update", "updateNonExistent"})
716 public void updateNonExistentItem(String testName) throws Exception {
718 setupUpdateNonExistent();
720 // Submit the request to the service and store the response.
721 // Note: The ID used in this 'create' call may be arbitrary.
722 // The only relevant ID may be the one used in update(), below.
723 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
724 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
725 PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
726 Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
728 int statusCode = res.getStatus();
730 // Check the status code of the response: does it match
731 // the expected response(s)?
732 if (logger.isDebugEnabled()) {
733 logger.debug(testName + ": status = " + statusCode);
735 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
736 invalidStatusCodeMessage(testRequestType, statusCode));
737 Assert.assertEquals(statusCode, testExpectedStatusCode);
744 // Methods to persuade TestNG to follow the correct test dependency path
747 @Test(dataProvider = "testName",
748 dependsOnMethods = {"createItem"})
749 public void baseAuthorityTests(String testName) {
750 // Do nothing. Here just to setup a test dependency chain.
754 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
755 * refer to this method in their @Test annotation declarations.
758 @Test(dataProvider = "testName",
760 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
761 public void CRUDTests(String testName) {
762 // TODO Auto-generated method stub
766 public void cleanUp() {
767 String noTest = System.getProperty("noTestCleanup");
768 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
769 if (logger.isDebugEnabled()) {
770 logger.debug("Skipping Cleanup phase ...");
775 AuthorityClient client = (AuthorityClient) this.getClientInstance();
776 String parentResourceId;
777 String itemResourceId;
779 // Clean up all authority item resources.
781 for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
782 itemResourceId = entry.getKey();
783 parentResourceId = entry.getValue();
784 Response response = client.deleteItem(parentResourceId, itemResourceId);
786 int status = response.getStatus();
787 if (status != Response.Status.OK.getStatusCode()) {
788 logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
789 itemResourceId, parentResourceId));
796 // Clean up authority items that were the result of a sync with the SAS
797 // all the IDs are URN (not CSIDs). The URNs work for the local items as well
800 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
801 itemResourceId = entry.getKey();
802 parentResourceId = entry.getValue();
803 // Note: Any non-success responses from the delete operation
804 // below are ignored and not reported.
805 client.deleteItem(parentResourceId, itemResourceId).close();
808 // Clean up authority items on the SAS using the SAS client.
810 client = (AuthorityClient) this.getSASClientInstance();
811 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
812 itemResourceId = entry.getKey();
813 parentResourceId = entry.getValue();
814 client.deleteItem(parentResourceId, itemResourceId).close();
817 // Finally, call out superclass's cleanUp method to deleted the local authorities
821 // Call out superclass's cleanUp method to delete the SAS authorities
823 super.cleanUp(client);
826 protected String getTestAuthorityItemShortId() {
827 return getTestAuthorityItemShortId(false);
830 protected String getTestAuthorityItemShortId(boolean makeUnique) {
831 String result = TEST_SHORTID;
833 if (makeUnique == true) {
834 result = result + System.currentTimeMillis() + Math.abs(random.nextInt());