From c0b67c75c7eac261a01871bc3a6b36c783836275 Mon Sep 17 00:00:00 2001 From: Sanjay Dalal Date: Wed, 23 Dec 2009 20:09:28 +0000 Subject: [PATCH] CSPACE-697 fixed documentutils to recognize multivalue field more deterministically added tests for single and multivalue instances for a multivalue fields test: collectionobject client M collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java M common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java --- .../test/CollectionObjectServiceTest.java | 37 ++++++++++--------- .../common/document/DocumentUtils.java | 24 ++++++------ services/pom.xml | 5 ++- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index 64ad4671a..e2532e4fd 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -59,6 +59,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { private CollectionObjectClient client = new CollectionObjectClient(); private String knownResourceId = null; private List allResourceIdsCreated = new ArrayList(); + private boolean multivalue; //toggle /* * This method is called only by the parent class, AbstractServiceTest @@ -323,12 +324,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { int i = 0; for (CollectionobjectsCommonList.CollectionObjectListItem item : items) { - logger.debug(testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] objectNumber=" + - item.getObjectNumber()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); + logger.debug(testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(testName + ": list-item[" + i + "] objectNumber=" + + item.getObjectNumber()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); i++; } @@ -371,7 +372,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { if (logger.isDebugEnabled()) { logger.debug("updated object"); logger.debug(objectAsXmlString(collectionObject, - CollectionobjectsCommon.class)); + CollectionobjectsCommon.class)); } // Submit the request to the service and store the response. @@ -595,8 +596,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // Check the status code of the response: does it match // the expected response(s)? if (logger.isDebugEnabled()) { - logger.debug("testSubmitRequest: url=" + url + - " status=" + statusCode); + logger.debug("testSubmitRequest: url=" + url + + " status=" + statusCode); } Assert.assertEquals(statusCode, EXPECTED_STATUS); @@ -605,7 +606,6 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { // --------------------------------------------------------------- // Cleanup of resources created during testing // --------------------------------------------------------------- - /** * Deletes all resources created by tests, after all tests have been run. * @@ -614,7 +614,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. */ - @AfterClass(alwaysRun=true) + @AfterClass(alwaysRun = true) public void cleanUp() { if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); @@ -641,14 +641,17 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { OtherNumberList onList = new OtherNumberList(); List ons = onList.getOtherNumber(); ons.add("urn:org.collectionspace.id:24082390"); - ons.add("urn:org.walkerart.id:123"); + if (multivalue) { + ons.add("urn:org.walkerart.id:123"); + } + multivalue = !multivalue; collectionObject.setOtherNumbers(onList); collectionObject.setObjectNumber(objectNumber); collectionObject.setObjectName(objectName); collectionObject.setAge(""); //test for null string - collectionObject.setBriefDescription("Papier mache bird mask with horns, " + - "painted red with black and yellow spots. " + - "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with horns)."); + collectionObject.setBriefDescription("Papier mache bird mask with horns, " + + "painted red with black and yellow spots. " + + "Puerto Rico. ca. 8" high, 6" wide, projects 10" (with horns)."); MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = multipart.addPart(collectionObject, MediaType.APPLICATION_XML_TYPE); @@ -657,7 +660,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { if (logger.isDebugEnabled()) { logger.debug("to be created, collectionobject common"); logger.debug(objectAsXmlString(collectionObject, - CollectionobjectsCommon.class)); + CollectionobjectsCommon.class)); } CollectionobjectsNaturalhistory conh = new CollectionobjectsNaturalhistory(); @@ -670,7 +673,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest { if (logger.isDebugEnabled()) { logger.debug("to be created, collectionobject nhistory"); logger.debug(objectAsXmlString(conh, - CollectionobjectsNaturalhistory.class)); + CollectionobjectsNaturalhistory.class)); } return multipart; diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index c3600db01..57c580f23 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -97,17 +97,19 @@ public class DocumentUtils { HashMap objectProps = new HashMap(); // Get a list of all elements in the document Node root = document.getFirstChild(); - NodeList rootChildren = root.getChildNodes(); - for (int i = 0; i < rootChildren.getLength(); i++) { - Node node = rootChildren.item(i); + NodeList nodeChildren = root.getChildNodes(); + for (int i = 0; i < nodeChildren.getLength(); i++) { + Node node = nodeChildren.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { NodeList childNodes = node.getChildNodes(); - if (childNodes.getLength() > 1) { - //must be multi value element - String[] vals = getMultiValues(node); - objectProps.put(node.getNodeName(), vals); - } else if (childNodes.getLength() == 1) { - objectProps.put(node.getNodeName(), getTextNodeValue(node)); + Node cnode = childNodes.item(0); + if (cnode != null) { + if (cnode.getNodeType() == Node.TEXT_NODE) { + objectProps.put(node.getNodeName(), getTextNodeValue(node)); + } else { + String[] vals = getMultiValues(node); + objectProps.put(node.getNodeName(), vals); + } } } } @@ -265,8 +267,8 @@ public class DocumentUtils { nv.name = stz.nextToken(); nv.value = stz.nextToken(); } else { - throw new IllegalStateException("Found multi valued element " + input + - " without qualification"); + throw new IllegalStateException("Found multi valued element " + input + + " without qualification"); } return nv; } diff --git a/services/pom.xml b/services/pom.xml index 4c25658c3..5455df1c4 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -129,15 +129,18 @@ org.collectionspace.* - org.codehaus.mojo findbugs-maven-plugin 2.0.1 org.collectionspace.* + true + + target/site + -- 2.47.3