1 package org.collectionspace.services.client.test;
3 import java.util.ArrayList;
4 import java.util.HashMap;
8 import javax.ws.rs.core.Response;
10 import org.apache.http.HttpStatus;
11 import org.collectionspace.services.client.AbstractCommonListUtils;
12 import org.collectionspace.services.client.AuthorityClient;
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.PoxPayloadIn;
17 import org.collectionspace.services.client.PoxPayloadOut;
18 import org.collectionspace.services.client.RelationClient;
19 import org.collectionspace.services.client.XmlTools;
20 import org.collectionspace.services.client.workflow.WorkflowClient;
21 import org.collectionspace.services.description.ServiceDescription;
22 import org.collectionspace.services.jaxb.AbstractCommonList;
23 import org.collectionspace.services.relation.RelationsCommon;
24 import org.collectionspace.services.relation.RelationsCommonList;
25 import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
26 import org.collectionspace.services.relation.RelationshipType;
27 import org.dom4j.Document;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.testng.Assert;
31 import org.testng.SkipException;
32 import org.testng.annotations.Test;
38 * @param <AUTHORITY_COMMON_TYPE>
39 * @param <AUTHORITY_ITEM_TYPE>
41 * All CRUD related authority test classes should extend this class.
44 @SuppressWarnings("rawtypes")
45 public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE>
46 extends AbstractPoxServiceTestImpl<AbstractCommonList, AUTHORITY_COMMON_TYPE> {
48 private final Logger logger = LoggerFactory.getLogger(AbstractAuthorityServiceTest.class);
50 protected String knownResourceShortIdentifer = null;
51 protected static final String READITEMS_SHORT_IDENTIFIER = "resourceWithItems" + random.nextInt(1000);
52 protected String knownAuthorityWithItems = null;
53 protected String knownAuthorityWithItemsIdentifier = null;
55 protected static final String SAS_IDENTIFIER = "SAS";
56 protected static final String SAS_WITH_RELATIONS = "_RELATIONS_";
58 private static final int SAS_ITEMLIST_SIZE = 5;
60 protected String knownSASAuthorityResourceId = null;
61 protected String knownSASAuthorityResourceShortId = null;
62 protected List<String> knownSASItemIdentifiersList = new ArrayList<String>();
63 protected String knownSASItemResourceId = null;
64 protected HashMap<String, String> allSASResourceItemIdsCreated = new HashMap<String, String>(); /* itemURN, parentURN */;
66 protected String knownResourceRefName = null;
67 protected String knownItemResourceId = null;
68 protected String knownItemResourceShortIdentifer = null;
69 protected int nItemsToCreateInList = 5;
70 protected String TEST_SHORTID = "johnWayneActor";
72 protected List<String> knownSASItemIdentifiersWithRelationsList = new ArrayList<String>();
73 protected String knownSASAuthorityResourceWithRelationsId = null;
74 protected String knownSASAuthorityResourceWithRelationsShortId = null;
77 // Used to test hierarchical relationship synchronization
79 private String continentShortId;
80 private String countryShortId;
81 private String cityShortId;
84 * Abstract methods that subclasses must override/implement
91 public abstract void authorityTests(String testName);
100 abstract protected String createItemInAuthority(AuthorityClient client, String vcsid, String shortId) throws Exception;
105 * @param authorityItem
108 protected abstract AUTHORITY_ITEM_TYPE updateItemInstance(final AUTHORITY_ITEM_TYPE authorityItem);
116 protected abstract void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original,
117 AUTHORITY_ITEM_TYPE updated,
118 boolean compareRevNumbers) throws Exception;
126 protected void compareUpdatedItemInstances(AUTHORITY_ITEM_TYPE original,
127 AUTHORITY_ITEM_TYPE updated) throws Exception {
128 compareUpdatedItemInstances(original, updated, false);
134 * @param shortIdentifer
136 protected void setKnownItemResource(String id, String shortIdentifer ) {
137 knownItemResourceId = id;
138 knownItemResourceShortIdentifer = shortIdentifer;
144 * @param shortIdentifer
147 protected void setKnownResource(String id, String shortIdentifer,
149 knownResourceId = id;
150 knownResourceShortIdentifer = shortIdentifer;
151 knownResourceRefName = refName;
158 protected String getSASAuthorityIdentifier() {
159 return this.getKnowResourceIdentifier() + SAS_IDENTIFIER;
166 protected String getSASAuthorityWithRelationsIdentifier() {
167 return this.getKnowResourceIdentifier() + SAS_WITH_RELATIONS + SAS_IDENTIFIER;
175 protected String getUrnIdentifier(String shortId) {
176 return String.format("urn:cspace:name(%s)", shortId);
180 * Returns the CSID using the authority short ID. Passed in client must be for the correct authority type -i.e., the on
181 * that corresponds to the CSID.
183 protected String getCsidFromShortId(AuthorityClient client, String authShortId, String itemShortId) {
184 String result = null;
186 Response res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
188 result = extractCsid(res);
189 } catch (Exception e) {
190 logger.error(String.format("Could not get CSID for authority item '%s' in authority '%s' of type '%s'.",
191 itemShortId, authShortId, client.getServiceName()), e);
201 * Sets up create tests.
203 protected void setupSync() {
204 testExpectedStatusCode = STATUS_OK;
205 testRequestType = ServiceRequestType.SYNC;
206 testSetup(testExpectedStatusCode, testRequestType);
210 * Gets a client to the SAS (Shared Authority Server)
215 protected AuthorityClient getSASClientInstance() throws Exception {
216 return (AuthorityClient) this.getClientInstance(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
220 * Returns the root URL for a service.
222 * This URL consists of a base URL for all services, followed by
223 * a path component for the owning vocabulary, followed by the
224 * path component for the items.
226 * @return The root URL for a service.
228 protected String getItemServiceRootURL(String parentResourceIdentifier) {
229 return getResourceURL(parentResourceIdentifier) + "/" + getServicePathItemsComponent();
233 * Returns the URL of a specific resource managed by a service, and
234 * designated by an identifier (such as a universally unique ID, or UUID).
236 * @param resourceIdentifier An identifier (such as a UUID) for a resource.
238 * @return The URL of a specific resource managed by a service.
240 protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) {
241 return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier;
245 * For authorities we override this method so we can save the shortid.
248 protected String createWithIdentifier(String testName, String identifier) throws Exception {
249 String csid = createResource(testName, identifier);
250 // Store the ID returned from the first resource created
251 // for additional tests below.
252 if (getKnowResourceId() == null) {
253 setKnownResource(csid, identifier /*shortId*/, null /*refname*/ );
254 if (logger.isDebugEnabled()) {
255 logger.debug(testName + ": Setting knownResourceId=" + getKnowResourceId());
262 @Test(dependsOnMethods = {"readItem", "CRUDTests"})
263 public void testItemSubmitRequest() {
265 // Expected status code: 200 OK
266 final int EXPECTED_STATUS = Response.Status.OK.getStatusCode();
268 // Submit the request to the service and store the response.
269 String method = ServiceRequestType.READ.httpMethodName();
270 String url = getItemResourceURL(knownResourceId, knownItemResourceId);
271 int statusCode = submitRequest(method, url);
273 // Check the status code of the response: does it match
274 // the expected response(s)?
275 if (logger.isDebugEnabled()) {
276 logger.debug("testItemSubmitRequest: url=" + url
277 + " status=" + statusCode);
279 Assert.assertEquals(statusCode, EXPECTED_STATUS);
282 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
283 dependsOnMethods = {"readItem"})
284 public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
288 // Submit the request to the service and store the response.
289 AuthorityClient client = (AuthorityClient)this.getClientInstance();
290 Response res = client.readItem(knownResourceId, knownItemResourceId);
291 AUTHORITY_ITEM_TYPE vitem = null;
293 int statusCode = res.getStatus();
295 // Check the status code of the response: does it match
296 // the expected response(s)?
297 if (logger.isDebugEnabled()) {
298 logger.debug(testName + " read authority:" + knownResourceId + "/Item:"
299 + knownItemResourceId + " status = " + statusCode);
301 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
302 invalidStatusCodeMessage(testRequestType, statusCode));
303 Assert.assertEquals(statusCode, Response.Status.OK.getStatusCode());
305 vitem = extractItemCommonPartValue(res);
306 Assert.assertNotNull(vitem);
307 // Try to Update with new parent vocab (use self, for test).
308 Assert.assertEquals(client.getInAuthority(vitem), knownResourceId,
309 "VocabularyItem inAuthority does not match knownResourceId.");
310 client.setInAuthority(vitem, knownItemResourceId);
316 // Submit the updated resource to the service and store the response.
317 PoxPayloadOut output = this.createItemRequestTypeInstance(vitem);
318 res = client.updateItem(knownResourceId, knownItemResourceId, output);
320 int statusCode = res.getStatus();
322 // Check the status code of the response: does it match the expected response(s)?
323 if (logger.isDebugEnabled()) {
324 logger.debug(testName + ": status = " + statusCode);
326 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
327 invalidStatusCodeMessage(testRequestType, statusCode));
328 Assert.assertEquals(statusCode, testExpectedStatusCode);
333 res = client.readItem(knownResourceId, knownItemResourceId);
335 // Retrieve the updated resource and verify that the parent did not change
336 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
337 Assert.assertNotNull(updatedVocabularyItem);
339 // Verify that the updated resource received the correct data.
340 Assert.assertEquals(client.getInAuthority(updatedVocabularyItem),
342 "VocabularyItem allowed update to the parent (inAuthority).");
348 @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
349 public void createItem(String testName) throws Exception {
353 String newID = createItemInAuthority((AuthorityClient) getClientInstance(), knownResourceId, getTestAuthorityItemShortId());
355 // Store the ID returned from the first item resource created
356 // for additional tests below.
357 if (knownItemResourceId == null) {
358 knownItemResourceId = newID;
359 if (null != testName && logger.isDebugEnabled()) {
360 logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId);
366 * Verify that we can test synchronization with this authority. Otherwise, we skip the test.
369 private void assertSupportsSync() throws Exception {
371 // Test to see if the authority on our locally tenant supports sync
373 AuthorityClient client = (AuthorityClient) this.getClientInstance();
374 if (client.supportsSync() == false) {
375 throw new SkipException(String.format("Skipped the test since this authority '%s' doesn't support synchronization.",
376 client.getServiceName()));
379 // Test to see if the test tenancy's authority supports synchronization.
381 AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
382 if (sasClient.supportsSync() == false) {
383 String tenantName = sasClient.getTenantName();
384 throw new SkipException(String.format("Skipped the test since this authority '%s' doesn't support synchronization on the server's tenant '%s'.",
385 sasClient.getServiceName(), tenantName != null ? tenantName : "unknown"));
390 * Sync the local with the SAS
393 @Test(dataProvider = "testName", dependsOnMethods = {"createSASItemList", "CRUDTests"})
394 public void syncWithSAS(String testName) throws Exception {
396 // First check to see if the authority supports synchronization.
398 assertSupportsSync();
401 // Create an empty instance of the authority, so we can sync items with it. We're
402 // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
404 AuthorityClient client = (AuthorityClient) getClientInstance();
405 String localAuthorityId = null;
407 localAuthorityId = createResource(client, testName, knownSASAuthorityResourceShortId, false);
408 } catch (Exception e) {
409 Assert.assertNotNull(localAuthorityId);
413 // Now we can try to sync the SAS authority with the local one we just created.
416 Response response = client.syncByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
418 int statusCode = response.getStatus();
419 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
420 invalidStatusCodeMessage(testRequestType, statusCode));
421 Assert.assertEquals(statusCode, testExpectedStatusCode);
427 // Check to see if the parent authority (local) is in the "Replicated" state.
430 response = client.readByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
432 int statusCode = response.getStatus();
433 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
434 invalidStatusCodeMessage(testRequestType, statusCode));
435 Assert.assertEquals(statusCode, testExpectedStatusCode);
436 String workflowState = this.extractAuthorityWorkflowState(response);
437 Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // After a sync, the parent should be in the "Replicated" state
443 @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthorityWithRelations", "CRUDTests"})
444 public void syncWithSASWithRelations(String testName) throws Exception {
446 // First check to see if the authority supports synchronization.
448 assertSupportsSync();
451 // Create an empty instance of the authority, so we can sync items with it. We're
452 // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
454 AuthorityClient client = (AuthorityClient) this.getClientInstance();
455 String localAuthorityId = null;
457 localAuthorityId = createResource(client, testName, knownSASAuthorityResourceWithRelationsShortId, false);
458 } catch (Exception e) {
459 Assert.assertNotNull(localAuthorityId);
463 // Now we can try to sync the SAS authority with the local one we just created.
466 Response response = client.syncByName(knownSASAuthorityResourceWithRelationsShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
468 int statusCode = response.getStatus();
469 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
470 invalidStatusCodeMessage(testRequestType, statusCode));
471 Assert.assertEquals(statusCode, testExpectedStatusCode);
477 // Check to see if the parent authority (local) is in the "Replicated" state.
480 response = client.readByName(knownSASAuthorityResourceWithRelationsShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
482 int statusCode = response.getStatus();
483 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
484 invalidStatusCodeMessage(testRequestType, statusCode));
485 Assert.assertEquals(statusCode, testExpectedStatusCode);
486 String workflowState = this.extractAuthorityWorkflowState(response);
487 Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // After a sync, the parent should be in the "Replicated" state
494 * Check to make sure the sync with the SAS returned the correct number of items as well as items
495 * with the correct short IDs.
499 @Test(dataProvider = "testName", dependsOnMethods = {"syncWithSAS", "CRUDTests"})
500 public void veryifySyncWithSAS(String testName) throws Exception {
502 // First check to see if we support sync.
504 assertSupportsSync();
509 // Submit the request to the service and store the response.
510 AuthorityClient client = (AuthorityClient) getClientInstance();
512 res = client.readItemListForNamedAuthority(knownSASAuthorityResourceShortId, null, null);
515 int statusCode = res.getStatus();
517 // Check the status code of the response: does it match
518 // the expected response(s)?
519 if (logger.isDebugEnabled()) {
520 logger.debug(" " + testName + ": status = " + statusCode);
522 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
523 invalidStatusCodeMessage(testRequestType, statusCode));
524 Assert.assertEquals(statusCode, testExpectedStatusCode);
526 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
527 List<AbstractCommonList.ListItem> items = list.getListItem();
528 int nItemsReturned = items.size();
529 long nItemsTotal = list.getTotalItems();
530 if (logger.isDebugEnabled()) {
531 logger.debug(" " + testName + ": Expected "
532 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
534 Assert.assertEquals(nItemsTotal, SAS_ITEMLIST_SIZE);
536 // Verify that each of our local items has a corresponding remote item
538 for (AbstractCommonList.ListItem item : items) {
539 String shortId = AbstractCommonListUtils.ListItemGetElementValue(
540 item, AuthorityClient.SHORT_IDENTIFIER);
541 Assert.assertTrue(knownSASItemIdentifiersList.contains(shortId)); // The local short ID should be in SAS list
543 String workflowState = AbstractCommonListUtils.ListItemGetElementValue(
544 item, CollectionSpaceClient.COLLECTIONSPACE_CORE_WORKFLOWSTATE);
545 Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // Workflow state must show up in a "replicated" state
547 String refName = AbstractCommonListUtils.ListItemGetElementValue(
548 item, AuthorityClient.REF_NAME);
549 Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
550 String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
551 AuthorityClient.TERM_DISPLAY_NAME);
552 String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
553 AuthorityClient.VOCAB_DISPLAY_NAME);
554 // One of these names needs to be set.
555 Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
558 if(logger.isTraceEnabled()){
559 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
566 @Test(dataProvider = "testName", dependsOnMethods = {"syncWithSASWithRelations", "CRUDTests"})
567 public void veryifySyncWithSASWithRelations(String testName) throws Exception {
569 // First check to see if we support sync.
571 assertSupportsSync();
576 // Submit the request to the service and store the response.
577 AuthorityClient client = (AuthorityClient) getClientInstance();
579 res = client.readItemListForNamedAuthority(knownSASAuthorityResourceWithRelationsShortId, null, null);
582 int statusCode = res.getStatus();
583 // Check the status code of the response: does it match
584 // the expected response(s)?
585 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
586 invalidStatusCodeMessage(testRequestType, statusCode));
587 Assert.assertEquals(statusCode, testExpectedStatusCode);
589 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
590 long nItemsTotal = list.getTotalItems();
591 Assert.assertEquals(nItemsTotal, knownSASItemIdentifiersWithRelationsList.size());
593 // Verify that each of our local items has a corresponding remote item
595 List<AbstractCommonList.ListItem> itemList = list.getListItem();
596 for (AbstractCommonList.ListItem item : itemList) {
597 String shortId = AbstractCommonListUtils.ListItemGetElementValue(
598 item, AuthorityClient.SHORT_IDENTIFIER);
599 Assert.assertTrue(knownSASItemIdentifiersWithRelationsList.contains(shortId)); // The local short ID should be in SAS list
601 String workflowState = AbstractCommonListUtils.ListItemGetElementValue(
602 item, CollectionSpaceClient.COLLECTIONSPACE_CORE_WORKFLOWSTATE);
603 Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // Workflow state must show up in a "replicated" state
605 String refName = AbstractCommonListUtils.ListItemGetElementValue(
606 item, AuthorityClient.REF_NAME);
607 Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
608 String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
609 AuthorityClient.TERM_DISPLAY_NAME);
610 String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
611 AuthorityClient.VOCAB_DISPLAY_NAME);
612 // One of these names needs to be set.
613 Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
620 // Verify the relationship hierarchy is correct.
622 AuthorityClient authorityClient = (AuthorityClient) getClientInstance();
623 ServiceDescription serviceDescription = authorityClient.getServiceDescription();
624 final String authorityItemDocumentType = serviceDescription == null ? "unknown" : serviceDescription.getSubresourceDocumentType();
626 verifyBroaderRelationship(authorityClient, knownSASAuthorityResourceWithRelationsShortId, cityShortId, countryShortId, authorityItemDocumentType);
627 verifyBroaderRelationship(authorityClient, knownSASAuthorityResourceWithRelationsShortId, countryShortId, continentShortId, authorityItemDocumentType);
631 * Verifies a broader relationship exists between the subject and object.
633 * @param authorityClient
634 * @param authorityShortId
635 * @param subjectShortId
636 * @param objectShortId
637 * @param authorityItemDocumentType
640 private void verifyBroaderRelationship(AuthorityClient authorityClient, String authorityShortId, String subjectShortId, String objectShortId, String authorityItemDocumentType) throws Exception {
642 RelationClient relationClient = new RelationClient();
643 Response res = relationClient.readList(getCsidFromShortId(authorityClient, authorityShortId, subjectShortId),
644 authorityItemDocumentType,
645 RelationshipType.HAS_BROADER.value(),
646 getCsidFromShortId(authorityClient, authorityShortId, objectShortId),
647 authorityItemDocumentType);
649 int statusCode = res.getStatus();
650 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
651 invalidStatusCodeMessage(testRequestType, statusCode));
652 Assert.assertEquals(statusCode, testExpectedStatusCode);
654 RelationsCommonList list = (RelationsCommonList) res.readEntity(RelationsCommonList.class);
655 Assert.assertEquals(list.getTotalItems(), 1); // Should be exactly one relationship
656 RelationListItem relationListItem = list.getRelationListItem().get(0);
658 // Check the subject and object refnames to see if the contain the correct short identifiers
660 Assert.assertTrue(relationListItem.getSubject().getRefName().contains(subjectShortId)); // The subject refname should contain our known short ID
661 Assert.assertTrue(relationListItem.getSubject().getRefName().contains(authorityShortId)); // The subject refname should contain our known short ID
662 // Now check the object refname
663 Assert.assertTrue(relationListItem.getObject().getRefName().contains(objectShortId)); // The object refname should contain our known short ID
664 Assert.assertTrue(relationListItem.getObject().getRefName().contains(authorityShortId)); // The object refname should contain our known short ID
671 * SAS - Create a new authority on the SAS server.
675 @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
676 public void createSASAuthority(String testName) throws Exception {
678 // First check to see if the authority supports synchronization.
680 assertSupportsSync();
686 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityIdentifier(), true);
687 knownSASAuthorityResourceId = newID;
688 knownSASAuthorityResourceShortId = getShortId(getSASClientInstance(), knownSASAuthorityResourceId);
689 if (logger.isDebugEnabled()) {
690 String.format("Created SAS authority '%s' with CSID=%s.", getSASAuthorityIdentifier(), newID);
692 } catch (Exception e) {
693 logger.info(String.format("Failed to create SAS authority '%s'.", getSASAuthorityIdentifier()));
697 @Test(dataProvider = "testName", dependsOnMethods = {"deleteLocalItemWithSync", "CRUDTests"})
698 public void createSASAuthorityWithRelations(String testName) throws Exception {
700 // First check to see if the authority supports synchronization.
702 assertSupportsSync();
707 // Create a new authority on the remote server
709 AuthorityClient client = (AuthorityClient) getClientInstance();
711 String newID = createResource(getSASClientInstance(), testName, getSASAuthorityWithRelationsIdentifier(), true);
712 knownSASAuthorityResourceWithRelationsId = newID;
713 knownSASAuthorityResourceWithRelationsShortId = getShortId(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId);
714 } catch (Exception e) {
715 logger.info(String.format("Failed to create SAS authority with relations '%s'.", getSASAuthorityWithRelationsIdentifier()));
718 // Add three items to the remote authority
720 continentShortId = "Continent" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
721 String continentCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, continentShortId);
722 knownSASItemIdentifiersWithRelationsList.add(continentShortId);
723 allSASResourceItemIdsCreated.put(this.getUrnIdentifier(continentShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
725 countryShortId = "Country" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
726 String countryCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, countryShortId);
727 knownSASItemIdentifiersWithRelationsList.add(countryShortId);
728 allSASResourceItemIdsCreated.put(this.getUrnIdentifier(countryShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
730 cityShortId = "City" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
731 String cityCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, cityShortId);
732 knownSASItemIdentifiersWithRelationsList.add(cityShortId);
733 allSASResourceItemIdsCreated.put(this.getUrnIdentifier(cityShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
735 // Create a set of hierarchical relationships between the items
737 ServiceDescription serviceDescription = client.getServiceDescription();
738 final String authorityItemDocumentType = serviceDescription == null ? "unknown" : serviceDescription.getSubresourceDocumentType();
739 RelationClient relationClient = new RelationClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME); // Get a Relation service client to the SAS
741 boolean success = false;
743 createBroaderRelationship(relationClient, cityCSID, countryCSID, authorityItemDocumentType);
744 createBroaderRelationship(relationClient, countryCSID, continentCSID, authorityItemDocumentType);
746 } catch (Exception e) {
747 logger.error(e.getMessage());
750 Assert.assertTrue(success);
754 * Creates a broader relationship record between the subject and the object
755 * @param relationClient
758 private void createBroaderRelationship(RelationClient relationClient, String subjectCSID, String objectCSID, String docType) throws Exception {
759 RelationsCommon relationCommon = new RelationsCommon();
761 relationCommon.setSubjectCsid(subjectCSID);
762 relationCommon.setSubjectDocumentType(docType);
763 relationCommon.setObjectCsid(objectCSID);
764 relationCommon.setObjectDocumentType(docType);
765 relationCommon.setRelationshipType(RelationshipType.HAS_BROADER.value());
766 relationCommon.setPredicateDisplayName(RelationshipType.HAS_BROADER.value());
768 PoxPayloadOut payloadOut = relationClient.createRequestTypeInstance(relationCommon);
769 Response res = relationClient.create(payloadOut);
771 if (res.getStatus() == HttpStatus.SC_CREATED) {
772 String relationCSID = extractId(res);
773 allRelationResourceIdsCreated.add(relationCSID); // keep track of what we create so we can cleanup later
775 String errMsg = "Could not create Relationship.";
776 logger.error(errMsg);
777 throw new Exception(errMsg);
785 * SAS - Create an item in the SAS authority on the SAS server.
789 @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
790 public void createSASItemList(String testName) throws Exception {
792 // First check to see if the authority supports synchronization.
794 assertSupportsSync();
796 // Perform setup for create.
799 for (int i = 0; i < SAS_ITEMLIST_SIZE; i++) {
800 String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
801 String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
803 // Store the ID returned from the first item resource created
804 // for additional tests below.
805 if (knownSASItemResourceId == null) {
806 knownSASItemResourceId = newID;
807 if (null != testName && logger.isDebugEnabled()) {
808 logger.debug(testName + ": knownSASItemResourceId=" + knownSASItemResourceId);
812 knownSASItemIdentifiersList.add(shortId);
815 // Keep track of the SAS authority items we create, so we can delete them from
816 // the *local* authority after we perform a sync operation. We need to keep track
817 // of the URN (not the CSID) since the CSIDs will differ on the SAS vs local.
819 this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(shortId), getUrnIdentifier(knownSASAuthorityResourceShortId));
824 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
825 dependsOnMethods = {"createItem"})
826 public void createItemList(String testName) throws Exception {
827 knownAuthorityWithItems = createResource(testName, READITEMS_SHORT_IDENTIFIER);
828 knownAuthorityWithItemsIdentifier = getShortId(knownAuthorityWithItems);
829 for (int j = 0; j < nItemsToCreateInList; j++) {
830 createItemInAuthority((AuthorityClient) getClientInstance(), knownAuthorityWithItems, this.getTestAuthorityItemShortId(true));
834 private String getShortId(AuthorityClient client, String authorityCsid) throws Exception {
835 String result = null;
837 // Submit the request to the service and store the response.
838 Response res = client.read(authorityCsid);
840 int statusCode = res.getStatus();
841 result = this.extractAuthorityShortId(res);
849 private String getShortId(String authorityCsid) throws Exception {
850 AuthorityClient client = (AuthorityClient) getClientInstance();
851 return getShortId(client, authorityCsid);
857 * @param testName the test name
858 * @throws Exception the exception
860 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
861 dependsOnMethods = {"CRUDTests"})
862 public void readByName(String testName) throws Exception {
866 // Submit the request to the service and store the response.
867 AuthorityClient client = (AuthorityClient) this.getClientInstance();
868 Response res = client.readByName(getKnowResourceIdentifier());
870 int statusCode = res.getStatus();
872 // Check the status code of the response: does it match
873 // the expected response(s)?
874 if (logger.isDebugEnabled()) {
875 logger.debug(testName + ": status = " + statusCode);
877 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
878 invalidStatusCodeMessage(testRequestType, statusCode));
879 Assert.assertEquals(statusCode, testExpectedStatusCode);
881 AUTHORITY_COMMON_TYPE commonPart = extractCommonPartValue(res);
882 Assert.assertNotNull(commonPart);
889 * Extracts the common part item from a service's item payload.
895 public AUTHORITY_ITEM_TYPE extractItemCommonPartValue(Response res) throws Exception {
896 AUTHORITY_ITEM_TYPE result = null;
898 AuthorityClient client = (AuthorityClient) getClientInstance();
899 PayloadInputPart payloadInputPart = extractPart(res, client.getItemCommonPartName());
900 if (payloadInputPart != null) {
901 result = (AUTHORITY_ITEM_TYPE) payloadInputPart.getBody();
903 Assert.assertNotNull(result,
904 "Part or body of part " + client.getCommonPartName() + " was unexpectedly null.");
911 * Extracts the short ID from a service request payload
917 protected String extractAuthorityShortId(Response res) throws Exception {
918 String result = null;
920 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
921 Document document = input.getDOMDocument();
922 result = XmlTools.getElementValue(document, "//" + AuthorityClient.SHORT_IDENTIFIER);
927 protected String extractCsid(Response res) throws Exception {
928 String result = null;
930 PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
931 Document document = input.getDOMDocument();
932 result = XmlTools.getElementValue(document, "//" + AuthorityClient.COLLECTIONSPACE_CORE_CSID);
937 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
938 dependsOnMethods = {"readItem"})
939 public void readItemNonExistent(String testName) throws Exception {
941 setupReadNonExistent();
943 // Submit the request to the service and store the response.
944 AuthorityClient client = (AuthorityClient) getClientInstance();
945 Response res = client.readItem(knownResourceId, NON_EXISTENT_ID);
947 int statusCode = res.getStatus();
949 // Check the status code of the response: does it match
950 // the expected response(s)?
951 if (logger.isDebugEnabled()) {
952 logger.debug(testName + ": status = " + statusCode);
954 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
955 invalidStatusCodeMessage(testRequestType, statusCode));
956 Assert.assertEquals(statusCode, testExpectedStatusCode);
962 @Test(dataProvider = "testName",
963 dependsOnMethods = {"createItem"})
964 public void readItem(String testName) throws Exception {
968 // Submit the request to the service and store the response.
969 AuthorityClient client = (AuthorityClient) getClientInstance();
970 Response res = client.readItem(knownResourceId, knownItemResourceId);
972 int statusCode = res.getStatus();
974 // Check the status code of the response: does it match
975 // the expected response(s)?
976 if (logger.isDebugEnabled()) {
977 logger.debug(testName + ": status = " + statusCode);
979 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
980 invalidStatusCodeMessage(testRequestType, statusCode));
981 Assert.assertEquals(statusCode, testExpectedStatusCode);
983 AUTHORITY_ITEM_TYPE itemCommonPart = extractItemCommonPartValue(res);
984 Assert.assertNotNull(itemCommonPart);
985 Assert.assertEquals(client.getInAuthority(itemCommonPart), knownResourceId);
986 verifyReadItemInstance(itemCommonPart);
992 protected abstract void verifyReadItemInstance(AUTHORITY_ITEM_TYPE item) throws Exception;
994 @Test(dataProvider = "testName",
995 dependsOnMethods = {"testItemSubmitRequest", "updateItem", "verifyIgnoredUpdateWithInAuthority"})
996 public void deleteItem(String testName) throws Exception {
1000 // Submit the request to the service and store the response.
1001 AuthorityClient client = (AuthorityClient) getClientInstance();
1002 Response res = client.deleteItem(knownResourceId, knownItemResourceId);
1005 statusCode = res.getStatus();
1010 // Check the status code of the response: does it match
1011 // the expected response(s)?
1012 if (logger.isDebugEnabled()) {
1013 logger.debug("delete: status = " + statusCode);
1015 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1016 invalidStatusCodeMessage(testRequestType, statusCode));
1017 Assert.assertEquals(statusCode, testExpectedStatusCode);
1020 protected void readItemListInt(String vcsid, String shortId, String testName) throws Exception {
1024 // Submit the request to the service and store the response.
1025 AuthorityClient client = (AuthorityClient) getClientInstance();
1026 Response res = null;
1027 if (vcsid != null) {
1028 res = client.readItemList(vcsid, null, null);
1029 } else if (shortId != null) {
1030 res = client.readItemListForNamedAuthority(shortId, null, null);
1032 Assert.fail("Internal Error: readItemList both vcsid and shortId are null!");
1035 int statusCode = res.getStatus();
1037 // Check the status code of the response: does it match
1038 // the expected response(s)?
1039 if (logger.isDebugEnabled()) {
1040 logger.debug(" " + testName + ": status = " + statusCode);
1042 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1043 invalidStatusCodeMessage(testRequestType, statusCode));
1044 Assert.assertEquals(statusCode, testExpectedStatusCode);
1046 AbstractCommonList list = res.readEntity(AbstractCommonList.class);
1047 List<AbstractCommonList.ListItem> items = list.getListItem();
1048 int nItemsReturned = items.size();
1049 long nItemsTotal = list.getTotalItems();
1050 if (logger.isDebugEnabled()) {
1051 logger.debug(" " + testName + ": Expected "
1052 + nItemsToCreateInList + " items; got: " + nItemsReturned + " of: " + nItemsTotal);
1054 Assert.assertEquals(nItemsTotal, nItemsToCreateInList);
1056 for (AbstractCommonList.ListItem item : items) {
1057 String refName = AbstractCommonListUtils.ListItemGetElementValue(
1058 item, AuthorityClient.REF_NAME);
1059 Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
1060 String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
1061 AuthorityClient.TERM_DISPLAY_NAME);
1062 String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
1063 AuthorityClient.VOCAB_DISPLAY_NAME);
1064 // One of these names needs to be set.
1065 Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
1068 if(logger.isTraceEnabled()){
1069 AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
1076 @Test(dataProvider = "testName", dependsOnMethods = {"createItemList"})
1077 public void readItemList(String testName) throws Exception {
1078 readItemListInt(knownAuthorityWithItems, null, testName);
1081 @Test(dataProvider = "testName", dependsOnMethods = {"readItemList"})
1082 public void readItemListByName(String testName) throws Exception {
1083 readItemListInt(null, knownAuthorityWithItemsIdentifier, testName);
1086 @Test(dataProvider = "testName",
1087 dependsOnMethods = {"deleteItem"})
1088 public void deleteNonExistentItem(String testName) throws Exception {
1090 setupDeleteNonExistent();
1092 // Submit the request to the service and store the response.
1093 AuthorityClient client = (AuthorityClient) getClientInstance();
1094 Response res = client.deleteItem(knownResourceId, NON_EXISTENT_ID);
1097 statusCode = res.getStatus();
1102 // Check the status code of the response: does it match
1103 // the expected response(s)?
1104 if (logger.isDebugEnabled()) {
1105 logger.debug(testName + ": status = " + statusCode);
1107 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1108 invalidStatusCodeMessage(testRequestType, statusCode));
1109 Assert.assertEquals(statusCode, testExpectedStatusCode);
1112 protected String getServicePathItemsComponent() {
1113 return AuthorityClient.ITEMS;
1116 public PoxPayloadOut createItemRequestTypeInstance(AUTHORITY_ITEM_TYPE itemTypeInstance) throws Exception {
1117 PoxPayloadOut result = null;
1119 AuthorityClient client = (AuthorityClient) getClientInstance();
1120 PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
1121 payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
1122 result = payloadOut;
1128 * Update an Authority item.
1133 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1134 dependsOnMethods = {"readItem", "CRUDTests", "verifyIgnoredUpdateWithInAuthority"})
1135 public void updateItem(String testName) throws Exception {
1138 AUTHORITY_ITEM_TYPE theUpdate = null;
1140 // Retrieve the contents of a resource to update.
1141 AuthorityClient client = (AuthorityClient)this.getClientInstance();
1142 Response res = client.readItem(knownResourceId, knownItemResourceId);
1144 if (logger.isDebugEnabled()) {
1145 logger.debug(testName + ": read status = " + res.getStatus());
1147 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1149 if (logger.isDebugEnabled()) {
1150 logger.debug("got Authority item to update with ID: "
1151 + knownItemResourceId
1152 + " in authority: " + knownResourceId);
1154 AUTHORITY_ITEM_TYPE authorityItem = extractItemCommonPartValue(res);
1155 Assert.assertNotNull(authorityItem);
1157 // Update the contents of this resource.
1158 theUpdate = updateItemInstance(authorityItem);
1159 if (logger.isDebugEnabled()) {
1160 logger.debug("\n\nTo be updated fields: CSID = " + knownItemResourceId + "\n"
1161 + objectAsXmlString(theUpdate));
1167 // Submit the updated resource to the service and store the response.
1168 PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
1169 res = client.updateItem(knownResourceId, knownItemResourceId, output);
1171 int statusCode = res.getStatus();
1173 // Check the status code of the response: does it match the expected response(s)?
1174 if (logger.isDebugEnabled()) {
1175 logger.debug("updateItem: status = " + statusCode);
1177 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1178 invalidStatusCodeMessage(testRequestType, statusCode));
1179 Assert.assertEquals(statusCode, testExpectedStatusCode);
1181 // Retrieve the updated resource and verify that its contents exist.
1182 AUTHORITY_ITEM_TYPE updatedVocabularyItem = extractItemCommonPartValue(res);
1183 Assert.assertNotNull(updatedVocabularyItem);
1185 compareUpdatedItemInstances(theUpdate, updatedVocabularyItem);
1191 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1192 dependsOnMethods = {"updateLocalItemWithSync", "CRUDTests"})
1193 public void deleteLocalItemWithSync(String testName) throws Exception {
1194 final int itemIndexToDelete = 1;
1196 // First check to see if we support sync.
1198 assertSupportsSync();
1200 // Perform test setup for a DELETE.
1203 // Delete an item from the SAS server
1204 AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
1205 Response res = sasClient.deleteNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(itemIndexToDelete));
1207 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1212 // Synchronize the local item's parent authority and verify the delete we just made
1213 // to the SAS takes place locally after the sync -i.e., the local item should be deleted as well.
1215 AuthorityClient localClient = (AuthorityClient) this.getClientInstance();
1216 Response response = localClient.syncByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
1218 int statusCode = response.getStatus();
1219 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode));
1220 Assert.assertEquals(statusCode, testExpectedStatusCode);
1225 // Verify that the local item has been deleted.
1226 setupReadNonExistent();
1227 res = localClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(itemIndexToDelete));
1229 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1230 knownSASItemIdentifiersList.remove(0); // remove it from our known set now that we've deleted it
1237 * We create a new item on the SAS, perform a sync with the local authority, and verify the local authority contains a copy
1240 @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
1241 dependsOnMethods = {"veryifySyncWithSAS", "CRUDTests"})
1242 public void updateLocalItemWithSync(String testName) throws Exception {
1244 // First check to see if we support sync.
1246 assertSupportsSync();
1251 // Retrieve the contents of a shared authority item that we're going to update.
1252 AUTHORITY_ITEM_TYPE theUpdate = null;
1253 AUTHORITY_ITEM_TYPE sasAuthorityItem = null;
1254 AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
1255 Response res = sasClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(0));
1257 if (logger.isDebugEnabled()) {
1258 logger.debug(testName + ": read status = " + res.getStatus());
1260 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1262 sasAuthorityItem = extractItemCommonPartValue(res); // This is a SAS authority item
1263 Assert.assertNotNull(sasAuthorityItem);
1268 // Update the contents of this authority item so we can post an UPDATE to the server
1269 theUpdate = updateItemInstance(sasAuthorityItem);
1271 // Submit the updated authority item and check the response.
1272 PoxPayloadOut output = this.createItemRequestTypeInstance(theUpdate);
1273 res = sasClient.updateNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(0), output);
1274 AUTHORITY_ITEM_TYPE updatedSASAuthorityItem = null;
1276 int statusCode = res.getStatus();
1278 // Check the status code of the response: does it match the expected response(s)?
1279 if (logger.isDebugEnabled()) {
1280 logger.debug("updateItem: status = " + statusCode);
1282 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1283 invalidStatusCodeMessage(testRequestType, statusCode));
1284 Assert.assertEquals(statusCode, testExpectedStatusCode);
1286 // Retrieve the updated authority item and verify that its contents exist.
1287 updatedSASAuthorityItem = extractItemCommonPartValue(res);
1288 Assert.assertNotNull(updatedSASAuthorityItem);
1290 compareUpdatedItemInstances(theUpdate, updatedSASAuthorityItem);
1295 // Synchronize the local item's parent authority and verify the update we just made
1296 // to the SAS item appears locally after the sync
1298 AuthorityClient localClient = (AuthorityClient) this.getClientInstance();
1299 Response response = localClient.syncByName(knownSASAuthorityResourceShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
1301 int statusCode = response.getStatus();
1302 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode));
1303 Assert.assertEquals(statusCode, testExpectedStatusCode);
1309 res = localClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(0));
1311 Assert.assertEquals(res.getStatus(), testExpectedStatusCode);
1312 AUTHORITY_ITEM_TYPE syncedAuthorityItem = extractItemCommonPartValue(res);
1313 Assert.assertNotNull(syncedAuthorityItem);
1314 compareUpdatedItemInstances(syncedAuthorityItem, updatedSASAuthorityItem);
1320 protected abstract PoxPayloadOut createNonExistenceItemInstance(String commonPartName, String identifier);
1323 * @see org.collectionspace.services.client.test.ServiceTest#updateNonExistent(java.lang.String)
1325 @Test(dataProvider = "testName",
1326 dependsOnMethods = {"create", "update", "updateNonExistent"})
1327 public void updateNonExistentItem(String testName) throws Exception {
1329 setupUpdateNonExistent();
1331 // Submit the request to the service and store the response.
1332 // Note: The ID used in this 'create' call may be arbitrary.
1333 // The only relevant ID may be the one used in update(), below.
1334 AuthorityClient client = (AuthorityClient)this.getClientInstance();
1335 PoxPayloadOut multipart = createNonExistenceItemInstance(client.getItemCommonPartName(), NON_EXISTENT_ID);
1336 Response res = client.updateItem(knownResourceId, NON_EXISTENT_ID, multipart);
1338 int statusCode = res.getStatus();
1340 // Check the status code of the response: does it match
1341 // the expected response(s)?
1342 if (logger.isDebugEnabled()) {
1343 logger.debug(testName + ": status = " + statusCode);
1345 Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
1346 invalidStatusCodeMessage(testRequestType, statusCode));
1347 Assert.assertEquals(statusCode, testExpectedStatusCode);
1354 // Methods to persuade TestNG to follow the correct test dependency path
1357 @Test(dataProvider = "testName",
1358 dependsOnMethods = {"createItem"})
1359 public void baseAuthorityTests(String testName) {
1360 // Do nothing. Here just to setup a test dependency chain.
1364 * For convenience and terseness, this test method is the base of the test execution dependency chain. Other test methods may
1365 * refer to this method in their @Test annotation declarations.
1368 @Test(dataProvider = "testName",
1369 dependsOnMethods = {
1370 "org.collectionspace.services.client.test.AbstractServiceTestImpl.baseCRUDTests"})
1371 public void CRUDTests(String testName) {
1372 // TODO Auto-generated method stub
1376 public void cleanUp() throws Exception {
1377 String noTest = System.getProperty("noTestCleanup");
1378 if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) {
1379 if (logger.isDebugEnabled()) {
1380 logger.debug("Skipping Cleanup phase ...");
1385 AuthorityClient client = (AuthorityClient) this.getClientInstance();
1386 String parentResourceId;
1387 String itemResourceId;
1389 // Clean up all authority item resources.
1391 for (Map.Entry<String, String> entry : allResourceItemIdsCreated.entrySet()) {
1392 itemResourceId = entry.getKey();
1393 parentResourceId = entry.getValue();
1394 Response response = client.deleteItem(parentResourceId, itemResourceId);
1396 int status = response.getStatus();
1397 if (status != Response.Status.OK.getStatusCode()) {
1398 logger.debug(String.format("Could not deleted authority item '%s' in authority '%s'.",
1399 itemResourceId, parentResourceId));
1406 // Clean up authority items that were the result of a sync with the SAS
1407 // all the IDs are URN (not CSIDs). The URNs work for the local items as well
1408 // as the SAS items.
1410 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
1411 itemResourceId = entry.getKey();
1412 parentResourceId = entry.getValue();
1413 // Note: Any non-success responses from the delete operation
1414 // below are ignored and not reported.
1415 client.deleteItem(parentResourceId, itemResourceId).close();
1418 // Clean up authority items on the SAS using the SAS client.
1420 AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
1421 for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
1422 itemResourceId = entry.getKey();
1423 parentResourceId = entry.getValue();
1424 sasClient.deleteItem(parentResourceId, itemResourceId).close();
1427 // Finally, call out superclass's cleanUp method to deleted the local authorities
1431 // Call out superclass's cleanUp method to delete the SAS authorities
1433 super.cleanUp(sasClient);
1436 protected String getTestAuthorityItemShortId() {
1437 return getTestAuthorityItemShortId(false);
1440 protected String getTestAuthorityItemShortId(boolean makeUnique) {
1441 String result = TEST_SHORTID;
1443 if (makeUnique == true) {
1444 result = result + System.currentTimeMillis() + Math.abs(random.nextInt());