]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-697 fixed documentutils to recognize multivalue field more deterministically
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 23 Dec 2009 20:09:28 +0000 (20:09 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Wed, 23 Dec 2009 20:09:28 +0000 (20:09 +0000)
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

services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java
services/pom.xml

index 64ad4671a0e0e6e1046f2e37e298f38f2200938b..e2532e4fdee2f65f2d15414f6512d5bc3a739891 100644 (file)
@@ -59,6 +59,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTest {
     private CollectionObjectClient client = new CollectionObjectClient();
     private String knownResourceId = null;
     private List<String> 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<String> 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&quot; high, 6&quot; wide, projects 10&quot; (with horns).");
+        collectionObject.setBriefDescription("Papier mache bird mask with horns, "
+                + "painted red with black and yellow spots. "
+                "Puerto Rico. ca. 8&quot; high, 6&quot; wide, projects 10&quot; (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;
 
index c3600db01c4be86e5eba18253fa059bf80c31649..57c580f237ed21311246641bd180eb97bdb9e4bf 100644 (file)
@@ -97,17 +97,19 @@ public class DocumentUtils {
         HashMap<String, Object> objectProps = new HashMap<String, Object>();
         // 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;
     }
index 4c25658c3e3cc7a4520e4f162d848c9e7b00ffb1..5455df1c4b0baa2b3dec2246b3fadbaa8dcc7aa7 100644 (file)
                      <onlyAnalyze>org.collectionspace.*</onlyAnalyze>
                 </configuration>
             </plugin-->
-
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>findbugs-maven-plugin</artifactId>
                 <version>2.0.1</version>
                 <configuration>
                     <onlyAnalyze>org.collectionspace.*</onlyAnalyze>
+                    <findbugsXmlOutput>true</findbugsXmlOutput>
+                    <!-- Optional directory to put findbugs xml report -->
+                    <findbugsXmlOutputDirectory>target/site</findbugsXmlOutputDirectory>
                 </configuration>
             </plugin>
+            
         </plugins>
     </reporting>
     <dependencyManagement>