jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r789338 - in /jackrabbit/trunk/jackrabbit-jcr-tests/src/main/java/org/apache/jackrabbit/test/api: BinaryPropertyTest.java SetValueBinaryTest.java
Date Mon, 29 Jun 2009 14:15:34 GMT
Author: mreutegg
Date: Mon Jun 29 14:15:34 2009
New Revision: 789338

URL: http://svn.apache.org/viewvc?rev=789338&view=rev
Log:
JCR-2085: test case (TCK) maintenance for JCR 2.0
- client must call Binary.dispose() when done with binary

Modified:
    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

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=789338&r1=789337&r2=789338&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
Mon Jun 29 14:15:34 2009
@@ -98,28 +98,32 @@
     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
+            InputStream in = bin.getStream();
+            InputStream in2 = bin.getStream();
             try {
-                in.close();
-            } catch (IOException ignore) {}
-            if (in2 != in) {
+                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 {
-                    in2.close();
+                    in.close();
                 } catch (IOException ignore) {}
+                if (in2 != in) {
+                    try {
+                        in2.close();
+                    } catch (IOException ignore) {}
+                }
             }
+        } finally {
+            bin.dispose();
         }
     }
 
@@ -203,24 +207,29 @@
     public void testValueJcr2() throws IOException, RepositoryException {
         Value val = PropertyUtil.getValue(prop);
         InputStream in = val.getStream();
-        InputStream in2 = val.getBinary().getStream();
+        Binary bin = val.getBinary();
         try {
-            int b = in.read();
-            while (b != -1) {
-                int b2 = in2.read();
+            InputStream in2 = bin.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.", b, b2);
-                b = in.read();
+                        "return different values.", -1, in2.read());
+            } finally {
+                try {
+                    in.close();
+                } catch (IOException ignore) {}
+                try {
+                    in2.close();
+                } catch (IOException ignore) {}
             }
-            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) {}
+            bin.dispose();
         }
     }
 
@@ -379,7 +388,13 @@
      */
     public void testGetLengthJcr2() throws RepositoryException {
         Value val = PropertyUtil.getValue(prop);
-        long length = val.getBinary().getSize();
+        Binary binary = val.getBinary();
+        long length;
+        try {
+            length = binary.getSize();
+        } finally {
+            binary.dispose();
+        }
         long bytes = PropertyUtil.countBytes(prop.getValue());
         if (bytes != -1) {
             assertEquals("Binary.getSize() returns wrong number of bytes.",
@@ -419,43 +434,47 @@
     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()));
+        try {
+            byte[] buf = new byte[0x1000];
 
-        //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 that reading behind EOF returns -1
+            assertEquals("reading behind EOF must return -1", -1, bin.read(buf, bin.getSize()));
 
-        //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.", (byte) b, content[k]);
+            //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.", (byte) b, content[k]);
+                }
+                assertEquals("unexpected content length", k, content.length);
+            } finally {
+                try {
+                    in.close();
+                } catch (IOException ignore) {}
             }
-            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]);
+            //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]);
+            }
+        } finally {
+            bin.dispose();
         }
     }
     

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=789338&r1=789337&r2=789338&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
Mon Jun 29 14:15:34 2009
@@ -121,11 +121,16 @@
     public void testBinarySessionJcr2() throws RepositoryException, IOException {
         property1.setValue(value);
         superuser.save();
-        InputStream in = property1.getValue().getBinary().getStream();
+        Binary bin = property1.getValue().getBinary();
         try {
-            compareStream(data, in);
+            InputStream in = bin.getStream();
+            try {
+                compareStream(data, in);
+            } finally {
+                in.close();
+            }
         } finally {
-            in.close();
+            bin.dispose();
         }
     }
 
@@ -155,14 +160,18 @@
      */
     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);
+            property1.setValue(bin);
+            node.save();
+            bin = property1.getValue().getBinary();
+            InputStream in = bin.getStream();
+            try {
+                compareStream(data, in);
+            } finally {
+                in.close();
+            }
         } finally {
-            in.close();
+            bin.dispose();
         }
     }
 



Mime
View raw message