]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-2242: Created client tests to demonstrate bug, identified by Chris, in which...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 25 Jun 2010 18:20:35 +0000 (18:20 +0000)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 25 Jun 2010 18:20:35 +0000 (18:20 +0000)
services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java
services/collectionobject/client/src/test/resources/test-data/cspace-2242-first-value-instance-blank.xml [new file with mode: 0644]
services/collectionobject/client/src/test/resources/test-data/cspace-2242-first-value-instance-nonblank.xml [new file with mode: 0644]

index a647eee74b175b1007c1717f57c26ae1564a7223..8a722d302da2c2699ba7250242b766ed7d81f38d 100644 (file)
@@ -165,6 +165,48 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl {
         testSubmitRequest(newId);
     }
 
+   /*
+    * Tests to diagnose and fix CSPACE-2242.
+    *
+    * This is a bug identified in release 0.8 in which value instances of a
+    * repeatable field are not stored when the first value instance of that
+    * field is blank.
+    */
+
+    // Verify that record creation occurs successfully when the first value instance
+    // of a single, repeatble String scalar field is non-blank.
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+        dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2242group"})
+    public void createFromXmlNonBlankFirstValueInstance(String testName) throws Exception {
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        String newId =
+            createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-nonblank.xml", true);
+        CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
+        // Verify that at least one value instance of the repeatable field was successfully persisted.
+        BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
+        List<String> descriptions = descriptionList.getBriefDescription();
+        Assert.assertTrue(descriptions.size() > 0);
+    }
+
+    // Verify that record creation occurs successfully when the first value instance
+    // of a single, repeatble String scalar field is blank.
+    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
+        dependsOnMethods = {"create", "testSubmitRequest"}, groups = {"cspace2242group"})
+    public void createFromXmlBlankFirstValueInstance(String testName) throws Exception {
+        if (logger.isDebugEnabled()) {
+            logger.debug(testBanner(testName, CLASS_NAME));
+        }
+        String newId =
+            createFromXmlFile(testName, "./test-data/cspace-2242-first-value-instance-blank.xml", true);
+        CollectionobjectsCommon collectionObject = readCollectionObjectCommonPart(newId);
+        // Verify that at least one value instance of the repeatable field was successfully persisted.
+        BriefDescriptionList descriptionList = collectionObject.getBriefDescriptions();
+        List<String> descriptions = descriptionList.getBriefDescription();
+        // Assert.assertTrue(descriptions.size() > 0);
+    }
+
     /**
      * Creates the from xml rfw s1.
      *
@@ -228,12 +270,12 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl {
         testSubmitRequest(newId);
     }
 
-    /*
-     * Tests to diagnose and verify the fixed status of CSPACE-1248,
-     * "Wedged records created!" (i.e. records with child repeatable
-     * fields, which contain null values, can be successfully created
-     * but an error occurs on trying to retrieve those records).
-     */
+//    /*
+//     * Tests to diagnose and verify the fixed status of CSPACE-1248,
+//     * "Wedged records created!" (i.e. records with child repeatable
+//     * fields, which contain null values, can be successfully created
+//     * but an error occurs on trying to retrieve those records).
+//     */
     /**
      * Creates the with null value repeatable field.
      *
@@ -1231,4 +1273,41 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl {
         allResourceIdsCreated.add(newId);
         return newId;
     }
+
+    // FIXME: This duplicates code in read(), and should be consolidated.
+    // This is an expedient to support reading and verifying the contents
+    // of resources that have been created from test data XML files.
+    private CollectionobjectsCommon readCollectionObjectCommonPart(String csid)
+        throws Exception {
+
+        String testName = "readCollectionObjectCommonPart";
+
+        setupRead();
+
+        // Submit the request to the service and store the response.
+        CollectionObjectClient client = new CollectionObjectClient();
+        ClientResponse<MultipartInput> res = client.read(csid);
+        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);
+
+        MultipartInput input = (MultipartInput) res.getEntity();
+
+        if (logger.isDebugEnabled()) {
+            logger.debug(testName + ": Reading Common part ...");
+        }
+        CollectionobjectsCommon collectionObject =
+                (CollectionobjectsCommon) extractPart(input,
+                client.getCommonPartName(), CollectionobjectsCommon.class);
+        Assert.assertNotNull(collectionObject);
+
+        return collectionObject;
+     }
 }
diff --git a/services/collectionobject/client/src/test/resources/test-data/cspace-2242-first-value-instance-blank.xml b/services/collectionobject/client/src/test/resources/test-data/cspace-2242-first-value-instance-blank.xml
new file mode 100644 (file)
index 0000000..9a69aa8
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Document   : cspace-2242-first-value-instance-blank.xml
+    Created on : 
+    Author     : 
+    Description: Test data for http://issues.collectionspace.org/browse/CSPACE-2242
+-->
+
+<ns2:collectionobjects_common
+    xmlns:ns2="http://collectionspace.org/services/collectionobject"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+    xsi:schemaLocation="http://collectionspace.org/services/collectionobject http://services.collectionspace.org/collectionobject/collectionobjects_common.xsd">
+    <objectNumber>2</objectNumber>
+    <comments>description</comments>
+    <objectName>Left-handed screwdriver</objectName>
+    <title></title>
+    <briefDescriptions>
+        <!-- First value instance of this repeatable field is blank -->
+        <briefDescription></briefDescription>
+        <briefDescription></briefDescription>
+        <briefDescription>bob2</briefDescription>
+    </briefDescriptions>
+</ns2:collectionobjects_common>
diff --git a/services/collectionobject/client/src/test/resources/test-data/cspace-2242-first-value-instance-nonblank.xml b/services/collectionobject/client/src/test/resources/test-data/cspace-2242-first-value-instance-nonblank.xml
new file mode 100644 (file)
index 0000000..a8bad2b
--- /dev/null
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Document   : cspace-2242-first-value-instance-nonblank.xml
+    Created on : 
+    Author     : 
+    Description: Test data for http://issues.collectionspace.org/browse/CSPACE-2242
+-->
+
+<ns2:collectionobjects_common
+    xmlns:ns2="http://collectionspace.org/services/collectionobject"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+    xsi:schemaLocation="http://collectionspace.org/services/collectionobject http://services.collectionspace.org/collectionobject/collectionobjects_common.xsd">
+    <objectNumber>2</objectNumber>
+    <comments>description</comments>
+    <objectName>Left-handed screwdriver</objectName>
+    <title></title>
+    <briefDescriptions>
+        <!-- First value instance of this repeatable field is non-blank -->
+        <briefDescription>data</briefDescription>
+        <briefDescription></briefDescription>
+        <briefDescription>bob2</briefDescription>
+    </briefDescriptions>
+</ns2:collectionobjects_common>