From 27537ce71f0faf2f18efe162ec30be157476e805 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Thu, 13 Oct 2011 18:38:11 +0000 Subject: [PATCH] CSPACE-4481 Missing call in RelationDocumentModelHandler.handleUpdate() to do the work that .handleCreate was doing to populate the doctype, uri, etc. Fixing this surfaced more test case bugs (i.e., assuming that relation fields were string buckets without semantics). --- .../client/test/RelationServiceTest.java | 51 ++++++++++--------- .../nuxeo/RelationDocumentModelHandler.java | 19 +++++-- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java index 8b220a874..76f0254c0 100644 --- a/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java +++ b/services/relation/client/src/test/java/org/collectionspace/services/client/test/RelationServiceTest.java @@ -554,22 +554,16 @@ public class RelationServiceTest extends AbstractServiceTestImpl { dependsOnMethods = {"read"}) public void update(String testName) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug(testBanner(testName, CLASS_NAME)); - } + logger.debug(testBanner(testName, CLASS_NAME)); // Perform setup. setupUpdate(); // Retrieve an existing resource that we can update. RelationClient client = new RelationClient(); ClientResponse res = client.read(knownResourceId); - if(logger.isDebugEnabled()){ - logger.debug(testName + ": read status = " + res.getStatus()); - } + logger.debug(testName + ": read status = " + res.getStatus()); Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); - if(logger.isDebugEnabled()){ - logger.debug("Got object to update with ID: " + knownResourceId); - } + logger.debug("Got object to update with ID: " + knownResourceId); // Extract the common part and verify that it is not null. PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); @@ -579,17 +573,21 @@ public class RelationServiceTest extends AbstractServiceTestImpl { relationCommon = (RelationsCommon) payloadInputPart.getBody(); } Assert.assertNotNull(relationCommon); - - // Update the content of this resource. - relationCommon.setDocumentId1("updated-" + relationCommon.getDocumentId1()); - relationCommon.setDocumentType1("updated-" + relationCommon.getDocumentType1()); - relationCommon.setDocumentId2("updated-" + relationCommon.getDocumentId2()); - relationCommon.setDocumentType2("updated-" + relationCommon.getDocumentType2()); + logger.trace("object before update"); + logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class)); + + String newSubjectDocType = relationCommon.getObjectDocumentType(); + String newObjectDocType = relationCommon.getSubjectDocumentType(); + String newSubjectId = relationCommon.getObjectCsid(); + String newObjectId = relationCommon.getSubjectCsid(); + // Update the content of this resource, inverting subject and object + relationCommon.setSubjectCsid(newSubjectId); + relationCommon.setSubjectDocumentType("Hooey"); + relationCommon.setObjectCsid(newObjectId); + relationCommon.setObjectDocumentType("Fooey"); relationCommon.setPredicateDisplayName("updated-" + relationCommon.getPredicateDisplayName()); - if(logger.isDebugEnabled()){ - logger.debug("updated object"); - logger.debug(objectAsXmlString(relationCommon, RelationsCommon.class)); - } + logger.trace("updated object to send"); + logger.trace(objectAsXmlString(relationCommon, RelationsCommon.class)); // Submit the request containing the updated resource to the service // and store the response. @@ -600,9 +598,7 @@ public class RelationServiceTest extends AbstractServiceTestImpl { int statusCode = res.getStatus(); // Check the status code of the response: does it match the expected response(s)? - if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); - } Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); @@ -614,16 +610,21 @@ public class RelationServiceTest extends AbstractServiceTestImpl { client.getCommonPartName(), RelationsCommon.class); Assert.assertNotNull(updatedRelationCommon); + logger.trace("updated object as received"); + logger.trace(objectAsXmlString(updatedRelationCommon, RelationsCommon.class)); + final String msg = "Data in updated object did not match submitted data."; + final String msg2 = + "Data in updated object was not correctly computed."; Assert.assertEquals( - updatedRelationCommon.getDocumentId1(), relationCommon.getDocumentId1(), msg); + updatedRelationCommon.getDocumentId1(), newSubjectId, msg); Assert.assertEquals( - updatedRelationCommon.getDocumentType1(), relationCommon.getDocumentType1(), msg); + updatedRelationCommon.getDocumentType1(), newSubjectDocType, msg2); Assert.assertEquals( - updatedRelationCommon.getDocumentId2(), relationCommon.getDocumentId2(), msg); + updatedRelationCommon.getDocumentId2(), newObjectId, msg); Assert.assertEquals( - updatedRelationCommon.getDocumentType2(), relationCommon.getDocumentType2(), msg); + updatedRelationCommon.getDocumentType2(), newObjectDocType, msg2); Assert.assertEquals( updatedRelationCommon.getPredicateDisplayName(), relationCommon.getPredicateDisplayName(), msg); diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java index 5aceb9a87..dc38d6e6d 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/nuxeo/RelationDocumentModelHandler.java @@ -92,6 +92,20 @@ public class RelationDocumentModelHandler // Merge in the data from the payload super.handleCreate(wrapDoc); + // And take care of ensuring all the values for the relation info are correct + populateSubjectAndObjectValues(wrapDoc); + } + + @Override + public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { + // Merge in the data from the payload + super.handleUpdate(wrapDoc); + + // And take care of ensuring all the values for the relation info are correct + populateSubjectAndObjectValues(wrapDoc); + } + + private void populateSubjectAndObjectValues(DocumentWrapper wrapDoc) throws Exception { // Obtain document models for the subject and object of the relation, so that // we ensure we have value docType, URI info. If the docModels support refNames, // we will also set those. @@ -111,11 +125,6 @@ public class RelationDocumentModelHandler } } - @Override - public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { - super.handleUpdate(wrapDoc); - } - @Override public RelationsCommon getCommonPart() { return relation; -- 2.47.3