Return-Path: Delivered-To: apmail-incubator-jackrabbit-commits-archive@www.apache.org Received: (qmail 65737 invoked from network); 1 Feb 2006 08:59:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 1 Feb 2006 08:59:44 -0000 Received: (qmail 85451 invoked by uid 500); 1 Feb 2006 08:59:43 -0000 Mailing-List: contact jackrabbit-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jackrabbit-dev@incubator.apache.org Delivered-To: mailing list jackrabbit-commits@incubator.apache.org Received: (qmail 85440 invoked by uid 500); 1 Feb 2006 08:59:43 -0000 Delivered-To: apmail-incubator-jackrabbit-cvs@incubator.apache.org Received: (qmail 85437 invoked by uid 99); 1 Feb 2006 08:59:43 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Feb 2006 00:59:43 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Wed, 01 Feb 2006 00:59:42 -0800 Received: (qmail 65655 invoked by uid 65534); 1 Feb 2006 08:59:22 -0000 Message-ID: <20060201085922.65653.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r374024 - /incubator/jackrabbit/trunk/jackrabbit/src/test/java/org/apache/jackrabbit/test/api/ Date: Wed, 01 Feb 2006 08:59:01 -0000 To: jackrabbit-cvs@incubator.apache.org From: stefan@apache.org X-Mailer: svnmailer-1.0.5 X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N 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; /** * SetPropertyConstraintViolationExceptionTest 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; /** * SetValueConstraintViolationExceptionTest 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)