import javax.xml.bind.Marshaller;
import org.testng.Assert;
+import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
import org.collectionspace.services.client.CollectionObjectClient;
import org.collectionspace.services.client.DimensionClient;
import org.collectionspace.services.client.DimensionFactory;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.collectionobject.CollectionobjectsCommon;
-
import org.collectionspace.services.client.IntakeClient;
import org.collectionspace.services.intake.IntakesCommon;
-
import org.collectionspace.services.client.RelationClient;
import org.collectionspace.services.client.workflow.WorkflowClient;
import org.collectionspace.services.dimension.DimensionsCommon;
private static final int OBJECTS_TO_INTAKE = 1;
+ @AfterClass(alwaysRun = true)
+ public void cleanUp() {
+ relationClient.cleanup();
+ collectionObjectClient.cleanup();
+ intakeClient.cleanup();
+ dimensionClient.cleanup();
+ }
+
/**
* Object as xml string.
*
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
+ collectionObjectClient.addToCleanup(collectionObjectCsid);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid1 = extractId(response);
+ dimensionClient.addToCleanup(dimensionCsid1);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid1 = extractId(response);
+ relationClient.addToCleanup(relationCsid1);
} finally {
response.close();
}
// Now lock the dimension record.
- @SuppressWarnings("unused")
- Response workflowResponse = dimensionClient.updateWorkflowWithTransition(
- dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_LOCK);
- System.out.println("Locked dimension record with CSID=" + dimensionCsid1);
- workflowResponse.close();
+ Response workflowResponse = null;
+ try {
+ workflowResponse = dimensionClient.updateWorkflowWithTransition(
+ dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_LOCK);
+ System.out.println("Locked dimension record with CSID=" + dimensionCsid1);
+ } finally {
+ workflowResponse.close();
+ }
// Finally, try to delete the relationship
workflowResponse = dimensionClient.updateWorkflowWithTransition(dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_DELETE);
System.out.println("Locked dimension record with CSID=" + dimensionCsid1);
workflowResponse.close();
+
+ // Now unlock the dimension record so we can cleanup all the records after the test suite completes.
+ try {
+ workflowResponse = dimensionClient.updateWorkflowWithTransition(
+ dimensionCsid1, WorkflowClient.WORKFLOWTRANSITION_UNLOCK);
+ } finally {
+ workflowResponse.close();
+ }
}
@Test void createCollectionObjectRelationshipToManyDimensions() {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
+ collectionObjectClient.addToCleanup(collectionObjectCsid);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid1 = extractId(response);
+ dimensionClient.addToCleanup(dimensionCsid1);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid2 = extractId(response);
+ dimensionClient.addToCleanup(dimensionCsid2);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
dimensionCsid3 = extractId(response);
+ dimensionClient.addToCleanup(dimensionCsid3);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid1 = extractId(response);
+ relationClient.addToCleanup(relationCsid1);
} finally {
response.close();
}
commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
// Create the relationship
response = relationClient.create(multipart);
- @SuppressWarnings("unused")
+
String relationCsid2 = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid2 = extractId(response);
+ relationClient.addToCleanup(relationCsid2);
} finally {
response.close();
}
commonPart = multipart.addPart(relationClient.getCommonPartName(), relation);
// Create the relationship
response = relationClient.create(multipart);
- @SuppressWarnings("unused")
+
String relationCsid3 = null;
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid3 = extractId(response);
+ relationClient.addToCleanup(relationCsid3);
} finally {
response.close();
}
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
+ collectionObjectClient.addToCleanup(collectionObjectCsid);
} finally {
response.close();
}
commonPart = multipart.addPart(relation, MediaType.APPLICATION_XML_TYPE);
commonPart.setLabel(relationClient.getCommonPartName());
- // Make the call to crate
+ // Make the call to create the relationship
Response relationresponse = relationClient.create(multipart);
String relationCsid = null;
try {
Assert.assertEquals(relationresponse.getStatus(), Response.Status.BAD_REQUEST.getStatusCode());
relationCsid = extractId(response);
+ relationClient.addToCleanup(relationCsid);
} finally {
relationresponse.close();
}
+
+ // Now unlock the dimension record so we can cleanup all the records after the test suite completes.
+ try {
+ workflowResponse = dimensionClient.updateWorkflowWithTransition(
+ dimensionCsid, WorkflowClient.WORKFLOWTRANSITION_UNLOCK);
+ } finally {
+ workflowResponse.close();
+ }
}
@Test
Assert.assertEquals(response.getStatus(), Response.Status.CREATED
.getStatusCode());
collectionObjectCsid = extractId(response);
+ collectionObjectClient.addToCleanup(collectionObjectCsid);
} finally {
response.close();
}
-
// Next, create an Intake object
IntakesCommon intake = new IntakesCommon();
fillIntake(intake, createIdentifier());
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
intakeCsid = extractId(response);
+ intakeClient.addToCleanup(intakeCsid);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid = extractId(response);
+ relationClient.addToCleanup(relationCsid);
} finally {
response.close();
}
.getStatusCode());
collectionObjectCsid = extractId(response);
collectionObjectIDList.add(collectionObjectCsid);
+ collectionObjectClient.addToCleanup(collectionObjectCsid);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
intakeCsid = extractId(response);
+ intakeClient.addToCleanup(intakeCsid);
} finally {
response.close();
}
try {
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());
relationCsid = extractId(response);
+ relationClient.addToCleanup(relationCsid);
} finally {
response.close();
}
import java.util.Map;
import javax.ws.rs.core.Response;
-import org.apache.http.HttpStatus;
+import org.apache.http.HttpStatus;
import org.collectionspace.services.client.AbstractCommonListUtils;
import org.collectionspace.services.client.AuthorityClient;
import org.collectionspace.services.client.CollectionSpaceClient;
import org.collectionspace.services.description.ServiceDescription;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.relation.RelationsCommon;
+import org.collectionspace.services.relation.RelationsCommonList;
+import org.collectionspace.services.relation.RelationsCommonList.RelationListItem;
import org.collectionspace.services.relation.RelationshipType;
-
import org.dom4j.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
+import org.testng.SkipException;
import org.testng.annotations.Test;
/**
* All CRUD related authority test classes should extend this class.
*
*/
+@SuppressWarnings("rawtypes")
public abstract class AbstractAuthorityServiceTest<AUTHORITY_COMMON_TYPE, AUTHORITY_ITEM_TYPE>
extends AbstractPoxServiceTestImpl<AbstractCommonList, AUTHORITY_COMMON_TYPE> {
protected int nItemsToCreateInList = 5;
protected String TEST_SHORTID = "johnWayneActor";
+ protected List<String> knownSASItemIdentifiersWithRelationsList = new ArrayList<String>();
protected String knownSASAuthorityResourceWithRelationsId = null;
protected String knownSASAuthorityResourceWithRelationsShortId = null;
+ //
+ // Used to test hierarchical relationship synchronization
+ //
+ private String continentShortId;
+ private String countryShortId;
+ private String cityShortId;
+
/*
* Abstract methods that subclasses must override/implement
*/
return String.format("urn:cspace:name(%s)", shortId);
}
+ /*
+ * Returns the CSID using the authority short ID. Passed in client must be for the correct authority type -i.e., the on
+ * that corresponds to the CSID.
+ */
+ protected String getCsidFromShortId(AuthorityClient client, String authShortId, String itemShortId) {
+ String result = null;
+
+ Response res = client.readNamedItemInNamedAuthority(authShortId, itemShortId);
+ try {
+ result = extractCsid(res);
+ } catch (Exception e) {
+ logger.error(String.format("Could not get CSID for authority item '%s' in authority '%s' of type '%s'.",
+ itemShortId, authShortId, client.getServiceName()), e);
+ } finally {
+ res.close();
+ }
+
+ return result;
+ }
+
+
/**
* Sets up create tests.
*/
protected void setupSync() {
- testExpectedStatusCode = this.STATUS_OK;
+ testExpectedStatusCode = STATUS_OK;
testRequestType = ServiceRequestType.SYNC;
testSetup(testExpectedStatusCode, testRequestType);
}
*
* @return the client
*/
- protected AuthorityClient getSASClientInstance() {
+ protected AuthorityClient getSASClientInstance() {
return (AuthorityClient) this.getClientInstance(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME);
}
Assert.assertEquals(statusCode, EXPECTED_STATUS);
}
-
- @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readItem"})
public void verifyIgnoredUpdateWithInAuthority(String testName) throws Exception {
// Perform setup.
}
}
- @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"CRUDTests"})
public void createItem(String testName) {
// Perform setup.
setupCreate();
}
}
}
+
+ /**
+ * Verify that we can test synchronization with this authority. Otherwise, we skip the test.
+ */
+ private void assertSupportsSync() {
+ //
+ // Test to see if the authority on our locally tenant supports sync
+ //
+ AuthorityClient client = (AuthorityClient) this.getClientInstance();
+ if (client.supportsSync() == false) {
+ throw new SkipException(String.format("Skipped the test since this authority '%s' doesn't support synchronization.",
+ client.getServiceName()));
+ }
+ //
+ // Test to see if the test tenancy's authority supports synchronization.
+ //
+ AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
+ if (sasClient.supportsSync() == false) {
+ String tenantName = sasClient.getTenantName();
+ throw new SkipException(String.format("Skipped the test since this authority '%s' doesn't support synchronization on the server's tenant '%s'.",
+ sasClient.getServiceName(), tenantName != null ? tenantName : "unknown"));
+ }
+ }
/**
* Sync the local with the SAS
* @throws Exception
*/
- @Test(dataProvider = "testName", dependsOnMethods = {"createSASItemList", "CRUDTests"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"createSASItemList", "CRUDTests"})
public void syncWithSAS(String testName) throws Exception {
//
// First check to see if the authority supports synchronization.
//
- AuthorityClient client = (AuthorityClient) this.getClientInstance();
- if (client.supportsSync() == false) {
- return; // Exit the test since this authority doesn't support synchronization
- }
+ assertSupportsSync();
//
// Create an empty instance of the authority, so we can sync items with it. We're
// using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
//
+ AuthorityClient client = (AuthorityClient) getClientInstance();
String localAuthorityId = null;
try {
localAuthorityId = createResource(client, testName, knownSASAuthorityResourceShortId, false);
Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // After a sync, the parent should be in the "Replicated" state
} finally {
response.close();
- }
+ }
+ }
+
+ @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthorityWithRelations", "CRUDTests"})
+ public void syncWithSASWithRelations(String testName) throws Exception {
+ //
+ // First check to see if the authority supports synchronization.
+ //
+ assertSupportsSync();
+
+ //
+ // Create an empty instance of the authority, so we can sync items with it. We're
+ // using the short ID of the SAS authority. The short ID of the local and the SAS will (must) be the same.
+ //
+ AuthorityClient client = (AuthorityClient) this.getClientInstance();
+ String localAuthorityId = null;
+ try {
+ localAuthorityId = createResource(client, testName, knownSASAuthorityResourceWithRelationsShortId, false);
+ } catch (Exception e) {
+ Assert.assertNotNull(localAuthorityId);
+ }
+
+ //
+ // Now we can try to sync the SAS authority with the local one we just created.
+ //
+ setupSync();
+ Response response = client.syncByName(knownSASAuthorityResourceWithRelationsShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
+ try {
+ int statusCode = response.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ } finally {
+ response.close();
+ }
+ //
+ // Check to see if the parent authority (local) is in the "Replicated" state.
+ //
+ setupRead();
+ response = client.readByName(knownSASAuthorityResourceWithRelationsShortId); // Notice we're using the Short ID (short ID is the same on the local and SAS)
+ try {
+ int statusCode = response.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+ String workflowState = this.extractAuthorityWorkflowState(response);
+ Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // After a sync, the parent should be in the "Replicated" state
+ } finally {
+ response.close();
+ }
}
/**
* with the correct short IDs.
*
*/
- @Test(dataProvider = "testName", dependsOnMethods = {"syncWithSAS", "CRUDTests"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"syncWithSAS", "CRUDTests"})
public void veryifySyncWithSAS(String testName) {
//
// First check to see if we support sync.
//
- AuthorityClient client = (AuthorityClient) getClientInstance();
- if (client.supportsSync() == false) {
- return; // Exit the test since this authority doesn't support synchronization
- }
-
+ assertSupportsSync();
+
// Perform setup.
setupReadList();
// Submit the request to the service and store the response.
+ AuthorityClient client = (AuthorityClient) getClientInstance();
Response res = null;
res = client.readItemListForNamedAuthority(knownSASAuthorityResourceShortId, null, null);
res.close();
}
}
+
+ @Test(dataProvider = "testName", dependsOnMethods = {"syncWithSASWithRelations", "CRUDTests"})
+ public void veryifySyncWithSASWithRelations(String testName) {
+ //
+ // First check to see if we support sync.
+ //
+ assertSupportsSync();
+
+ // Perform setup.
+ setupReadList();
+
+ // Submit the request to the service and store the response.
+ AuthorityClient client = (AuthorityClient) getClientInstance();
+ Response res = null;
+ res = client.readItemListForNamedAuthority(knownSASAuthorityResourceWithRelationsShortId, null, null);
+
+ try {
+ int statusCode = res.getStatus();
+ // Check the status code of the response: does it match
+ // the expected response(s)?
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+
+ AbstractCommonList list = res.readEntity(AbstractCommonList.class);
+ long nItemsTotal = list.getTotalItems();
+ Assert.assertEquals(nItemsTotal, knownSASItemIdentifiersWithRelationsList.size());
+ //
+ // Verify that each of our local items has a corresponding remote item
+ //
+ List<AbstractCommonList.ListItem> itemList = list.getListItem();
+ for (AbstractCommonList.ListItem item : itemList) {
+ String shortId = AbstractCommonListUtils.ListItemGetElementValue(
+ item, AuthorityClient.SHORT_IDENTIFIER);
+ Assert.assertTrue(knownSASItemIdentifiersWithRelationsList.contains(shortId)); // The local short ID should be in SAS list
+
+ String workflowState = AbstractCommonListUtils.ListItemGetElementValue(
+ item, CollectionSpaceClient.COLLECTIONSPACE_CORE_WORKFLOWSTATE);
+ Assert.assertTrue(workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED)); // Workflow state must show up in a "replicated" state
+
+ String refName = AbstractCommonListUtils.ListItemGetElementValue(
+ item, AuthorityClient.REF_NAME);
+ Assert.assertTrue((refName != null), "Item refName is null or not set in the item list!");
+ String termDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
+ AuthorityClient.TERM_DISPLAY_NAME);
+ String vocabDisplayName = AbstractCommonListUtils.ListItemGetElementValue(item,
+ AuthorityClient.VOCAB_DISPLAY_NAME);
+ // One of these names needs to be set.
+ Assert.assertTrue(!(termDisplayName == null && vocabDisplayName == null), "The item's display name is null or not set in the item list!");
+ }
+ } finally {
+ res.close();
+ }
+
+ //
+ // Verify the relationship hierarchy is correct.
+ //
+ AuthorityClient authorityClient = (AuthorityClient) getClientInstance();
+ ServiceDescription serviceDescription = authorityClient.getServiceDescription();
+ final String authorityItemDocumentType = serviceDescription == null ? "unknown" : serviceDescription.getSubresourceDocumentType();
+
+ verifyBroaderRelationship(authorityClient, knownSASAuthorityResourceWithRelationsShortId, cityShortId, countryShortId, authorityItemDocumentType);
+ verifyBroaderRelationship(authorityClient, knownSASAuthorityResourceWithRelationsShortId, countryShortId, continentShortId, authorityItemDocumentType);
+ }
+
+ /**
+ * Verifies a broader relationship exists between the subject and object.
+ *
+ * @param authorityClient
+ * @param authorityShortId
+ * @param subjectShortId
+ * @param objectShortId
+ * @param authorityItemDocumentType
+ */
+ private void verifyBroaderRelationship(AuthorityClient authorityClient, String authorityShortId, String subjectShortId, String objectShortId, String authorityItemDocumentType) {
+ setupReadList();
+ RelationClient relationClient = new RelationClient();
+ Response res = relationClient.readList(getCsidFromShortId(authorityClient, authorityShortId, subjectShortId),
+ authorityItemDocumentType,
+ RelationshipType.HAS_BROADER.value(),
+ getCsidFromShortId(authorityClient, authorityShortId, objectShortId),
+ authorityItemDocumentType);
+ try {
+ int statusCode = res.getStatus();
+ Assert.assertTrue(testRequestType.isValidStatusCode(statusCode),
+ invalidStatusCodeMessage(testRequestType, statusCode));
+ Assert.assertEquals(statusCode, testExpectedStatusCode);
+
+ RelationsCommonList list = (RelationsCommonList) res.readEntity(RelationsCommonList.class);
+ Assert.assertEquals(list.getTotalItems(), 1); // Should be exactly one relationship
+ RelationListItem relationListItem = list.getRelationListItem().get(0);
+ //
+ // Check the subject and object refnames to see if the contain the correct short identifiers
+ //
+ Assert.assertTrue(relationListItem.getSubject().getRefName().contains(subjectShortId)); // The subject refname should contain our known short ID
+ Assert.assertTrue(relationListItem.getSubject().getRefName().contains(authorityShortId)); // The subject refname should contain our known short ID
+ // Now check the object refname
+ Assert.assertTrue(relationListItem.getObject().getRefName().contains(objectShortId)); // The object refname should contain our known short ID
+ Assert.assertTrue(relationListItem.getObject().getRefName().contains(authorityShortId)); // The object refname should contain our known short ID
+ } finally {
+ res.close();
+ }
+ }
/**
* SAS - Create a new authority on the SAS server.
* @param testName
*/
- @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"createItem", "CRUDTests"})
public void createSASAuthority(String testName) {
//
// First check to see if the authority supports synchronization.
//
- AuthorityClient client = (AuthorityClient) this.getClientInstance();
- if (client.supportsSync() == false) {
- return; // Exit the test since this authority doesn't support synchronization
- }
+ assertSupportsSync();
// Perform setup.
setupCreate();
}
}
- @Test(dataProvider = "testName", dependsOnMethods = {"deleteLocalItemWithSync", "CRUDTests"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"deleteLocalItemWithSync", "CRUDTests"})
public void createSASAuthorityWithRelations(String testName) {
//
// First check to see if the authority supports synchronization.
//
- AuthorityClient client = (AuthorityClient) getClientInstance();
- if (client.supportsSync() == false) {
- return; // Exit the test since this authority doesn't support synchronization
- }
-
+ assertSupportsSync();
+
// Perform setup.
setupCreate();
//
// Create a new authority on the remote server
//
+ AuthorityClient client = (AuthorityClient) getClientInstance();
try {
String newID = createResource(getSASClientInstance(), testName, getSASAuthorityWithRelationsIdentifier(), true);
knownSASAuthorityResourceWithRelationsId = newID;
//
// Add three items to the remote authority
//
- String continentShortId = "Continent" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
+ continentShortId = "Continent" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
String continentCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, continentShortId);
- this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(continentShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
+ knownSASItemIdentifiersWithRelationsList.add(continentShortId);
+ allSASResourceItemIdsCreated.put(this.getUrnIdentifier(continentShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
- String countryShortId = "Country" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
+ countryShortId = "Country" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
String countryCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, countryShortId);
- this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(countryShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
+ knownSASItemIdentifiersWithRelationsList.add(countryShortId);
+ allSASResourceItemIdsCreated.put(this.getUrnIdentifier(countryShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
- String cityShortId = "City" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
+ cityShortId = "City" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
String cityCSID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceWithRelationsId, cityShortId);
- this.allSASResourceItemIdsCreated.put(this.getUrnIdentifier(cityShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
+ knownSASItemIdentifiersWithRelationsList.add(cityShortId);
+ allSASResourceItemIdsCreated.put(this.getUrnIdentifier(cityShortId), getUrnIdentifier(getSASAuthorityWithRelationsIdentifier()));
//
// Create a set of hierarchical relationships between the items
//
ServiceDescription serviceDescription = client.getServiceDescription();
- final String authorityItemDocumentType = serviceDescription == null ? "unknown" : serviceDescription.getSubresourceDocumentType();
+ final String authorityItemDocumentType = serviceDescription == null ? "unknown" : serviceDescription.getSubresourceDocumentType();
+ RelationClient relationClient = new RelationClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME); // Get a Relation service client to the SAS
+ boolean success = false;
+ try {
+ createBroaderRelationship(relationClient, cityCSID, countryCSID, authorityItemDocumentType);
+ createBroaderRelationship(relationClient, countryCSID, continentCSID, authorityItemDocumentType);
+ success = true;
+ } catch (Exception e) {
+ logger.error(e.getMessage());
+ }
+
+ Assert.assertTrue(success);
+ }
+
+ /**
+ * Creates a broader relationship record between the subject and the object
+ * @param relationClient
+ * @throws Exception
+ */
+ private void createBroaderRelationship(RelationClient relationClient, String subjectCSID, String objectCSID, String docType) throws Exception {
RelationsCommon relationCommon = new RelationsCommon();
- relationCommon.setSubjectCsid(countryCSID);
- relationCommon.setSubjectDocumentType(authorityItemDocumentType);
- relationCommon.setObjectCsid(continentCSID);
- relationCommon.setObjectDocumentType(authorityItemDocumentType);
+
+ relationCommon.setSubjectCsid(subjectCSID);
+ relationCommon.setSubjectDocumentType(docType);
+ relationCommon.setObjectCsid(objectCSID);
+ relationCommon.setObjectDocumentType(docType);
relationCommon.setRelationshipType(RelationshipType.HAS_BROADER.value());
relationCommon.setPredicateDisplayName(RelationshipType.HAS_BROADER.value());
- RelationClient relationClient = new RelationClient(CollectionSpaceClient.SAS_CLIENT_PROPERTIES_FILENAME); // Get a Relation service client to the SAS
PoxPayloadOut payloadOut = relationClient.createRequestTypeInstance(relationCommon);
Response res = relationClient.create(payloadOut);
- if (res.getStatus() != HttpStatus.SC_CREATED) {
- logger.error("Could not create Relationship.");
+ try {
+ if (res.getStatus() == HttpStatus.SC_CREATED) {
+ String relationCSID = extractId(res);
+ allRelationResourceIdsCreated.add(relationCSID); // keep track of what we create so we can cleanup later
+ } else {
+ String errMsg = "Could not create Relationship.";
+ logger.error(errMsg);
+ throw new Exception(errMsg);
+ }
+ } finally {
+ res.close();
}
-
-}
+ }
/**
* SAS - Create an item in the SAS authority on the SAS server.
* @param testName
*/
- @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
+ @Test(dataProvider = "testName", dependsOnMethods = {"createSASAuthority", "CRUDTests"})
public void createSASItemList(String testName) {
//
// First check to see if the authority supports synchronization.
//
- AuthorityClient client = (AuthorityClient) this.getClientInstance();
- if (client.supportsSync() == false) {
- return; // Exit the test since this authority doesn't support synchronization
- }
+ assertSupportsSync();
- // Perform setup.
+ // Perform setup for create.
setupCreate();
-
+
for (int i = 0; i < SAS_ITEMLIST_SIZE; i++) {
String shortId = "SassyActor" + System.currentTimeMillis() + Math.abs(random.nextInt()); // short ID needs to be unique
String newID = createItemInAuthority(getSASClientInstance(), knownSASAuthorityResourceId, shortId);
}
}
- private String getShortId(AuthorityClient client, String authorityCsid) throws Exception {
+ private String getShortId(AuthorityClient client, String authorityCsid) throws Exception {
String result = null;
// Submit the request to the service and store the response.
return result;
}
- private String getShortId(String authorityCsid) throws Exception {
+ private String getShortId(String authorityCsid) throws Exception {
AuthorityClient client = (AuthorityClient) getClientInstance();
return getShortId(client, authorityCsid);
}
return result;
}
+ protected String extractCsid(Response res) throws Exception {
+ String result = null;
+
+ PoxPayloadIn input = new PoxPayloadIn((String)res.readEntity(getEntityResponseType()));
+ Document document = input.getDOMDocument();
+ result = XmlTools.getElementValue(document, "//" + AuthorityClient.COLLECTIONSPACE_CORE_CSID);
+
+ return result;
+ }
@Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"readItem"})
AuthorityClient client = (AuthorityClient) getClientInstance();
PoxPayloadOut payloadOut = new PoxPayloadOut(this.getServicePathItemsComponent());
- PayloadOutputPart part = payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
+ payloadOut.addPart(client.getItemCommonPartName(), itemTypeInstance);
result = payloadOut;
return result;
}
}
- @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"updateLocalItemWithSync", "CRUDTests"})
public void deleteLocalItemWithSync(String testName) throws Exception {
final int itemIndexToDelete = 1;
//
// First check to see if we support sync.
//
- AuthorityClient client = (AuthorityClient) getClientInstance();
- if (client.supportsSync() == false) {
- return; // Exit the test since this authority doesn't support synchronization
- }
+ assertSupportsSync();
// Perform test setup for a DELETE.
setupDelete();
- AUTHORITY_ITEM_TYPE theUpdate = null;
// Delete an item from the SAS server
AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
* We create a new item on the SAS, perform a sync with the local authority, and verify the local authority contains a copy
* of the SAS item.
*/
- @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+ @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
dependsOnMethods = {"veryifySyncWithSAS", "CRUDTests"})
public void updateLocalItemWithSync(String testName) throws Exception {
//
// First check to see if we support sync.
//
- AuthorityClient client = (AuthorityClient) getClientInstance();
- if (client.supportsSync() == false) {
- return; // Exit the test since this authority doesn't support synchronization
- }
+ assertSupportsSync();
// Perform setup.
setupUpdate();
- AUTHORITY_ITEM_TYPE theUpdate = null;
// Retrieve the contents of a shared authority item that we're going to update.
+ AUTHORITY_ITEM_TYPE theUpdate = null;
AUTHORITY_ITEM_TYPE sasAuthorityItem = null;
AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
Response res = sasClient.readNamedItemInNamedAuthority(knownSASAuthorityResourceShortId, knownSASItemIdentifiersList.get(0));
//
// Clean up authority items on the SAS using the SAS client.
//
- client = (AuthorityClient) this.getSASClientInstance();
+ AuthorityClient sasClient = (AuthorityClient) this.getSASClientInstance();
for (Map.Entry<String, String> entry : allSASResourceItemIdsCreated.entrySet()) {
itemResourceId = entry.getKey();
parentResourceId = entry.getValue();
- client.deleteItem(parentResourceId, itemResourceId).close();
+ sasClient.deleteItem(parentResourceId, itemResourceId).close();
}
//
// Finally, call out superclass's cleanUp method to deleted the local authorities
//
// Call out superclass's cleanUp method to delete the SAS authorities
//
- super.cleanUp(client);
+ super.cleanUp(sasClient);
}
protected String getTestAuthorityItemShortId() {