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;
52 public abstract void authorityTests(String testName);
53 protected abstract String createItemInAuthority(AuthorityClient client, String authorityId);
55 protected abstract AUTHORITY_ITEM_TYPE updateItemInstance(final AUTHORITY_ITEM_TYPE authorityItem);
56 protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original, AUTHORITY_ITEM_TYPE updated) throws Exception;
58 protected void setKnownItemResource(String id, String shortIdentifer ) {
59 knownItemResourceId = id;
60 knownItemResourceShortIdentifer = shortIdentifer;
63 protected void setKnownResource(String id, String shortIdentifer,
66 knownResourceShortIdentifer = shortIdentifer;
67 knownResourceRefName = refName;
70 protected String getSASAuthorityIdentifier() {
71 // TODO Auto-generated method stub
72 return this.getKnowResourceIdentifier() + this.SAS_IDENTIFIER;
75 protected String getUrnIdentifier(String shortId) {
76 return String.format("urn:cspace:name:(%s)", shortId);
80 * Sets up create tests.
82 protected void setupSync() {
83 testExpectedStatusCode = this.STATUS_OK;
84 testRequestType = ServiceRequestType.SYNC;
85 testSetup(testExpectedStatusCode, testRequestType);
89 * Gets a client to the SAS (Shared Authority Server)
93 protected AuthorityClient getSASClientInstance() {
94 return (AuthorityClient) this.getClientInstance(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
98 * Returns the root URL for a service.
100 * This URL consists of a base URL for all services, followed by
101 * a path component for the owning vocabulary, followed by the
102 * path component for the items.
104 * @return The root URL for a service.
106 protected String getItemServiceRootURL(String parentResourceIdentifier) {
107 return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
111 * Returns the URL of a specific resource managed by a service, and
112 * designated by an identifier (such as a universally unique ID, or UUID).
114 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
116 * @return The URL of a specific resource managed by a service.
118 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
119 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
123 * For authorities we override this method so we can save the shortid.
126 protected String createWithIdentifier(String testName, String identifier) throws Exception {
127 String csid = createResource(testName, identifier);
128 // Store the ID returned from the first resource created
129 // for additional tests below.
130 if (getKnowResourceId() == null) {
131 setKnownResource(csid, identifier /*shortId*/, null /*refname*/ );
132 if (logger.isDebugEnabled()) {
133 logger.debug(testName + ": Setting knownResourceId=" + getKnowResourceId());
140 @Test(dependsOnMethods = {"readItem", "CRUDTests"})
141 public void testItemSubmitRequest() {
143 // Expected status code: 200 OK
144 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
146 // Submit the request to the service and store the response.
147 String method = ServiceRequestType.READ.httpMethodName();
148 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
149 int statusCode = submitRequest(method, url);
151 // Check the status code of the response: does it match
152 // the expected response(s)?
153 if (logger.isDebugEnabled()) {
154 logger.debug("testItemSubmitRequest: url=" + url
155 + " status=" + statusCode);
157 Assert.assertEquals(statusCode, EXPECTED_STATUS);
161 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
162 dependsOnMethods = {"readItem"})
163 public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
167 // Submit the request to the service and store the response.
168 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
169 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
170 Response res = client.readItem(knownResourceId, knownItemResourceId);
171 AUTHORITY_ITEM_TYPE vitem = null;
173 int statusCode = res.getStatus();
175 // Check the status code of the response: does it match
176 // the expected response(s)?
177 if (logger.isDebugEnabled()) {
178 logger.debug(testName + " read authority:" + knownResourceId + "/Item:"
179 + knownItemResourceId + " status = " + statusCode);
181 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
182 invalidStatusCodeMessage(testRequestType, statusCode));
183 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
185 vitem = extractItemCommonPartValue(res);
186 Assert.assertNotNull(vitem);
187 // Try to Update with new parent vocab (use self, for test).
188 Assert.assertEquals(client.getInAuthority(vitem), knownResourceId,
189 "VocabularyItem inAuthority does not match knownResourceId.");
190 client.setInAuthority(vitem, knownItemResourceId);
196 // Submit the updated resource to the service and store the response.
197 PoxPayloadOut output = this.createItemRequestTypeInstance(vitem);
198 res = client.updateItem(knownResourceId, knownItemResourceId, output);
200 int statusCode = res.getStatus();
202 // Check the status code of the response: does it match the expected response(s)?
203 if (logger.isDebugEnabled()) {
204 logger.debug(testName + ": status = " + statusCode);
206 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
207 invalidStatusCodeMessage(testRequestType, statusCode));
208 Assert.assertEquals(statusCode, testExpectedStatusCode);
213 res = client.readItem(knownResourceId, knownItemResourceId);
215 // Retrieve the updated resource and verify that the parent did not change
216 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
217 Assert.assertNotNull(updatedVocabularyItem);
219 // Verify that the updated resource received the correct data.
220 Assert.assertEquals(client.getInAuthority(updatedVocabularyItem),
222 "VocabularyItem allowed update to the parent (inAuthority).");
228 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
229 public void createItem(String testName) {
233 String newID = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId);
235 // Store the ID returned from the first item resource created
236 // for additional tests below.
237 if (knownItemResourceId == null) {
238 knownItemResourceId = newID;
239 if (null != testName && logger.isDebugEnabled()) {
240 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
246 * Sync the local with the SAS
248 @Test(dataProvider = "testName", dependsOnMethods = {"createSASItem", "CRUDTests"})
249 public void syncWithSAS(String testName) {
251 AuthorityClient client = (AuthorityClient) this.getClientInstance();
254 // First create an empty instance of the authority, so we can sync items with it. We're
255 // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
257 String localAuthorityId = null;
259 localAuthorityId = createResource(client, testName, getSASAuthorityIdentifier());
260 } catch (Exception e) {
261 Assert.assertNotNull(localAuthorityId);
265 // Now we can try to sync the SAS authority with the local one we just created.
267 Response response = client.syncByName(getSASAuthorityIdentifier()); // Notice we're using the Short ID (short ID is the same on the local and SAS)
269 int statusCode = response.getStatus();
270 if (logger.isDebugEnabled()) {
271 logger.debug(testName + ": HTTP status = " + statusCode);
273 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
274 invalidStatusCodeMessage(testRequestType, statusCode));
275 Assert.assertEquals(statusCode, testExpectedStatusCode);
282 * SAS - Create a new authority on the SAS server.
285 @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
286 public void createSASAuthority(String testName) {
291 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier());
292 knownSASAuthorityResourceId = newID;
293 if (logger.isDebugEnabled()) {
294 String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
296 } catch (Exception e) {
297 logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
302 * SAS - Create an item in the SAS authority on the SAS server.
305 @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
306 public void createSASItem(String testName) {
310 String shortId = "SassyActor" + System.currentTimeMillis() + random.nextInt();; // short ID needs to be unique
311 String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
313 // Store the ID returned from the first item resource created
314 // for additional tests below.
315 if (knownSASItemResourceId == null) {
316 knownSASItemResourceId = newID;
317 if (null != testName && logger.isDebugEnabled()) {
318 logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
322 // Keep track of the SAS authority items we create, so we can delete them from
323 // the *local* authority after we perform a sync operation. We need to keep track
324 // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
326 this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(getSASAuthorityIdentifier()));
329 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
330 dependsOnMethods = {"createItem"})
331 public void createItemList(String testName) throws Exception {
332 knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
333 for (int j = 0; j < nItemsToCreateInList; j++) {
334 createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems);
341 * @param testName the test name
342 * @throws Exception the exception
344 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
345 dependsOnMethods = {"CRUDTests"})
346 public void readByName(String testName) throws Exception {
350 // Submit the request to the service and store the response.
351 AuthorityClient client = (AuthorityClient) this.getClientInstance();
352 Response res = client.readByName(getKnowResourceIdentifier());
354 int statusCode = res.getStatus();
356 // Check the status code of the response: does it match
357 // the expected response(s)?
358 if (logger.isDebugEnabled()) {
359 logger.debug(testName + ": status = " + statusCode);
361 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
362 invalidStatusCodeMessage(testRequestType, statusCode));
363 Assert.assertEquals(statusCode, testExpectedStatusCode);
365 AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res);
366 Assert.assertNotNull(commonPart);
373 * Extracts the common part item from a service's item payload.
379 public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception {
380 AUTHORITY_ITEM_TYPE result = null;
382 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)
383 this.getClientInstance();
384 PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName());
385 if (payloadInputPart != null) {
386 result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody();
388 Assert.assertNotNull(result,
389 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
394 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
395 dependsOnMethods = {"readItem"})
396 public void readItemNonExistent(String testName) {
398 setupReadNonExistent();
400 // Submit the request to the service and store the response.
401 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)
402 this.getClientInstance();
403 Response res = client.readItem(knownResourceId, NON_EXISTENT_ID);
405 int statusCode = res.getStatus();
407 // Check the status code of the response: does it match
408 // the expected response(s)?
409 if (logger.isDebugEnabled()) {
410 logger.debug(testName + ": status = " + statusCode);
412 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
413 invalidStatusCodeMessage(testRequestType, statusCode));
414 Assert.assertEquals(statusCode, testExpectedStatusCode);
420 @Test(dataProvider = "testName",
421 dependsOnMethods = {"createItem"})
422 public void readItem(String testName) throws Exception {
426 // Submit the request to the service and store the response.
427 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
428 Response res = client.readItem(knownResourceId, knownItemResourceId);
430 int statusCode = res.getStatus();
432 // Check the status code of the response: does it match
433 // the expected response(s)?
434 if (logger.isDebugEnabled()) {
435 logger.debug(testName + ": status = " + statusCode);
437 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
438 invalidStatusCodeMessage(testRequestType, statusCode));
439 Assert.assertEquals(statusCode, testExpectedStatusCode);
441 AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res);
442 Assert.assertNotNull(itemCommonPart);
443 Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId);
444 verifyReadItemInstance(itemCommonPart);
450 protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception;
452 @Test(dataProvider = "testName",
453 dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"})
454 public void deleteItem(String testName) throws Exception {
458 // Submit the request to the service and store the response.
459 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)
460 this.getClientInstance();
461 Response res = client.deleteItem(knownResourceId, knownItemResourceId);
464 statusCode = res.getStatus();
469 // Check the status code of the response: does it match
470 // the expected response(s)?
471 if (logger.isDebugEnabled()) {
472 logger.debug("delete: status = " + statusCode);
474 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
475 invalidStatusCodeMessage(testRequestType, statusCode));
476 Assert.assertEquals(statusCode, testExpectedStatusCode);
479 protected void readItemListInt(String vcsid, String shortId, String testName) {
483 // Submit the request to the service and store the response.
484 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
487 res = client.readItemList(vcsid, null, null);
488 } else if (shortId != null) {
489 res = client.readItemListForNamedAuthority(shortId, null, null);
491 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
494 int statusCode = res.getStatus();
496 // Check the status code of the response: does it match
497 // the expected response(s)?
498 if (logger.isDebugEnabled()) {
499 logger.debug(" " + testName + ": status = " + statusCode);
501 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
502 invalidStatusCodeMessage(testRequestType, statusCode));
503 Assert.assertEquals(statusCode, testExpectedStatusCode);
505 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
506 List<AbstractCommonList.ListItem> items = list.getListItem();
507 int nItemsReturned = items.size();
508 long nItemsTotal = list.getTotalItems();
509 if (logger.isDebugEnabled()) {
510 logger.debug(" " + testName + ": Expected "
511 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
513 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
515 if(logger.isTraceEnabled()){
516 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
523 @Test(dataProvider = "testName",
524 dependsOnMethods = {"createItemList"})
525 public void readItemList(String testName) {
526 readItemListInt(knownAuthorityWithItems, null, testName);
529 @Test(dataProvider = "testName",
530 dependsOnMethods = {"readItem"})
531 public void readItemListByName(String testName) {
532 readItemListInt(null, READITEMS_SHORT_IDENTIFIER, testName);
535 @Test(dataProvider = "testName",
536 dependsOnMethods = {"deleteItem"})
537 public void deleteNonExistentItem(String testName) {
539 setupDeleteNonExistent();
541 // Submit the request to the service and store the response.
542 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
543 Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
546 statusCode = res.getStatus();
551 // Check the status code of the response: does it match
552 // the expected response(s)?
553 if (logger.isDebugEnabled()) {
554 logger.debug(testName + ": status = " + statusCode);
556 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
557 invalidStatusCodeMessage(testRequestType, statusCode));
558 Assert.assertEquals(statusCode, testExpectedStatusCode);
561 protected String getServicePathItemsComponent() {
562 return AuthorityClient.ITEMS;
565 public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) {
566 PoxPayloadOut result = null;
568 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client = (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
569 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
570 PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
577 * Update an Authority item.
582 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
583 dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"})
584 public void updateItem(String testName) throws Exception {
587 AUTHORITY_ITEM_TYPE theUpdate = null;
589 // Retrieve the contents of a resource to update.
590 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
591 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
592 Response res = client.readItem(knownResourceId, knownItemResourceId);
594 if (logger.isDebugEnabled()) {
595 logger.debug(testName + ": read status = " + res.getStatus());
597 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
599 if (logger.isDebugEnabled()) {
600 logger.debug("got Authority item to update with ID: "
601 + knownItemResourceId
602 + " in authority: " + knownResourceId);
604 AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res);
605 Assert.assertNotNull(authorityItem);
607 // Update the contents of this resource.
608 theUpdate = updateItemInstance(authorityItem);
609 if (logger.isDebugEnabled()) {
610 logger.debug("\n\nTo be updated fields: CSID = " + knownItemResourceId + "\n"
611 + objectAsXmlString(theUpdate));
617 // Submit the updated resource to the service and store the response.
618 PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
619 res = client.updateItem(knownResourceId, knownItemResourceId, output);
621 int statusCode = res.getStatus();
623 // Check the status code of the response: does it match the expected response(s)?
624 if (logger.isDebugEnabled()) {
625 logger.debug("updateItem: status = " + statusCode);
627 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
628 invalidStatusCodeMessage(testRequestType, statusCode));
629 Assert.assertEquals(statusCode, testExpectedStatusCode);
631 // Retrieve the updated resource and verify that its contents exist.
632 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
633 Assert.assertNotNull(updatedVocabularyItem);
635 compareUpdatedItemInstances(theUpdate, updatedVocabularyItem);
641 protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
644 * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
646 @Test(dataProvider = "testName",
647 dependsOnMethods = {"create", "update", "updateNonExistent"})
648 public void updateNonExistentItem(String testName) throws Exception {
650 setupUpdateNonExistent();
652 // Submit the request to the service and store the response.
653 // Note: The ID used in this 'create' call may be arbitrary.
654 // The only relevant ID may be the one used in update(), below.
655 AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy> client =
656 (AuthorityClientImpl<AUTHORITY_ITEM_TYPE, AuthorityProxy>)this.getClientInstance();
657 PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
658 Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
660 int statusCode = res.getStatus();
662 // Check the status code of the response: does it match
663 // the expected response(s)?
664 if (logger.isDebugEnabled()) {
665 logger.debug(testName + ": status = " + statusCode);
667 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
668 invalidStatusCodeMessage(testRequestType, statusCode));
669 Assert.assertEquals(statusCode, testExpectedStatusCode);
676 // Methods to persuade TestNG to follow the correct test dependency path
679 @Test(dataProvider = "testName",
680 dependsOnMethods = {"createItem"})
681 public void baseAuthorityTests(String testName) {
682 // Do nothing. Here just to setup a test dependency chain.
686 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
687 * refer to this method in their @Test annotation declarations.
690 @Test(dataProvider = "testName",
692 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
693 public void CRUDTests(String testName) {
694 // TODO Auto-generated method stub
698 public void cleanUp() {
699 String noTest = System.getProperty("noTestCleanup");
700 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
701 if (logger.isDebugEnabled()) {
702 logger.debug("Skipping Cleanup phase ...");
707 AuthorityClient client = (AuthorityClient) this.getClientInstance();
708 String parentResourceId;
709 String itemResourceId;
711 // Clean up all authority item resources.
713 for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
714 itemResourceId = entry.getKey();
715 parentResourceId = entry.getValue();
716 Response response = client.deleteItem(parentResourceId, itemResourceId);
718 int status = response.getStatus();
719 if (status != Response.Status.OK.getStatusCode()) {
720 logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
721 itemResourceId, parentResourceId));
728 // Clean up authority items that were the result of a sync with the SAS
729 // all the IDs are URN (not CSIDs). The URNs work for the local items as well
732 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
733 itemResourceId = entry.getKey();
734 parentResourceId = entry.getValue();
735 // Note: Any non-success responses from the delete operation
736 // below are ignored and not reported.
737 client.deleteItem(parentResourceId, itemResourceId).close();
740 // Clean up authority items on the SAS using the SAS client.
742 client = (AuthorityClient) this.getSASClientInstance();
743 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
744 itemResourceId = entry.getKey();
745 parentResourceId = entry.getValue();
746 client.deleteItem(parentResourceId, itemResourceId).close();
749 // Finally, call out superclass's cleanUp method to deleted the local authorities
753 // Call out superclass's cleanUp method to delete the SAS authorities
755 super.cleanUp(client);
758 abstract protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId);