From: remillet Date: Thu, 2 Jun 2016 21:37:24 +0000 (-0700) Subject: CSPACE-6953: Getting all unit tests passing again after changes for synchronization... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c7ef82f4b902c49558daca45feb7d300ae8b61da;p=tmp%2Fjakarta-migration.git CSPACE-6953: Getting all unit tests passing again after changes for synchronization of hierarchy relations. --- diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java index 8fe6645c7..534cae94d 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/CollectionSpaceIntegrationTest.java @@ -47,6 +47,8 @@ import org.collectionspace.services.relation.RelationsCommon; * The Class CollectionSpaceIntegrationTest. */ public abstract class CollectionSpaceIntegrationTest { + protected List allRelationResourceIdsCreated = new ArrayList(); + protected List allResourceIdsCreated = new ArrayList(); /* * Package scoped methods. diff --git a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java index 22eea86d8..aec72528c 100644 --- a/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java +++ b/services/IntegrationTests/src/test/java/org/collectionspace/services/IntegrationTests/test/RelationIntegrationTest.java @@ -33,11 +33,10 @@ import javax.xml.bind.JAXBContext; 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; @@ -45,10 +44,8 @@ import org.collectionspace.services.client.PayloadOutputPart; 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; @@ -76,6 +73,14 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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. * @@ -148,6 +153,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { Assert.assertEquals(response.getStatus(), Response.Status.CREATED .getStatusCode()); collectionObjectCsid = extractId(response); + collectionObjectClient.addToCleanup(collectionObjectCsid); } finally { response.close(); } @@ -160,6 +166,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); dimensionCsid1 = extractId(response); + dimensionClient.addToCleanup(dimensionCsid1); } finally { response.close(); } @@ -178,17 +185,21 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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 @@ -204,6 +215,14 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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() { @@ -222,6 +241,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { Assert.assertEquals(response.getStatus(), Response.Status.CREATED .getStatusCode()); collectionObjectCsid = extractId(response); + collectionObjectClient.addToCleanup(collectionObjectCsid); } finally { response.close(); } @@ -234,6 +254,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); dimensionCsid1 = extractId(response); + dimensionClient.addToCleanup(dimensionCsid1); } finally { response.close(); } @@ -246,6 +267,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); dimensionCsid2 = extractId(response); + dimensionClient.addToCleanup(dimensionCsid2); } finally { response.close(); } @@ -258,6 +280,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); dimensionCsid3 = extractId(response); + dimensionClient.addToCleanup(dimensionCsid3); } finally { response.close(); } @@ -277,6 +300,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); relationCsid1 = extractId(response); + relationClient.addToCleanup(relationCsid1); } finally { response.close(); } @@ -297,11 +321,12 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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(); } @@ -322,11 +347,12 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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(); } @@ -351,6 +377,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { Assert.assertEquals(response.getStatus(), Response.Status.CREATED .getStatusCode()); collectionObjectCsid = extractId(response); + collectionObjectClient.addToCleanup(collectionObjectCsid); } finally { response.close(); } @@ -383,15 +410,24 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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 @@ -414,11 +450,11 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { 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()); @@ -433,6 +469,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); intakeCsid = extractId(response); + intakeClient.addToCleanup(intakeCsid); } finally { response.close(); } @@ -453,6 +490,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); relationCsid = extractId(response); + relationClient.addToCleanup(relationCsid); } finally { response.close(); } @@ -538,6 +576,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { .getStatusCode()); collectionObjectCsid = extractId(response); collectionObjectIDList.add(collectionObjectCsid); + collectionObjectClient.addToCleanup(collectionObjectCsid); } finally { response.close(); } @@ -558,6 +597,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); intakeCsid = extractId(response); + intakeClient.addToCleanup(intakeCsid); } finally { response.close(); } @@ -580,6 +620,7 @@ public class RelationIntegrationTest extends CollectionSpaceIntegrationTest { try { Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); relationCsid = extractId(response); + relationClient.addToCleanup(relationCsid); } finally { response.close(); } diff --git a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authrefs/authrefsSimple.xml b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authrefs/authrefsSimple.xml index 8f55a0d81..badb978d1 100644 --- a/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authrefs/authrefsSimple.xml +++ b/services/IntegrationTests/src/test/resources/test-data/xmlreplay/authrefs/authrefsSimple.xml @@ -93,6 +93,5 @@ authrefs/res/foo.res.xml - diff --git a/services/JaxRsServiceProvider/src/main/resources/log4j.properties b/services/JaxRsServiceProvider/src/main/resources/log4j.properties index 36e5757db..e91afb29b 100644 --- a/services/JaxRsServiceProvider/src/main/resources/log4j.properties +++ b/services/JaxRsServiceProvider/src/main/resources/log4j.properties @@ -55,7 +55,7 @@ log4j.additivity.perf.collectionspace=false log4j.logger.org.collectionspace=WARN log4j.logger.org.collectionspace.services.nuxeo.client.java.NuxeoClientEmbedded=ERROR log4j.logger.org.collectionspace.services.nuxeo.client.java.RepositoryClientImpl=ERROR -log4j.logger.org.collectionspace.services.common.security.SecurityInterceptor=TRACE +log4j.logger.org.collectionspace.services.common.security.SecurityInterceptor=ERROR log4j.logger.org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl=DEBUG #log4j.logger.org.collectionspace.services.nuxeo.client.java=ERROR #log4j.logger.org.collectionspace.services.common.storage.JDBCTools=ERROR diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java index d6e857432..f7cf59935 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityDocumentModelHandler.java @@ -134,42 +134,49 @@ public abstract class AuthorityDocumentModelHandler // Get the rev number of the authority so we can compare with rev number of shared authority // DocumentModel docModel = NuxeoUtils.getDocFromSpecifier(ctx, getRepositorySession(), authorityCommonSchemaName, specifier); - Long localRev = (Long) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REV); - String shortId = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.SHORT_IDENTIFIER); - // - // Using the short ID of the local authority, create a URN specifier to retrieve the SAS authority - // - Specifier sasSpecifier = new Specifier(SpecifierForm.URN_NAME, shortId); - PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadIn(ctx, sasSpecifier, getEntityResponseType()); - // - // If the authority on the SAS is newer, synch all the items and then the authority record as well - // - // - Long sasRev = getRevision(sasPayloadIn); - if (sasRev > localRev) { - // - // First, sync all the authority items - // - syncAllItems(ctx, sasSpecifier); - // - // Next, sync the authority resource/record itself - // - AuthorityResource authorityResource = (AuthorityResource) ctx.getResource(); - ctx.setProperty(AuthorityServiceUtils.SHOULD_UPDATE_REV_PROPERTY, AuthorityServiceUtils.DONT_UPDATE_REV); // Don't update the rev number, use the rev number for the SAS instance instead - PoxPayloadOut payloadOut = authorityResource.update(ctx, ctx.getResourceMap(), ctx.getUriInfo(), docModel.getName(), - sasPayloadIn); - if (payloadOut != null) { - ctx.setOutput(payloadOut); - result = true; - } - // - // We may need to transition the authority into a replicated state the first time we sync it. - // - String workflowState = docModel.getCurrentLifeCycleState(); - if (workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED) == false) { - String authorityCsid = docModel.getName(); - authorityResource.updateWorkflowWithTransition(ctx, ctx.getUriInfo(), authorityCsid, WorkflowClient.WORKFLOWTRANSITION_REPLICATE); - } + if (docModel != null) { + Long localRev = (Long) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.REV); + String shortId = (String) NuxeoUtils.getProperyValue(docModel, AuthorityJAXBSchema.SHORT_IDENTIFIER); + // + // Using the short ID of the local authority, create a URN specifier to retrieve the SAS authority + // + Specifier sasSpecifier = new Specifier(SpecifierForm.URN_NAME, shortId); + PoxPayloadIn sasPayloadIn = AuthorityServiceUtils.requestPayloadIn(ctx, sasSpecifier, getEntityResponseType()); + // + // If the authority on the SAS is newer, synch all the items and then the authority record as well + // + // + Long sasRev = getRevision(sasPayloadIn); + if (sasRev > localRev) { + // + // First, sync all the authority items + // + syncAllItems(ctx, sasSpecifier); + // + // Next, sync the authority resource/record itself + // + AuthorityResource authorityResource = (AuthorityResource) ctx.getResource(); + ctx.setProperty(AuthorityServiceUtils.SHOULD_UPDATE_REV_PROPERTY, AuthorityServiceUtils.DONT_UPDATE_REV); // Don't update the rev number, use the rev number for the SAS instance instead + PoxPayloadOut payloadOut = authorityResource.update(ctx, ctx.getResourceMap(), ctx.getUriInfo(), docModel.getName(), + sasPayloadIn); + if (payloadOut != null) { + ctx.setOutput(payloadOut); + result = true; + } + // + // We may need to transition the authority into a replicated state the first time we sync it. + // + String workflowState = docModel.getCurrentLifeCycleState(); + if (workflowState.contains(WorkflowClient.WORKFLOWSTATE_REPLICATED) == false) { + String authorityCsid = docModel.getName(); + authorityResource.updateWorkflowWithTransition(ctx, ctx.getUriInfo(), authorityCsid, WorkflowClient.WORKFLOWTRANSITION_REPLICATE); + } + } + } else { + String errMsg = String.format("Authority of type '%s' with identifier '%s' does not exist.", + getServiceContext().getServiceName(), specifier.getURNValue()); + logger.debug(errMsg); + throw new DocumentException(errMsg); } return result; diff --git a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java index c924de9a8..7f816c54c 100644 --- a/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java +++ b/services/authority/service/src/main/java/org/collectionspace/services/common/vocabulary/nuxeo/AuthorityItemDocumentModelHandler.java @@ -903,13 +903,18 @@ public abstract class AuthorityItemDocumentModelHandler inAuthorityCsid = (String)documentModel.getProperty(authorityItemCommonSchemaName, AuthorityItemJAXBSchema.IN_AUTHORITY); } DocumentModel inAuthorityDocModel = NuxeoUtils.getDocFromCsid(getServiceContext(), getRepositorySession(), inAuthorityCsid); - Long parentRev = (Long)inAuthorityDocModel.getProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV); - if (parentRev == null) { - parentRev = new Long(0); + if (inAuthorityDocModel != null) { + Long parentRev = (Long)inAuthorityDocModel.getProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV); + if (parentRev == null) { + parentRev = new Long(0); + } + parentRev++; + inAuthorityDocModel.setProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV, parentRev); + getRepositorySession().saveDocument(inAuthorityDocModel); + } else { + logger.warn(String.format("Containing authority '%s' for item '%s' has been deleted. Item is orphaned, so revision numbers can't be updated.", + inAuthorityCsid, documentModel.getName())); } - parentRev++; - inAuthorityDocModel.setProperty(getParentCommonSchemaName(), AuthorityJAXBSchema.REV, parentRev); - getRepositorySession().saveDocument(inAuthorityDocModel); } /** diff --git a/services/authorization-mgt/import/build.xml b/services/authorization-mgt/import/build.xml index 8617b4308..0ea7137cf 100644 --- a/services/authorization-mgt/import/build.xml +++ b/services/authorization-mgt/import/build.xml @@ -122,7 +122,7 @@ - + diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java index 99fb6101a..70cae8558 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractPoxServiceClientImpl.java @@ -1,5 +1,8 @@ package org.collectionspace.services.client; +import java.util.ArrayList; +import java.util.List; + import javax.ws.rs.core.Response; import org.testng.Assert; @@ -15,6 +18,8 @@ public abstract class AbstractPoxServiceClientImpl implements CollectionSpacePoxClient { + protected List allResourceIdsCreated = new ArrayList(); + public AbstractPoxServiceClientImpl(String clientPropertiesFilename) { super(clientPropertiesFilename); } @@ -22,7 +27,24 @@ public abstract class AbstractPoxServiceClientImpl extends AbstractPoxServiceTestImpl { @@ -66,9 +69,17 @@ public abstract class AbstractAuthorityServiceTest knownSASItemIdentifiersWithRelationsList = new ArrayList(); 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 */ @@ -164,11 +175,32 @@ public abstract class AbstractAuthorityServiceTest 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(); @@ -489,21 +688,19 @@ public abstract class AbstractAuthorityServiceTest 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 @@ -1197,7 +1423,7 @@ public abstract class AbstractAuthorityServiceTest UriInfo uriInfo = ctx.getUriInfo(); MultivaluedMap queryParams = uriInfo.getQueryParameters(); - if (fUpdate) { + if (forUpdate) { //Run getList() once as sent to get childListOuter: String predicate = RelationshipType.HAS_BROADER.value(); queryParams.putSingle(IRelationsManager.PREDICATE_QP, predicate); @@ -1229,13 +1229,6 @@ public abstract class RemoteDocumentModelHandlerImpl if (logger.isTraceEnabled()) { logger.trace("AuthItemDocHndler.updateRelations for: " + itemCSID + " got existing relations."); } - } else { - // For debugging purpose only. - if (logger.isDebugEnabled()) { - String debugMsg = "AuthItemDocHndler.updateRelations for: " + itemCSID + " with an fUpdate value of FALSE."; - logger.debug(debugMsg); - throw new Exception(debugMsg); - } } for (RelationsCommonList.RelationListItem inboundItem : inboundList) { @@ -1300,7 +1293,7 @@ public abstract class RemoteDocumentModelHandlerImpl String dump = dumpLists(itemCSID, parentList, childList, actionList); logger.trace("~~~~~~~~~~~~~~~~~~~~~~dump~~~~~~~~~~~~~~~~~~~~~~~~" + CR + dump); } - if (fUpdate) { + if (forUpdate) { if (logger.isTraceEnabled()) { logger.trace("AuthItemDocHndler.updateRelations for: " + itemCSID + " deleting " + parentList.size() + " existing parents and " + childList.size() + " existing children."); @@ -1411,14 +1404,14 @@ public abstract class RemoteDocumentModelHandlerImpl // Nevertheless, we should complete the item save before we do work on the relations, especially // since a save on Create might fail, and we would not want to create relations for something // that may not be created... - private void handleRelationsPayload(DocumentWrapper wrapDoc, boolean fUpdate) throws Exception { + private void handleRelationsPayload(DocumentWrapper wrapDoc, boolean forUpdate) throws Exception { ServiceContext ctx = getServiceContext(); PoxPayloadIn input = ctx.getInput(); DocumentModel documentModel = (wrapDoc.getWrappedObject()); String itemCsid = documentModel.getName(); //Updates relations part - RelationsCommonList relationsCommonList = updateRelations(itemCsid, input, wrapDoc, fUpdate); + RelationsCommonList relationsCommonList = updateRelations(itemCsid, input, wrapDoc, forUpdate); PayloadOutputPart payloadOutputPart = new PayloadOutputPart(RelationClient.SERVICE_COMMON_LIST_NAME, relationsCommonList); //FIXME: REM - We should check for a null relationsCommonList and not create the new common list payload ctx.setProperty(RelationClient.SERVICE_COMMON_LIST_NAME, payloadOutputPart);