jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r779583 - in /jackrabbit/trunk: jackrabbit-core/ jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/ jackrabbit-spi2jcr/
Date Thu, 28 May 2009 12:34:48 GMT
Author: reschke
Date: Thu May 28 12:34:48 2009
New Revision: 779583

URL: http://svn.apache.org/viewvc?rev=779583&view=rev
Log:
JCR-2056: add test cases (some cause failures, excluded for now)

Modified:
    jackrabbit/trunk/jackrabbit-core/pom.xml
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
    jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
    jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml

Modified: jackrabbit/trunk/jackrabbit-core/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/pom.xml?rev=779583&r1=779582&r2=779583&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-core/pom.xml Thu May 28 12:34:48 2009
@@ -88,6 +88,8 @@
               <name>known.issues</name>
               <value>
                 org.apache.jackrabbit.core.xml.DocumentViewTest#testMultiValue
+                org.apache.jackrabbit.test.api.BinaryPropertyTest#testRandomAccess
+                org.apache.jackrabbit.test.api.SetValueBinaryTest#testBinaryParentJcr2
                 org.apache.jackrabbit.test.api.ShareableNodeTest#testSharedNodePath
                 org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitialNumberOfLinearVersions
                 org.apache.jackrabbit.test.api.version.VersionHistoryTest#testInitiallyGetAllLinearVersionsContainsTheRootAndTheBaseVersion

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java?rev=779583&r1=779582&r2=779583&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
Thu May 28 12:34:48 2009
@@ -18,12 +18,15 @@
 
 import org.apache.jackrabbit.test.NotExecutableException;
 
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+
+import javax.jcr.Binary;
 import javax.jcr.PropertyType;
-import javax.jcr.Value;
 import javax.jcr.RepositoryException;
+import javax.jcr.Value;
 import javax.jcr.ValueFormatException;
-import java.io.InputStream;
-import java.io.IOException;
 
 /**
  * Tests a binary property. If the workspace does not contain a node with a
@@ -89,6 +92,38 @@
     }
 
     /**
+     * Tests that when Binary.getStream() is called a second time a new stream
+     * object is returned.
+     */
+    public void testSameStreamJcr2() throws RepositoryException, IOException {
+        Value val = PropertyUtil.getValue(prop);
+        Binary bin = val.getBinary();
+        InputStream in = bin.getStream();
+        InputStream in2 = bin.getStream();
+        try {
+            assertNotSame("Value.getStream() called on a new value " +
+                    "object should return a different Stream object.", in, in2);
+            //check if both streams can be read independently but contain the same bytes
+            int n,n2;
+            while ((n = in.read()) != -1) {
+                n2 = in2.read();
+                assertEquals("streams from the same binary object should have identical content",
n, n2);
+            }
+            assertEquals("streams from the same binary object should have identical content",
-1, in2.read());
+        } finally {
+            // cleaning up
+            try {
+                in.close();
+            } catch (IOException ignore) {}
+            if (in2 != in) {
+                try {
+                    in2.close();
+                } catch (IOException ignore) {}
+            }
+        }
+    }
+
+    /**
      * Tests the failure of calling Property.getStream() on a multivalue
      * property.
      */
@@ -110,6 +145,22 @@
     }
 
     /**
+     * Tests the failure of calling Property.getBinary() on a multivalue
+     * property.
+     */
+    public void testMultiValueJcr2() throws RepositoryException, IOException {
+        if (multiple) {
+            try {
+                prop.getBinary();
+                fail("Calling getStream() on a multivalue property " +
+                        "should throw a ValueFormatException.");
+            } catch (ValueFormatException vfe) {
+                // ok
+            }
+        }
+    }
+
+    /**
      * Tests that Property.getStream() delivers the same as Value.getStream().
      * We check this by reading each byte of the two streams and assuring that
      * they are equal.
@@ -145,6 +196,35 @@
     }
 
     /**
+     * Tests that Value.getStream() delivers the same as Value.getBinary.getStream().
+     * We check this by reading each byte of the two streams and assuring that
+     * they are equal.
+     */
+    public void testValueJcr2() throws IOException, RepositoryException {
+        Value val = PropertyUtil.getValue(prop);
+        InputStream in = val.getStream();
+        InputStream in2 = val.getBinary().getStream();
+        try {
+            int b = in.read();
+            while (b != -1) {
+                int b2 = in2.read();
+                assertEquals("Value.getStream() and Value.getBinary().getStream() " +
+                        "return different values.", b, b2);
+                b = in.read();
+            }
+            assertEquals("Value.getStream() and Value.getBinary().getStream() " +
+                    "return different values.", -1, in2.read());
+        } finally {
+            try {
+                in.close();
+            } catch (IOException ignore) {}
+            try {
+                in2.close();
+            } catch (IOException ignore) {}
+        }
+    }
+
+    /**
      * Tests conversion from Binary type to Boolean type. This is done via
      * String conversion.
      */
@@ -295,6 +375,19 @@
     }
 
     /**
+     * Tests the Binary.getSize() method.
+     */
+    public void testGetLengthJcr2() throws RepositoryException {
+        Value val = PropertyUtil.getValue(prop);
+        long length = val.getBinary().getSize();
+        long bytes = PropertyUtil.countBytes(prop.getValue());
+        if (bytes != -1) {
+            assertEquals("Binary.getSize() returns wrong number of bytes.",
+                    bytes, length);
+        }
+    }
+
+    /**
      * Tests the Property.getLengths() method. The test is successful, if either
      * -1 is returned
      */
@@ -319,4 +412,51 @@
             }
         }
     }
+
+    /**
+     * Tests the Binary.read() method.
+     */
+    public void testRandomAccess() throws RepositoryException, IOException {
+        Value val = PropertyUtil.getValue(prop);
+        Binary bin = val.getBinary();
+        byte[] buf = new byte[0x1000];
+
+        //verify that reading behind EOF returns -1
+        assertEquals("reading behind EOF must return -1", -1, bin.read(buf, bin.getSize()));
+
+        //read content using Binary.read()
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        for (int cnt, pos = 0; (cnt = bin.read(buf, pos)) > 0; pos += cnt) {
+            out.write(buf, 0, cnt);
+        }
+        byte[] content = out.toByteArray();
+        assertEquals("unexpected content length", bin.getSize(), content.length);
+
+        //verify against stream
+        InputStream in = val.getStream();
+        try {
+            int k = 0;
+            for (int b; (b = in.read()) != -1; k++) {
+                assertEquals("Value.getStream().read() and Value.getBinary().read() " +
+                        "return different values.", b, content[k]);
+            }
+            assertEquals("unexpected content length", k, content.length);
+        } finally {
+            try {
+                in.close();
+            } catch (IOException ignore) {}
+        }
+
+        //verify random access
+        buf = new byte[1];
+        assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf, 0));
+        assertEquals("unexpected result of Value.getBinary.read()", content[0], buf[0]);
+        if (content.length > 0) {
+            assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf,
content.length - 1));
+            assertEquals("unexpected result of Value.getBinary.read()", content[content.length
- 1], buf[0]);
+            assertTrue("unexpected result of Value.getBinary.read()", -1 != bin.read(buf,
0));
+            assertEquals("unexpected result of Value.getBinary.read()", content[0], buf[0]);
+        }
+    }
+    
 }
\ No newline at end of file

Modified: jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java?rev=779583&r1=779582&r2=779583&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
(original)
+++ jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
Thu May 28 12:34:48 2009
@@ -19,14 +19,16 @@
 import org.apache.jackrabbit.test.AbstractJCRTest;
 import org.apache.jackrabbit.test.NotExecutableException;
 
-import javax.jcr.Property;
-import javax.jcr.Value;
-import javax.jcr.RepositoryException;
-import javax.jcr.Node;
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.IOException;
 
+import javax.jcr.Binary;
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Value;
+
 /**
  * Tests the various {@link Property#setValue(Value)} methods.
  * <p>
@@ -113,6 +115,21 @@
     }
 
     /**
+     * Test the persistence of a property modified with an BinaryValue parameter
+     * and saved from the Session
+     */
+    public void testBinarySessionJcr2() throws RepositoryException, IOException {
+        property1.setValue(value);
+        superuser.save();
+        InputStream in = property1.getValue().getBinary().getStream();
+        try {
+            compareStream(data, in);
+        } finally {
+            in.close();
+        }
+    }
+
+    /**
      * Test the persistence of a property modified with an input stream
      * parameter and saved from the parent Node
      */
@@ -133,6 +150,23 @@
     }
 
     /**
+     * Test the persistence of a property modified with an input stream
+     * parameter and saved from the parent Node
+     */
+    public void testBinaryParentJcr2() throws RepositoryException, IOException {
+        Binary bin = value.getBinary();
+        property1.setValue(bin);
+        node.save();
+        bin = property1.getValue().getBinary();
+        InputStream in = bin.getStream();
+        try {
+            compareStream(data, in);
+        } finally {
+            in.close();
+        }
+    }
+
+    /**
      * Test the deletion of a property by assigning it a null value, saved from
      * the Session
      */

Modified: jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml?rev=779583&r1=779582&r2=779583&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml (original)
+++ jackrabbit/trunk/jackrabbit-spi2jcr/pom.xml Thu May 28 12:34:48 2009
@@ -70,6 +70,12 @@
                 org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryTest#testReRegisteredNamespaceVisibility
                 org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryTest#testRegisteredNamespaceVisibility
                 org.apache.jackrabbit.value.BinaryValueTest#testBinaryValueEquals
+                org.apache.jackrabbit.test.api.BinaryPropertyTest#testSameStreamJcr2
+                org.apache.jackrabbit.test.api.BinaryPropertyTest#testValueJcr2
+                org.apache.jackrabbit.test.api.BinaryPropertyTest#testGetLengthJcr2
+                org.apache.jackrabbit.test.api.BinaryPropertyTest#testRandomAccess
+                org.apache.jackrabbit.test.api.SetValueBinaryTest#testBinarySessionJcr2
+                org.apache.jackrabbit.test.api.SetValueBinaryTest#testBinaryParentJcr2
                 org.apache.jackrabbit.test.api.lock.LockManagerTest
                 org.apache.jackrabbit.test.api.observation.GetDateTest
                 org.apache.jackrabbit.test.api.observation.GetIdentifierTest



Mime
View raw message