jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r374024 - /incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/
Date Wed, 01 Feb 2006 08:59:01 GMT
Author: stefan
Date: Wed Feb  1 00:58:52 2006
New Revision: 374024

URL: http://svn.apache.org/viewcvs?rev=374024&view=rev
Log:
proper stream handling in junit test cases: make sure streams returned by Value.getStream()
and Property.getStream() are closed

Modified:
    incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
    incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java
    incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/PropertyUtil.java
    incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
    incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
    incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
    incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/BinaryPropertyTest.java
Wed Feb  1 00:58:52 2006
@@ -57,10 +57,27 @@
         InputStream in2 = val.getStream();
         Value otherVal = PropertyUtil.getValue(prop);
         InputStream in3 = otherVal.getStream();
-        assertSame("Same InputStream object expected when " +
-                "Value.getStream is called twice.", in, in2);
-        assertNotSame("Value.getStream() called on a new value " +
-                "object should return a different Stream object.", in, in3);
+        try {
+            assertSame("Same InputStream object expected when " +
+                    "Value.getStream is called twice.", in, in2);
+            assertNotSame("Value.getStream() called on a new value " +
+                    "object should return a different Stream object.", in, in3);
+        } finally {
+            // cleaning up
+            try {
+                in.close();
+            } catch (IOException ignore) {}
+            if (in2 != in) {
+                try {
+                    in2.close();
+                } catch (IOException ignore) {}
+            }
+            if (in3 != in) {
+                try {
+                    in3.close();
+                } catch (IOException ignore) {}
+            }
+        }
     }
 
     /**
@@ -99,15 +116,24 @@
         } else {
             in2 = prop.getStream();
         }
-        int b = in.read();
-        while (b != -1) {
-            int b2 = in2.read();
+        try {
+            int b = in.read();
+            while (b != -1) {
+                int b2 = in2.read();
+                assertEquals("Value.getStream() and Property.getStream() " +
+                        "return different values.", b, b2);
+                b = in.read();
+            }
             assertEquals("Value.getStream() and Property.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 Property.getStream() " +
-                "return different values.", -1, in2.read());
     }
 
     /**

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ExportDocViewTest.java
Wed Feb  1 00:58:52 2006
@@ -963,7 +963,12 @@
 
         if (isBinary) {
             for (int i = 0; i < vals.length; i++) {
-                exportedVal += encodeBase64(vals[i].getStream());
+                InputStream in = vals[i].getStream();
+                try {
+                    exportedVal += encodeBase64(in);
+                } finally {
+                    in.close();
+                }
                 exportedVal += " ";
             }
         } else {

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/PropertyUtil.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/PropertyUtil.java?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/PropertyUtil.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/PropertyUtil.java
Wed Feb  1 00:58:52 2006
@@ -30,6 +30,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.IOException;
 
 /**
  * This class provides various utility methods that are used by the property
@@ -281,14 +283,22 @@
      */
     public static long countBytes(Value val) {
         int length = 0;
+        InputStream in = null;
         try {
-            BufferedInputStream bin = new BufferedInputStream(val.getStream());
+            in = val.getStream();
+            BufferedInputStream bin = new BufferedInputStream(in);
             while (bin.read() != -1) {
                 length++;
             }
             bin.close();
         } catch (Exception e) {
             length = -1;
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException ignore) {}
+            }
         }
         return length;
     }

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyConstraintViolationExceptionTest.java
Wed Feb  1 00:58:52 2006
@@ -29,6 +29,8 @@
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeType;
+import java.io.InputStream;
+import java.io.IOException;
 
 /**
  * <code>SetPropertyConstraintViolationExceptionTest</code> tests if
@@ -257,14 +259,19 @@
         }
 
         // test of signature setProperty(String name, InputStream value)
+        InputStream in = valueNotSatisfied1.getStream();
         try {
-            node.setProperty(propDef.getName(), valueNotSatisfied1.getStream());
+            node.setProperty(propDef.getName(), in);
             node.save();
             fail("setProperty(String name, InputStream value) must throw a " +
                     "ConstraintViolationException if the change would violate a " +
                     "node type constraint either immediately or on save");
         } catch (ConstraintViolationException e) {
             // success
+        } finally {
+            try {
+                in.close();
+            } catch (IOException ignore) {}
         }
 
         // test of signature setProperty(String name, Value value)

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetPropertyInputStreamTest.java
Wed Feb  1 00:58:52 2006
@@ -54,8 +54,13 @@
         testNode.setProperty(propertyName1, is1);
         superuser.save();
         is1 = new ByteArrayInputStream(bytes1);
-        assertTrue("Setting property with Node.setProperty(String, InputStream) and Session.save()
not working",
-                compareInputStreams(is1, testNode.getProperty(propertyName1).getStream()));
+        InputStream in = testNode.getProperty(propertyName1).getStream();
+        try {
+            assertTrue("Setting property with Node.setProperty(String, InputStream) and Session.save()
not working",
+                    compareInputStreams(is1, in));
+        } finally {
+            in.close();
+        }
     }
 
     /**
@@ -68,8 +73,13 @@
         testNode.setProperty(propertyName1, is2);
         superuser.save();
         is2 = new ByteArrayInputStream(bytes2);
-        assertTrue("Modifying property with Node.setProperty(String, InputStream) and Session.save()
not working",
-                compareInputStreams(is2, testNode.getProperty(propertyName1).getStream()));
+        InputStream in = testNode.getProperty(propertyName1).getStream();
+        try {
+            assertTrue("Modifying property with Node.setProperty(String, InputStream) and
Session.save() not working",
+                    compareInputStreams(is2, in));
+        } finally {
+            in.close();
+        }
     }
 
     /**
@@ -80,8 +90,13 @@
         testNode.setProperty(propertyName1, is1);
         testRootNode.save();
         is1 = new ByteArrayInputStream(bytes1);
-        assertTrue("Setting property with Node.setProperty(String, InputStream) and parentNode.save()
not working",
-                compareInputStreams(is1, testNode.getProperty(propertyName1).getStream()));
+        InputStream in = testNode.getProperty(propertyName1).getStream();
+        try {
+            assertTrue("Setting property with Node.setProperty(String, InputStream) and parentNode.save()
not working",
+                    compareInputStreams(is1, in));
+        } finally {
+            in.close();
+        }
     }
 
     /**
@@ -94,8 +109,13 @@
         testNode.setProperty(propertyName1, is2);
         testRootNode.save();
         is2 = new ByteArrayInputStream(bytes2);
-        assertTrue("Modifying property with Node.setProperty(String, InputStream) and parentNode.save()
not working",
-                compareInputStreams(is2, testNode.getProperty(propertyName1).getStream()));
+        InputStream in = testNode.getProperty(propertyName1).getStream();
+        try {
+            assertTrue("Modifying property with Node.setProperty(String, InputStream) and
parentNode.save() not working",
+                    compareInputStreams(is2, in));
+        } finally {
+            in.close();
+        }
     }
 
     /**

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueBinaryTest.java
Wed Feb  1 00:58:52 2006
@@ -83,7 +83,12 @@
     public void testBinarySession() throws RepositoryException, IOException {
         property1.setValue(value);
         superuser.save();
-        compareStream(data, property1.getValue().getStream());
+        InputStream in = property1.getValue().getStream();
+        try {
+            compareStream(data, in);
+        } finally {
+            in.close();
+        }
     }
 
     /**
@@ -91,9 +96,19 @@
      * parameter and saved from the parent Node
      */
     public void testBooleanParent() throws RepositoryException, IOException {
-        property1.setValue(value.getStream());
-        node.save();
-        compareStream(data, property1.getValue().getStream());
+        InputStream in = value.getStream();
+        try {
+            property1.setValue(in);
+            node.save();
+        } finally {
+            in.close();
+        }
+        in = property1.getValue().getStream();
+        try {
+            compareStream(data, in);
+        } finally {
+            in.close();
+        }
     }
 
     /**

Modified: incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java?rev=374024&r1=374023&r2=374024&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java
(original)
+++ incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/SetValueConstraintViolationExceptionTest.java
Wed Feb  1 00:58:52 2006
@@ -30,6 +30,8 @@
 import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.NodeTypeIterator;
 import javax.jcr.nodetype.NodeType;
+import java.io.InputStream;
+import java.io.IOException;
 
 /**
  * <code>SetValueConstraintViolationExceptionTest</code> tests if setValue()
@@ -89,14 +91,19 @@
         }
 
         // test of signature setValue(InputStream value)
+        InputStream in = valueNotSatisfied1.getStream();
         try {
-            prop.setValue(valueNotSatisfied1.getStream());
+            prop.setValue(in);
             node.save();
             fail("setValue(InputStream value) must throw a ConstraintViolationException "
+
                     "if the change would violate a node type constraint " +
                     "either immediately or on save");
         } catch (ConstraintViolationException e) {
             // success
+        } finally {
+            try {
+                in.close();
+            } catch (IOException ignore) {}
         }
 
         // test of signature setValue(Value value)



Mime
View raw message