dion        2004/12/09 22:25:50

  Modified:    jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util
                        suite.jelly
               jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util
                        PropertiesTag.java
  Added:       jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util
                        deletable.properties
  Log:
  Jelly-172. properties tag doesn't close files
  
  Revision  Changes    Path
  1.7       +27 -0     
jakarta-commons/jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util/suite.jelly,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- suite.jelly       26 Oct 2004 16:42:56 -0000      1.6
  +++ suite.jelly       10 Dec 2004 06:25:49 -0000      1.7
  @@ -33,6 +33,7 @@
           

           <test:assert test="${tokens.size() == 4}"/>

   -->

  +

               

           <test:assertEquals expected="Test1" actual="${tokens[0]}"/>

           <test:assertEquals expected="Test2" actual="${tokens[1]}"/>

  @@ -64,6 +65,7 @@
         <util:available file="${base.dir}/project.xml">

             <j:set var="flag" value="found"/>

         </util:available>

  +

           

         <test:assertEquals expected="found" actual="${flag}">

             Should have found the file via the file $${base.dir}/project.xml 
with base.dir=${base.dir}

  @@ -90,6 +92,7 @@
         </test:assertEquals>

           

         <util:available uri="doesNotExist.xml">

  +

             <test:fail>The URI doesNotExist.xml should not exist!</test:fail>

         </util:available>

           

  @@ -101,6 +104,7 @@
       <test:assertEquals expected="A/B" actual="${testString}">

         Should have replaced a back slash with a forward one

       </test:assertEquals>

  +

       

       <j:set var="testString2"><util:replace oldChar="\" 
newChar="/">A\B</util:replace></j:set>

       <test:assertEquals expected="A/B" actual="${testString2}">

  @@ -115,6 +119,7 @@
       </test:assertEquals>

   

       <util:replace oldChar="ABC" newChar="123" value="CBABC" 
var="testString4" />

  +

       <test:assertEquals expected="CB1BC" actual="${testString4}">

         Should have only substituted the 1 for the A, since the

         old/newChar attributes were used.

  @@ -144,7 +149,25 @@
         Loaded properties value ${props}

       

     </test:case>

  +

     

  +  <test:case name="testPropertiesAreNotLocked">

  +      <j:set var="filename" 
value="${basedir}/target/test-classes/org/apache/commons/jelly/tags/util/deletable.properties"/>

  +      

  +      <util:properties file="${filename}"/>

  +      

  +      <j:new var="f" className="java.io.File">

  +        <j:arg type="java.lang.String" value="${filename}"/>

  +      </j:new>        

  +      <j:mute>

  +        ${f.delete()}

  +      </j:mute>

  +    

  +      <test:assertFalse test="${f.exists()}" >The file ${name} should no 
longer exist</test:assertFalse>

  +

  +  </test:case>

  +    

  +

     <test:case name="testFileTag">

         <util:file 
name="${basedir}/src/test/org/apache/commons/jelly/tags/util/suite.jelly" 

           var="suite" />

  @@ -154,6 +177,7 @@
     <test:case name="testSortBasic">

       <j:new var="testCollection" className="java.util.ArrayList"/>

       <j:mute>

  +

        ${testCollection.add('Hello')}

        ${testCollection.add('World')}

        ${testCollection.add('Jelly')}

  @@ -166,6 +190,7 @@
     

     <test:case name="testSortBean">

       <j:new var="testCollection" className="java.util.ArrayList"/>

  +

       <j:useBean var="cust1" class="org.apache.commons.jelly.util.Customer" 
city="Sydney" location="Australia" name="Fred Nerk"/>

       <j:useBean var="cust2" class="org.apache.commons.jelly.util.Customer" 
city="Melbourne" location="Australia" name="Joe Nerk"/>

       <j:useBean var="cust3" class="org.apache.commons.jelly.util.Customer" 
city="San Francisco" location="U.S.A." name="Colette Cool"/>

  @@ -177,6 +202,7 @@
       <!-- test sorting by the name property -->

       <util:sort var="sortedByName" items="${testCollection}" property="name"/>

       <test:assertEquals expected="Colette Cool" 
actual="${sortedByName[0].name}"/>

  +

       <test:assertEquals expected="Fred Nerk" 
actual="${sortedByName[1].name}"/>

       <test:assertEquals expected="Joe Nerk" actual="${sortedByName[2].name}"/>

   

  @@ -187,5 +213,6 @@
       <test:assertEquals expected="U.S.A." 
actual="${sortedByLocation[2].location}"/>

     

     </test:case>

  +

       

   </test:suite>

  
  
  
  1.1                  
jakarta-commons/jelly/jelly-tags/util/src/test/org/apache/commons/jelly/tags/util/deletable.properties
  
  Index: deletable.properties
  ===================================================================
  # Copyright 2002-2004 The Apache Software Foundation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  foo=ABC
  
  bar=XYZ
  
  
  1.7       +11 -2     
jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/PropertiesTag.java
  
  Index: PropertiesTag.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/jelly/jelly-tags/util/src/java/org/apache/commons/jelly/tags/util/PropertiesTag.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- PropertiesTag.java        9 Sep 2004 12:22:43 -0000       1.6
  +++ PropertiesTag.java        10 Dec 2004 06:25:50 -0000      1.7
  @@ -75,7 +75,16 @@
           } catch (IOException e) {
               throw new JellyTagException("properties tag could not load from 
file",e);
           }
  -
  +        finally {
  +            if (is != null) {
  +                try {
  +                    is.close();
  +                } catch (IOException ioe) {
  +                    ;
  +                }   
  +            }
  +        }           
  +        
           if (var != null) {
               context.setVariable(var, props);
           }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to