commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1102402 [20/20] - in /commons/sandbox/digester3/trunk/src: main/java/org/apache/commons/digester3/ main/java/org/apache/commons/digester3/annotations/ main/java/org/apache/commons/digester3/annotations/handlers/ main/java/org/apache/common...
Date Thu, 12 May 2011 18:03:33 GMT
Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/substitution/VariableExpansionTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/substitution/VariableExpansionTestCase.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/substitution/VariableExpansionTestCase.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/substitution/VariableExpansionTestCase.java Thu May 12 18:03:26 2011
@@ -16,7 +16,6 @@
  * limitations under the License.
  */
 
-
 package org.apache.commons.digester3.substitution;
 
 import static org.junit.Assert.*;
@@ -35,33 +34,37 @@ import org.junit.Test;
 import org.xml.sax.SAXException;
 
 /**
- * <p>Test Case for the variable expansion facility in Digester.
- *
+ * <p>
+ * Test Case for the variable expansion facility in Digester.
+ * 
  * @author Simon Kitching
  * @version $Revision$ $Date$
  */
 
-public class VariableExpansionTestCase {
+public class VariableExpansionTestCase
+{
 
     // --------------------------------------------------- Overall Test Methods
 
     // method used in tests4
     private LinkedList<SimpleTestBean> simpleTestBeans = new LinkedList<SimpleTestBean>();
-    public void addSimpleTestBean(SimpleTestBean bean) {
-        simpleTestBeans.add(bean);
+
+    public void addSimpleTestBean( SimpleTestBean bean )
+    {
+        simpleTestBeans.add( bean );
     }
-    
+
     // implementation of source shared by the variable expander and
     // is updatable during digesting via an Ant-like property element
-    private HashMap<String, Object> mutableSource=new HashMap<String, Object>();
+    private HashMap<String, Object> mutableSource = new HashMap<String, Object>();
 
     /**
-     * Used in test case "testExpansionWithMutableSource", where the
-     * set of variables available to be substituted into the xml is
-     * updated as the xml is parsed.
+     * Used in test case "testExpansionWithMutableSource", where the set of variables available to be substituted into
+     * the xml is updated as the xml is parsed.
      */
-    public void addProperty(String key, String value) {
-        mutableSource.put(key, value);
+    public void addProperty( String key, String value )
+    {
+        mutableSource.put( key, value );
     }
 
     /**
@@ -69,24 +72,24 @@ public class VariableExpansionTestCase {
      * 
      * @return a Digester with rules and variable substitutor
      */
-    private Digester createDigesterThatCanDoAnt() {
+    private Digester createDigesterThatCanDoAnt()
+    {
         Digester digester = new Digester();
 
         MultiVariableExpander expander = new MultiVariableExpander();
-        expander.addSource("$", mutableSource);
-        digester.setSubstitutor(new VariableSubstitutor(expander));
+        expander.addSource( "$", mutableSource );
+        digester.setSubstitutor( new VariableSubstitutor( expander ) );
 
         int useRootObj = -1;
-        Class<?>[] callerArgTypes = new Class[] {String.class, String.class};
-        CallMethodRule caller = new CallMethodRule(useRootObj, "addProperty",
-            callerArgTypes.length, callerArgTypes);
-        digester.addRule("root/property", caller);
-        digester.addCallParam("root/property", 0, "name");
-        digester.addCallParam("root/property", 1, "value");
-
-        digester.addObjectCreate("root/bean", SimpleTestBean.class);
-        digester.addSetProperties("root/bean");
-        digester.addSetNext("root/bean", "addSimpleTestBean");
+        Class<?>[] callerArgTypes = new Class[] { String.class, String.class };
+        CallMethodRule caller = new CallMethodRule( useRootObj, "addProperty", callerArgTypes.length, callerArgTypes );
+        digester.addRule( "root/property", caller );
+        digester.addCallParam( "root/property", 0, "name" );
+        digester.addCallParam( "root/property", 1, "value" );
+
+        digester.addObjectCreate( "root/bean", SimpleTestBean.class );
+        digester.addSetProperties( "root/bean" );
+        digester.addSetNext( "root/bean", "addSimpleTestBean" );
         return digester;
     }
 
@@ -96,103 +99,105 @@ public class VariableExpansionTestCase {
      * Test that by default no expansion occurs.
      */
     @Test
-    public void testNoExpansion() throws SAXException, IOException {
+    public void testNoExpansion()
+        throws SAXException, IOException
+    {
 
         String xml = "<root alpha='${attr1}' beta='var{attr2}'/>";
-        StringReader input = new StringReader(xml);
+        StringReader input = new StringReader( xml );
         Digester digester = new Digester();
-        
+
         // Configure the digester as required
-        digester.addObjectCreate("root", SimpleTestBean.class);
-        digester.addSetProperties("root");
+        digester.addObjectCreate( "root", SimpleTestBean.class );
+        digester.addSetProperties( "root" );
 
         // Parse our test input.
-        SimpleTestBean root = digester.parse(input);
+        SimpleTestBean root = digester.parse( input );
 
-        assertNotNull("Digester returned no object", root);
-        
-        assertEquals("${attr1}", root.getAlpha());
-        assertEquals("var{attr2}", root.getBeta());
+        assertNotNull( "Digester returned no object", root );
+
+        assertEquals( "${attr1}", root.getAlpha() );
+        assertEquals( "var{attr2}", root.getBeta() );
     }
 
     /**
      * Test that a MultiVariableExpander with no sources does no expansion.
      */
     @Test
-    public void testExpansionWithNoSource() throws SAXException, IOException {
+    public void testExpansionWithNoSource()
+        throws SAXException, IOException
+    {
 
         String xml = "<root alpha='${attr1}' beta='var{attr2}'/>";
-        StringReader input = new StringReader(xml);
+        StringReader input = new StringReader( xml );
         Digester digester = new Digester();
-        
+
         // Configure the digester as required
         MultiVariableExpander expander = new MultiVariableExpander();
-        digester.setSubstitutor(new VariableSubstitutor(expander));
-        digester.addObjectCreate("root", SimpleTestBean.class);
-        digester.addSetProperties("root");
+        digester.setSubstitutor( new VariableSubstitutor( expander ) );
+        digester.addObjectCreate( "root", SimpleTestBean.class );
+        digester.addSetProperties( "root" );
 
         // Parse our test input.
-        SimpleTestBean root = digester.parse(input);
+        SimpleTestBean root = digester.parse( input );
+
+        assertNotNull( "Digester returned no object", root );
 
-        assertNotNull("Digester returned no object", root);
-        
-        assertEquals("${attr1}", root.getAlpha());
-        assertEquals("var{attr2}", root.getBeta());
+        assertEquals( "${attr1}", root.getAlpha() );
+        assertEquals( "var{attr2}", root.getBeta() );
     }
 
     /**
-     * Test that a MultiVariableExpander with multiple sources works.
-     * It also tests that expansion works ok where multiple elements
-     * exist.
+     * Test that a MultiVariableExpander with multiple sources works. It also tests that expansion works ok where
+     * multiple elements exist.
      */
     @Test
-    public void testExpansionWithMultipleSources() throws SAXException, IOException {
+    public void testExpansionWithMultipleSources()
+        throws SAXException, IOException
+    {
 
-        String xml = 
-            "<root>" +
-              "<bean alpha='${attr1}' beta='var{attr1}'/>" +
-              "<bean alpha='${attr2}' beta='var{attr2}'/>" +
-            "</root>";
-            
-        StringReader input = new StringReader(xml);
+        String xml =
+            "<root>" + "<bean alpha='${attr1}' beta='var{attr1}'/>" + "<bean alpha='${attr2}' beta='var{attr2}'/>"
+                + "</root>";
+
+        StringReader input = new StringReader( xml );
         Digester digester = new Digester();
-        
+
         // Configure the digester as required
         HashMap<String, Object> source1 = new HashMap<String, Object>();
-        source1.put("attr1", "source1.attr1");
-        source1.put("attr2", "source1.attr2"); // should not be used
-        
+        source1.put( "attr1", "source1.attr1" );
+        source1.put( "attr2", "source1.attr2" ); // should not be used
+
         HashMap<String, Object> source2 = new HashMap<String, Object>();
-        source2.put("attr1", "source2.attr1"); // should not be used
-        source2.put("attr2", "source2.attr2");
-        
-        
+        source2.put( "attr1", "source2.attr1" ); // should not be used
+        source2.put( "attr2", "source2.attr2" );
+
         MultiVariableExpander expander = new MultiVariableExpander();
-        expander.addSource("$", source1);
-        expander.addSource("var", source2);
-        
-        digester.setSubstitutor(new VariableSubstitutor(expander));
-        digester.addObjectCreate("root/bean", SimpleTestBean.class);
-        digester.addSetProperties("root/bean");
-        digester.addSetNext("root/bean", "addSimpleTestBean");
+        expander.addSource( "$", source1 );
+        expander.addSource( "var", source2 );
+
+        digester.setSubstitutor( new VariableSubstitutor( expander ) );
+        digester.addObjectCreate( "root/bean", SimpleTestBean.class );
+        digester.addSetProperties( "root/bean" );
+        digester.addSetNext( "root/bean", "addSimpleTestBean" );
 
         // Parse our test input.
         this.simpleTestBeans.clear();
-        digester.push(this);
-        digester.parse(input);
+        digester.push( this );
+        digester.parse( input );
 
-        assertEquals(2, this.simpleTestBeans.size());
+        assertEquals( 2, this.simpleTestBeans.size() );
 
         {
-        SimpleTestBean bean = this.simpleTestBeans.get(0);
-        assertEquals("source1.attr1", bean.getAlpha());
-        assertEquals("source2.attr1", bean.getBeta());
+            SimpleTestBean bean = this.simpleTestBeans.get( 0 );
+            assertEquals( "source1.attr1", bean.getAlpha() );
+            assertEquals( "source2.attr1", bean.getBeta() );
         }
 
         {
-        SimpleTestBean bean = this.simpleTestBeans.get(1);
-        assertEquals("source1.attr2", bean.getAlpha());
-        assertEquals("source2.attr2", bean.getBeta());
+            SimpleTestBean bean = this.simpleTestBeans.get( 1 );
+            assertEquals( "source1.attr2", bean.getAlpha() );
+            assertEquals( "source2.attr2", bean.getBeta() );
         }
     }
 
@@ -200,140 +205,127 @@ public class VariableExpansionTestCase {
      * Test expansion of text in element bodies.
      */
     @Test
-    public void testBodyExpansion() throws SAXException, IOException {
+    public void testBodyExpansion()
+        throws SAXException, IOException
+    {
 
-        String xml = 
-            "<root>" + 
-            "Twas noun{1} and the noun{2}" +
-            " did verb{1} and verb{2} in the noun{3}" +
-            "</root>";
+        String xml = "<root>" + "Twas noun{1} and the noun{2}" + " did verb{1} and verb{2} in the noun{3}" + "</root>";
 
-        StringReader input = new StringReader(xml);
+        StringReader input = new StringReader( xml );
         Digester digester = new Digester();
-        
+
         // Configure the digester as required
         HashMap<String, Object> nouns = new HashMap<String, Object>();
-        nouns.put("1", "brillig");
-        nouns.put("2", "slithy toves");
-        nouns.put("3", "wabe");
-        
+        nouns.put( "1", "brillig" );
+        nouns.put( "2", "slithy toves" );
+        nouns.put( "3", "wabe" );
+
         HashMap<String, Object> verbs = new HashMap<String, Object>();
-        verbs.put("1", "gyre");
-        verbs.put("2", "gimble");
-        
+        verbs.put( "1", "gyre" );
+        verbs.put( "2", "gimble" );
+
         MultiVariableExpander expander = new MultiVariableExpander();
-        expander.addSource("noun", nouns);
-        expander.addSource("verb", verbs);
-        digester.setSubstitutor(new VariableSubstitutor(expander));
-        
-        digester.addObjectCreate("root", SimpleTestBean.class);
-        digester.addCallMethod("root", "setAlpha", 0);
+        expander.addSource( "noun", nouns );
+        expander.addSource( "verb", verbs );
+        digester.setSubstitutor( new VariableSubstitutor( expander ) );
+
+        digester.addObjectCreate( "root", SimpleTestBean.class );
+        digester.addCallMethod( "root", "setAlpha", 0 );
 
         // Parse our test input.
-        SimpleTestBean root = digester.parse(input);
+        SimpleTestBean root = digester.parse( input );
 
-        assertNotNull("Digester returned no object", root);
-        
-        assertEquals(
-            "Twas brillig and the slithy toves" +
-            " did gyre and gimble in the wabe",
-            root.getAlpha());
+        assertNotNull( "Digester returned no object", root );
+
+        assertEquals( "Twas brillig and the slithy toves" + " did gyre and gimble in the wabe", root.getAlpha() );
     }
 
     /**
      * Test that an unknown variable causes a RuntimeException.
      */
     @Test
-    public void testExpansionException() throws IOException {
+    public void testExpansionException()
+        throws IOException
+    {
 
         String xml = "<root alpha='${attr1}'/>";
-        StringReader input = new StringReader(xml);
+        StringReader input = new StringReader( xml );
         Digester digester = new Digester();
-        
+
         // Configure the digester as required
         MultiVariableExpander expander = new MultiVariableExpander();
-        expander.addSource("$", new HashMap<String, Object>());
-        digester.setSubstitutor(new VariableSubstitutor(expander));
-        
-        digester.addObjectCreate("root", SimpleTestBean.class);
-        digester.addSetProperties("root");
+        expander.addSource( "$", new HashMap<String, Object>() );
+        digester.setSubstitutor( new VariableSubstitutor( expander ) );
+
+        digester.addObjectCreate( "root", SimpleTestBean.class );
+        digester.addSetProperties( "root" );
 
         // Parse our test input.
-        try {
-            digester.parse(input);
-            fail("Exception expected due to unknown variable.");
-        } catch(SAXException e) {
+        try
+        {
+            digester.parse( input );
+            fail( "Exception expected due to unknown variable." );
+        }
+        catch ( SAXException e )
+        {
             // expected, due to reference to undefined variable
         }
     }
 
     /**
-     * First of two tests added to verify that the substitution
-     * framework is capable of processing Ant-like properties.
-     *
-     * The tests above essentially verify that if a property
-     * was pre-set (e.g. using the "-D" option to Ant), then
-     * the property could be expanded via a variable used either
-     * in an attribute or in body text.
-     *
-     * This test shows that if properties were also set while
-     * processing a document, you could still perform variable
-     * expansion (i.e. just like using the "property" task in Ant).
-     *
+     * First of two tests added to verify that the substitution framework is capable of processing Ant-like properties.
+     * The tests above essentially verify that if a property was pre-set (e.g. using the "-D" option to Ant), then the
+     * property could be expanded via a variable used either in an attribute or in body text. This test shows that if
+     * properties were also set while processing a document, you could still perform variable expansion (i.e. just like
+     * using the "property" task in Ant).
+     * 
      * @throws IOException
      * @throws SAXException
      */
     @Test
-    public void testExpansionWithMutableSource() throws SAXException, IOException {
-        String xml =
-            "<root>" +
-              "<property name='attr' value='prop.value'/>" +
-              "<bean alpha='${attr}'/>" +
-            "</root>";
-        StringReader input = new StringReader(xml);
+    public void testExpansionWithMutableSource()
+        throws SAXException, IOException
+    {
+        String xml = "<root>" + "<property name='attr' value='prop.value'/>" + "<bean alpha='${attr}'/>" + "</root>";
+        StringReader input = new StringReader( xml );
         Digester digester = createDigesterThatCanDoAnt();
 
         simpleTestBeans.clear();
-        digester.push(this);
-        digester.parse(input);
+        digester.push( this );
+        digester.parse( input );
 
-        assertEquals(1, simpleTestBeans.size());
-        SimpleTestBean bean = simpleTestBeans.get(0);
-        assertEquals("prop.value", bean.getAlpha());
+        assertEquals( 1, simpleTestBeans.size() );
+        SimpleTestBean bean = simpleTestBeans.get( 0 );
+        assertEquals( "prop.value", bean.getAlpha() );
     }
 
     /**
-     * Second of two tests added to verify that the substitution
-     * framework is capable of processing Ant-like properties.
-     *
-     * This test shows that if properties were also set while
-     * processing a document, the resulting variables could also
-     * be expanded within a property element.  This is thus
-     * effectively a "closure" test, since it shows that the
-     * mechanism used to bind properties is also capable of
-     * having property values that are driven by property variables.
-     *
+     * Second of two tests added to verify that the substitution framework is capable of processing Ant-like properties.
+     * This test shows that if properties were also set while processing a document, the resulting variables could also
+     * be expanded within a property element. This is thus effectively a "closure" test, since it shows that the
+     * mechanism used to bind properties is also capable of having property values that are driven by property
+     * variables.
+     * 
      * @throws IOException
      * @throws SAXException
      */
     @Test
-    public void testExpansionOfPropertyInProperty() throws SAXException, IOException {
+    public void testExpansionOfPropertyInProperty()
+        throws SAXException, IOException
+    {
         String xml =
-            "<root>" +
-              "<property name='attr1' value='prop.value1'/>" +
-              "<property name='attr2' value='substituted-${attr1}'/>" +
-              "<bean alpha='${attr2}'/>" +
-            "</root>";
-        StringReader input = new StringReader(xml);
+            "<root>" + "<property name='attr1' value='prop.value1'/>"
+                + "<property name='attr2' value='substituted-${attr1}'/>" + "<bean alpha='${attr2}'/>" + "</root>";
+        StringReader input = new StringReader( xml );
         Digester digester = createDigesterThatCanDoAnt();
 
         simpleTestBeans.clear();
-        digester.push(this);
-        digester.parse(input);
+        digester.push( this );
+        digester.parse( input );
 
-        assertEquals(1, simpleTestBeans.size());
-        SimpleTestBean bean = simpleTestBeans.get(0);
-        assertEquals("substituted-prop.value1", bean.getAlpha());
+        assertEquals( 1, simpleTestBeans.size() );
+        SimpleTestBean bean = simpleTestBeans.get( 0 );
+        assertEquals( "substituted-prop.value1", bean.getAlpha() );
     }
 
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/CallParamTestObject.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/CallParamTestObject.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/CallParamTestObject.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/CallParamTestObject.java Thu May 12 18:03:26 2011
@@ -18,56 +18,66 @@
 
 package org.apache.commons.digester3.xmlrules;
 
-
-
 /**
  * Object for use with testing call param rules.
- *
+ * 
  * @author Robert Burrell Donkin
  */
-public class CallParamTestObject {
-    
+public class CallParamTestObject
+{
+
     private String left = "UNSET";
+
     private String right = "UNSET";
+
     private String middle = "UNSET";
-    
-    public void triple(String left, String middle, String right) {
+
+    public void triple( String left, String middle, String right )
+    {
         this.left = left;
         this.right = right;
         this.middle = middle;
     }
-   
-    public void duo(String left, String right) {
+
+    public void duo( String left, String right )
+    {
         this.left = left;
         this.right = right;
     }
-      
-    public String getLeft() {
+
+    public String getLeft()
+    {
         return left;
     }
-    
-    public String getRight() {
+
+    public String getRight()
+    {
         return right;
     }
-    
-    public String getMiddle() {
+
+    public String getMiddle()
+    {
         return middle;
     }
 
-    public void setLeft(String left) {
-        this.left=left;
+    public void setLeft( String left )
+    {
+        this.left = left;
     }
-    
-    public void setRight(String right) {
+
+    public void setRight( String right )
+    {
         this.right = right;
     }
-    
-    public void setMiddle(String middle) {
+
+    public void setMiddle( String middle )
+    {
         this.middle = middle;
     }
-    
+
     @Override
-    public String toString() {
+    public String toString()
+    {
         return "LEFT: " + left + " MIDDLE:" + middle + " RIGHT:" + right;
     }
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderRulesTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderRulesTest.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderRulesTest.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderRulesTest.java Thu May 12 18:03:26 2011
@@ -28,105 +28,77 @@ import org.xml.sax.InputSource;
 
 /**
  * Tests for digester loader rule implementations,
- *
+ * 
  * @author Robert Burrell Donkin
  */
 
-public class DigesterLoaderRulesTest {
+public class DigesterLoaderRulesTest
+{
 
     @Test
     /** Basic test for object param rule */
-    public void testObjectParamRule() throws Exception {
-        String xmlRules = 
-            "<?xml version='1.0'?>" +
-            "<digester-rules>" + 
-            "  <pattern value='root'>" +
-            "     <pattern value='foo'>" +
-            "        <call-method-rule " +
-            "                methodname='duo' " +
-            "                paramcount='2' " +
-            "                paramtypes='java.lang.String,java.lang.String'/>" +
-            "        <pattern value='bar'>" +
-            "           <object-param-rule paramnumber='0' type='java.lang.String' />" +
-            "        </pattern>" +
-            "        <pattern value='rab'>" +
-            "           <object-param-rule paramnumber='1' type='java.lang.String' value='tester.test' />" +
-            "        </pattern>" +
-            "     </pattern>" +
-            "   </pattern>" +
-            "</digester-rules>";
-        
-        String xml = 
-            "<?xml version='1.0'?>" + 
-            "<root>" +
-            "  <foo>" +
-            "    <bar/>" +
-            "    <rab/>" +
-            "  </foo>" +
-            "</root>";
-            
+    public void testObjectParamRule()
+        throws Exception
+    {
+        String xmlRules =
+            "<?xml version='1.0'?>" + "<digester-rules>" + "  <pattern value='root'>" + "     <pattern value='foo'>"
+                + "        <call-method-rule " + "                methodname='duo' "
+                + "                paramcount='2' "
+                + "                paramtypes='java.lang.String,java.lang.String'/>" + "        <pattern value='bar'>"
+                + "           <object-param-rule paramnumber='0' type='java.lang.String' />" + "        </pattern>"
+                + "        <pattern value='rab'>"
+                + "           <object-param-rule paramnumber='1' type='java.lang.String' value='tester.test' />"
+                + "        </pattern>" + "     </pattern>" + "   </pattern>" + "</digester-rules>";
+
+        String xml =
+            "<?xml version='1.0'?>" + "<root>" + "  <foo>" + "    <bar/>" + "    <rab/>" + "  </foo>" + "</root>";
+
         CallParamTestObject testObject = new CallParamTestObject();
-        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(xmlRules)));
-        digester.push(testObject);    
-        digester.parse(new InputSource(new StringReader(xml)));
-        assertEquals("First param", "", testObject.getLeft());
-        assertEquals("Param with default set", "tester.test", testObject.getRight());
+        Digester digester = DigesterLoader.createDigester( new InputSource( new StringReader( xmlRules ) ) );
+        digester.push( testObject );
+        digester.parse( new InputSource( new StringReader( xml ) ) );
+        assertEquals( "First param", "", testObject.getLeft() );
+        assertEquals( "Param with default set", "tester.test", testObject.getRight() );
     }
-    
+
     /** Test for call method rule with target offset */
     @Test
-    public void testCallMethodRuleTargetOffset() throws Exception {
-        String xmlRules = 
-            "<?xml version='1.0'?>" +
-            "<digester-rules>" + 
-            "  <pattern value='root'>" +
-            "     <pattern value='call-top-object'>" +
-            "        <call-method-rule " +
-            "                methodname='setMiddle' " +
-            "                targetoffset='0' " +
-            "                paramcount='1' " +
-            "                paramtypes='java.lang.String' />" +
-            "        <call-param-rule paramnumber='0' />" +
-            "     </pattern>" +
-            "     <pattern value='call-parent-object'>" +
-            "        <call-method-rule " +
-            "                methodname='setLeft' " +
-            "                targetoffset='1' " +
-            "                paramcount='1' " +
-            "                paramtypes='java.lang.String' />" +
-            "        <call-param-rule paramnumber='0' />" +
-            "     </pattern>" +
-            "     <pattern value='call-root-object'>" +
-            "        <call-method-rule " +
-            "                methodname='setRight' " +
-            "                targetoffset='-1' " +
-            "                paramcount='1' " +
-            "                paramtypes='java.lang.String' />" +
-            "        <call-param-rule paramnumber='0' />" +
-            "     </pattern>" +
-            "   </pattern>" +
-            "</digester-rules>";
-        
-        String xml = 
-            "<?xml version='1.0'?>" + 
-            "<root>" +
-            "  <call-top-object>DataForTheTopObject</call-top-object>" +
-            "  <call-parent-object>DataForTheParentObject</call-parent-object>" +
-            "  <call-root-object>DataForTheRootObject</call-root-object>" +
-            "</root>";
-            
+    public void testCallMethodRuleTargetOffset()
+        throws Exception
+    {
+        String xmlRules =
+            "<?xml version='1.0'?>" + "<digester-rules>" + "  <pattern value='root'>"
+                + "     <pattern value='call-top-object'>" + "        <call-method-rule "
+                + "                methodname='setMiddle' " + "                targetoffset='0' "
+                + "                paramcount='1' " + "                paramtypes='java.lang.String' />"
+                + "        <call-param-rule paramnumber='0' />" + "     </pattern>"
+                + "     <pattern value='call-parent-object'>" + "        <call-method-rule "
+                + "                methodname='setLeft' " + "                targetoffset='1' "
+                + "                paramcount='1' " + "                paramtypes='java.lang.String' />"
+                + "        <call-param-rule paramnumber='0' />" + "     </pattern>"
+                + "     <pattern value='call-root-object'>" + "        <call-method-rule "
+                + "                methodname='setRight' " + "                targetoffset='-1' "
+                + "                paramcount='1' " + "                paramtypes='java.lang.String' />"
+                + "        <call-param-rule paramnumber='0' />" + "     </pattern>" + "   </pattern>"
+                + "</digester-rules>";
+
+        String xml =
+            "<?xml version='1.0'?>" + "<root>" + "  <call-top-object>DataForTheTopObject</call-top-object>"
+                + "  <call-parent-object>DataForTheParentObject</call-parent-object>"
+                + "  <call-root-object>DataForTheRootObject</call-root-object>" + "</root>";
+
         CallParamTestObject testObjectA = new CallParamTestObject();
         CallParamTestObject testObjectB = new CallParamTestObject();
         CallParamTestObject testObjectC = new CallParamTestObject();
-        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(xmlRules)));
+        Digester digester = DigesterLoader.createDigester( new InputSource( new StringReader( xmlRules ) ) );
         digester.push( testObjectA );
         digester.push( testObjectB );
         digester.push( testObjectC );
-        digester.parse(new InputSource(new StringReader(xml)));
-        
-        assertEquals("Top object invoked", "DataForTheTopObject", testObjectC.getMiddle());
-        assertEquals("Parent object invoked", "DataForTheParentObject", testObjectB.getLeft());
-        assertEquals("Root object invoked", "DataForTheRootObject", testObjectA.getRight());
+        digester.parse( new InputSource( new StringReader( xml ) ) );
+
+        assertEquals( "Top object invoked", "DataForTheTopObject", testObjectC.getMiddle() );
+        assertEquals( "Parent object invoked", "DataForTheParentObject", testObjectB.getLeft() );
+        assertEquals( "Root object invoked", "DataForTheRootObject", testObjectA.getRight() );
 
     }
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderTest.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderTest.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterLoaderTest.java Thu May 12 18:03:26 2011
@@ -16,10 +16,8 @@
  * limitations under the License.
  */
 
-
 package org.apache.commons.digester3.xmlrules;
 
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
@@ -41,302 +39,301 @@ import org.xml.sax.InputSource;
 
 /**
  * Tests loading Digester rules from an XML file.
- *
+ * 
  * @author David H. Martin - Initial Contribution
- * @author Scott Sanders   - Added ASL, removed external dependencies
+ * @author Scott Sanders - Added ASL, removed external dependencies
  */
 
-public class DigesterLoaderTest {
+public class DigesterLoaderTest
+{
 
     /**
-     * Tests the DigesterLoader.createDigester(), with multiple
-     * included rule sources: testrules.xml includes another rules xml
-     * file, and also includes programmatically created rules.
+     * Tests the DigesterLoader.createDigester(), with multiple included rule sources: testrules.xml includes another
+     * rules xml file, and also includes programmatically created rules.
      */
     @Test
-    public void testCreateDigester() throws Exception {
-        URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester3/xmlrules/testrules.xml");
-        URL input = getClass().getClassLoader().getResource("org/apache/commons/digester3/xmlrules/test.xml");
-        assertNotNull("The test could not locate testrules.xml", rules);
-        assertNotNull("The test could not locate test.xml", input);
-        Digester digester = DigesterLoader.createDigester(rules);
-        digester.push(new ArrayList<Object>());
-        Object root = digester.parse(input.openStream());
-        assertEquals("[foo1 baz1 foo2, foo3 foo4]",root.toString());
+    public void testCreateDigester()
+        throws Exception
+    {
+        URL rules = getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/testrules.xml" );
+        URL input = getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/test.xml" );
+        assertNotNull( "The test could not locate testrules.xml", rules );
+        assertNotNull( "The test could not locate test.xml", input );
+        Digester digester = DigesterLoader.createDigester( rules );
+        digester.push( new ArrayList<Object>() );
+        Object root = digester.parse( input.openStream() );
+        assertEquals( "[foo1 baz1 foo2, foo3 foo4]", root.toString() );
     }
 
     /**
-     * Tests the DigesterLoader.load(), with multiple included rule
-     * sources: testrules.xml includes another rules xml file, and
-     * also includes programmatically created rules.
+     * Tests the DigesterLoader.load(), with multiple included rule sources: testrules.xml includes another rules xml
+     * file, and also includes programmatically created rules.
      */
     @Test
-    public void testLoad1() throws Exception {
+    public void testLoad1()
+        throws Exception
+    {
         ClassLoader classLoader = getClass().getClassLoader();
-        URL rules = classLoader.getResource("org/apache/commons/digester3/xmlrules/testrules.xml");
-        URL input = classLoader.getResource("org/apache/commons/digester3/xmlrules/test.xml");
-        assertNotNull("The test could not locate testrules.xml", rules);
-        assertNotNull("The test could not locate test.xml", input);
-        Object root = DigesterLoader.load(rules, classLoader, input, new ArrayList<Object>());
-        if (!(root instanceof ArrayList<?>)) {
-            fail("Unexpected object returned from DigesterLoader. Expected ArrayList; got " + root.getClass().getName());
-        }
-        assertEquals( "[foo1 baz1 foo2, foo3 foo4]",root.toString());
-
-        @SuppressWarnings("unchecked") // root is an ArrayList
-        ArrayList<Object> al = (ArrayList<Object>)root;
-        Object obj = al.get(0);
-        if (! (obj instanceof ObjectTestImpl)) {
-            fail("Unexpected object returned from DigesterLoader. Expected TestObject; got " + obj.getClass().getName());
+        URL rules = classLoader.getResource( "org/apache/commons/digester3/xmlrules/testrules.xml" );
+        URL input = classLoader.getResource( "org/apache/commons/digester3/xmlrules/test.xml" );
+        assertNotNull( "The test could not locate testrules.xml", rules );
+        assertNotNull( "The test could not locate test.xml", input );
+        Object root = DigesterLoader.load( rules, classLoader, input, new ArrayList<Object>() );
+        if ( !( root instanceof ArrayList<?> ) )
+        {
+            fail( "Unexpected object returned from DigesterLoader. Expected ArrayList; got "
+                + root.getClass().getName() );
+        }
+        assertEquals( "[foo1 baz1 foo2, foo3 foo4]", root.toString() );
+
+        @SuppressWarnings( "unchecked" )
+        // root is an ArrayList
+        ArrayList<Object> al = (ArrayList<Object>) root;
+        Object obj = al.get( 0 );
+        if ( !( obj instanceof ObjectTestImpl ) )
+        {
+            fail( "Unexpected object returned from DigesterLoader. Expected TestObject; got "
+                + obj.getClass().getName() );
         }
-        ObjectTestImpl to = (ObjectTestImpl)obj;
-        assertEquals(new Long(555),to.getLongValue());
+        ObjectTestImpl to = (ObjectTestImpl) obj;
+        assertEquals( new Long( 555 ), to.getLongValue() );
         assertEquals( "foo", to.getMapValue( "test1" ) );
         assertEquals( "bar", to.getMapValue( "test2" ) );
     }
 
     /**
-     * The same as testLoad1, exception the input file is passed to
-     * DigesterLoader as an InputStream instead of a URL.
+     * The same as testLoad1, exception the input file is passed to DigesterLoader as an InputStream instead of a URL.
      */
     @Test
-    public void testLoad2() throws Exception {
-        URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester3/xmlrules/testrules.xml");
-        InputStream input = getClass().getClassLoader().getResource("org/apache/commons/digester3/xmlrules/test.xml").openStream();
-        Object root = DigesterLoader.load(rules, getClass().getClassLoader(), input, new ArrayList<Object>());
-        if (!(root instanceof ArrayList<?>)) {
-            fail("Unexpected object returned from DigesterLoader. Expected ArrayList; got " + root.getClass().getName());
+    public void testLoad2()
+        throws Exception
+    {
+        URL rules = getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/testrules.xml" );
+        InputStream input =
+            getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/test.xml" ).openStream();
+        Object root = DigesterLoader.load( rules, getClass().getClassLoader(), input, new ArrayList<Object>() );
+        if ( !( root instanceof ArrayList<?> ) )
+        {
+            fail( "Unexpected object returned from DigesterLoader. Expected ArrayList; got "
+                + root.getClass().getName() );
         }
-        @SuppressWarnings("unchecked") // root is an ArrayList
+        @SuppressWarnings( "unchecked" )
+        // root is an ArrayList
         ArrayList<Object> list = (ArrayList<Object>) root;
-        assertEquals(root.toString(), "[foo1 baz1 foo2, foo3 foo4]");
-        assertEquals("Wrong number of classes created", 2 , list.size());
-        assertEquals("Pushed first", true , ((ObjectTestImpl)list.get(0)).isPushed());
-        assertEquals("Didn't push second", false , ((ObjectTestImpl)list.get(1)).isPushed());
-        assertTrue("Property was set properly", ((ObjectTestImpl)list.get(0)).getProperty().equals("I am a property!") ); 
+        assertEquals( root.toString(), "[foo1 baz1 foo2, foo3 foo4]" );
+        assertEquals( "Wrong number of classes created", 2, list.size() );
+        assertEquals( "Pushed first", true, ( (ObjectTestImpl) list.get( 0 ) ).isPushed() );
+        assertEquals( "Didn't push second", false, ( (ObjectTestImpl) list.get( 1 ) ).isPushed() );
+        assertTrue( "Property was set properly",
+                    ( (ObjectTestImpl) list.get( 0 ) ).getProperty().equals( "I am a property!" ) );
     }
 
-
     /**
      * Validates that circular includes are detected and result in an exception
      */
     @Test
-    public void testCircularInclude1() {
-        URL rules = ClassLoader.getSystemResource("org/apache/commons/digester3/xmlrules/testCircularRules.xml");
-        try {
-            Digester digester = DigesterLoader.createDigester(rules);
-            assertNotNull(digester); // just to prevent compiler warning on unused var
-        } catch (Exception ex) {
+    public void testCircularInclude1()
+    {
+        URL rules = ClassLoader.getSystemResource( "org/apache/commons/digester3/xmlrules/testCircularRules.xml" );
+        try
+        {
+            Digester digester = DigesterLoader.createDigester( rules );
+            assertNotNull( digester ); // just to prevent compiler warning on unused var
+        }
+        catch ( Exception ex )
+        {
             return;
         }
-        fail("Creating a digester with circular rules should have thrown CircularIncludeException.");
+        fail( "Creating a digester with circular rules should have thrown CircularIncludeException." );
     }
 
-
     /**
      */
     @Test
-    public void testSetCustomProperties() throws Exception {
-        URL rules = getClass().getClassLoader().getResource
-            ("org/apache/commons/digester3/xmlrules/testPropertyAliasRules.xml");
-        InputStream input = getClass().getClassLoader().getResource
-            ("org/apache/commons/digester3/Test7.xml").openStream();
-            
-        Object obj = DigesterLoader.load(
-                                        rules, 
-                                        getClass().getClassLoader(), 
-                                        input, 
-                                        new ArrayList<Address>());
-                                        
-        if (!(obj instanceof ArrayList<?>)) {
-            fail(
-                "Unexpected object returned from DigesterLoader. Expected ArrayList; got " 
-                + obj.getClass().getName());
-        }
-        
-        @SuppressWarnings("unchecked") // root is an ArrayList of Address
-        ArrayList<Address> root = (ArrayList<Address>) obj;                
-        
-        assertEquals("Wrong array size", 4, root.size());
-        
+    public void testSetCustomProperties()
+        throws Exception
+    {
+        URL rules =
+            getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/testPropertyAliasRules.xml" );
+        InputStream input =
+            getClass().getClassLoader().getResource( "org/apache/commons/digester3/Test7.xml" ).openStream();
+
+        Object obj = DigesterLoader.load( rules, getClass().getClassLoader(), input, new ArrayList<Address>() );
+
+        if ( !( obj instanceof ArrayList<?> ) )
+        {
+            fail( "Unexpected object returned from DigesterLoader. Expected ArrayList; got " + obj.getClass().getName() );
+        }
+
+        @SuppressWarnings( "unchecked" )
+        // root is an ArrayList of Address
+        ArrayList<Address> root = (ArrayList<Address>) obj;
+
+        assertEquals( "Wrong array size", 4, root.size() );
+
         // note that the array is in popped order (rather than pushed)
-         
-        Address add = root.get(0);
+
+        Address add = root.get( 0 );
         Address addressOne = add;
-        assertEquals("(1) Street attribute", "New Street", addressOne.getStreet());
-        assertEquals("(1) City attribute", "Las Vegas", addressOne.getCity());
-        assertEquals("(1) State attribute", "Nevada", addressOne.getState());
-        
-        add = root.get(1);
+        assertEquals( "(1) Street attribute", "New Street", addressOne.getStreet() );
+        assertEquals( "(1) City attribute", "Las Vegas", addressOne.getCity() );
+        assertEquals( "(1) State attribute", "Nevada", addressOne.getState() );
+
+        add = root.get( 1 );
         Address addressTwo = add;
-        assertEquals("(2) Street attribute", "Old Street", addressTwo.getStreet());
-        assertEquals("(2) City attribute", "Portland", addressTwo.getCity());
-        assertEquals("(2) State attribute", "Oregon", addressTwo.getState());
-        
-        add = root.get(2);
+        assertEquals( "(2) Street attribute", "Old Street", addressTwo.getStreet() );
+        assertEquals( "(2) City attribute", "Portland", addressTwo.getCity() );
+        assertEquals( "(2) State attribute", "Oregon", addressTwo.getState() );
+
+        add = root.get( 2 );
         Address addressThree = add;
-        assertEquals("(3) Street attribute", "4th Street", addressThree.getStreet());
-        assertEquals("(3) City attribute", "Dayton", addressThree.getCity());
-        assertEquals("(3) State attribute", "US" , addressThree.getState());
-       
-        add = root.get(3);
+        assertEquals( "(3) Street attribute", "4th Street", addressThree.getStreet() );
+        assertEquals( "(3) City attribute", "Dayton", addressThree.getCity() );
+        assertEquals( "(3) State attribute", "US", addressThree.getState() );
+
+        add = root.get( 3 );
         Address addressFour = add;
-        assertEquals("(4) Street attribute", "6th Street", addressFour.getStreet());
-        assertEquals("(4) City attribute", "Cleveland", addressFour.getCity());
-        assertEquals("(4) State attribute", "Ohio", addressFour.getState());
-        
+        assertEquals( "(4) Street attribute", "6th Street", addressFour.getStreet() );
+        assertEquals( "(4) City attribute", "Cleveland", addressFour.getCity() );
+        assertEquals( "(4) State attribute", "Ohio", addressFour.getState() );
+
     }
 
     @Test
-   public void testFactoryCreateRule() throws Exception {
-        URL rules = getClass().getClassLoader().getResource
-            ("org/apache/commons/digester3/xmlrules/testfactory.xml");
-            
+    public void testFactoryCreateRule()
+        throws Exception
+    {
+        URL rules = getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/testfactory.xml" );
+
         String xml = "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><foo/></root>";
-        Object obj = DigesterLoader.load(
-                                        rules, 
-                                        getClass().getClassLoader(), 
-                                        new StringReader(xml), 
-                                        new ArrayList<ObjectCreationFactoryTestImpl>());
-                                        
-        if (!(obj instanceof ArrayList<?>)) {
-            fail(
-                "Unexpected object returned from DigesterLoader. Expected ArrayList; got " 
-                + obj.getClass().getName());
-        }
-        
-        @SuppressWarnings("unchecked") // root is an ArrayList of TestObjectCreationFactory
-        ArrayList<ObjectCreationFactoryTestImpl> list = (ArrayList<ObjectCreationFactoryTestImpl>) obj;                
-         
-        assertEquals("List should contain only the factory object", list.size() , 1);
-        ObjectCreationFactoryTestImpl factory = list.get(0);
-        assertEquals("Object create not called(1)", factory.called , true);
-        assertEquals(
-                    "Attribute not passed (1)", 
-                    factory.attributes.getValue("one"), 
-                    "good");
-        assertEquals(
-                    "Attribute not passed (2)", 
-                    factory.attributes.getValue("two"), 
-                    "bad");
-        assertEquals(
-                    "Attribute not passed (3)", 
-                    factory.attributes.getValue("three"), 
-                    "ugly");   
-
-        
-        rules = getClass().getClassLoader().getResource
-            ("org/apache/commons/digester3/xmlrules/testfactoryignore.xml");
-            
+        Object obj =
+            DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader( xml ),
+                                 new ArrayList<ObjectCreationFactoryTestImpl>() );
+
+        if ( !( obj instanceof ArrayList<?> ) )
+        {
+            fail( "Unexpected object returned from DigesterLoader. Expected ArrayList; got " + obj.getClass().getName() );
+        }
+
+        @SuppressWarnings( "unchecked" )
+        // root is an ArrayList of TestObjectCreationFactory
+        ArrayList<ObjectCreationFactoryTestImpl> list = (ArrayList<ObjectCreationFactoryTestImpl>) obj;
+
+        assertEquals( "List should contain only the factory object", list.size(), 1 );
+        ObjectCreationFactoryTestImpl factory = list.get( 0 );
+        assertEquals( "Object create not called(1)", factory.called, true );
+        assertEquals( "Attribute not passed (1)", factory.attributes.getValue( "one" ), "good" );
+        assertEquals( "Attribute not passed (2)", factory.attributes.getValue( "two" ), "bad" );
+        assertEquals( "Attribute not passed (3)", factory.attributes.getValue( "three" ), "ugly" );
+
+        rules = getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/testfactoryignore.xml" );
+
         xml = "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><foo/></root>";
-        try {
-            DigesterLoader.load(
-                                    rules, 
-                                    getClass().getClassLoader(), 
-                                    new StringReader(xml));
-        } catch (Exception e) {
-            fail("This exception should have been ignored: " + e.getClass().getName());
-        }
-        
-        rules = getClass().getClassLoader().getResource
-            ("org/apache/commons/digester3/xmlrules/testfactorynoignore.xml");
-            
+        try
+        {
+            DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader( xml ) );
+        }
+        catch ( Exception e )
+        {
+            fail( "This exception should have been ignored: " + e.getClass().getName() );
+        }
+
+        rules =
+            getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/testfactorynoignore.xml" );
+
         xml = "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><foo/></root>";
-        try {
-            DigesterLoader.load(
-                                    rules, 
-                                    getClass().getClassLoader(), 
-                                    new StringReader(xml));
-            fail("Exception should have been propagated from create method.");
-        } catch (Exception e) {
+        try
+        {
+            DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader( xml ) );
+            fail( "Exception should have been propagated from create method." );
+        }
+        catch ( Exception e )
+        {
             /* What we expected */
-            assertEquals(org.xml.sax.SAXParseException.class, e.getClass());
-        }        
+            assertEquals( org.xml.sax.SAXParseException.class, e.getClass() );
+        }
     }
 
-   @Test
-    public void testCallParamRule() throws Exception {
-    
-        URL rules = getClass().getClassLoader().getResource
-            ("org/apache/commons/digester3/xmlrules/test-call-param-rules.xml");
-        
-        String xml = "<?xml version='1.0' ?>"
-                     + "<root><foo attr='long'><bar>short</bar><foobar><ping>tosh</ping></foobar></foo></root>";
-        
+    @Test
+    public void testCallParamRule()
+        throws Exception
+    {
+
+        URL rules =
+            getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/test-call-param-rules.xml" );
+
+        String xml =
+            "<?xml version='1.0' ?>"
+                + "<root><foo attr='long'><bar>short</bar><foobar><ping>tosh</ping></foobar></foo></root>";
+
         CallParamTestObject testObject = new CallParamTestObject();
-        
-        DigesterLoader.load(
-                                    rules, 
-                                    getClass().getClassLoader(), 
-                                    new StringReader(xml),
-                                    testObject);        
-                                                                        
-        assertEquals("Incorrect left value", "long", testObject.getLeft());
-        assertEquals("Incorrect middle value", "short", testObject.getMiddle());
-        assertEquals("Incorrect right value", "", testObject.getRight());
+
+        DigesterLoader.load( rules, getClass().getClassLoader(), new StringReader( xml ), testObject );
+
+        assertEquals( "Incorrect left value", "long", testObject.getLeft() );
+        assertEquals( "Incorrect middle value", "short", testObject.getMiddle() );
+        assertEquals( "Incorrect right value", "", testObject.getRight() );
     }
 
     @Test
-    public void testInputSourceLoader() throws Exception {
-        String rulesXml = "<?xml version='1.0'?>"
-                + "<digester-rules>"
-                + " <pattern value='root'>"
-                + "   <pattern value='foo'>"
+    public void testInputSourceLoader()
+        throws Exception
+    {
+        String rulesXml =
+            "<?xml version='1.0'?>" + "<digester-rules>" + " <pattern value='root'>" + "   <pattern value='foo'>"
                 + "     <call-method-rule methodname='triple' paramcount='3'"
                 + "            paramtypes='java.lang.String,java.lang.String,java.lang.String'/>"
-                + "     <call-param-rule paramnumber='0' attrname='attr'/>"
-                + "        <pattern value='bar'>"
-                + "            <call-param-rule paramnumber='1' from-stack='false'/>"
-                + "        </pattern>"
-                + "        <pattern value='foobar'>"
-                + "            <object-create-rule classname='java.lang.String'/>"
+                + "     <call-param-rule paramnumber='0' attrname='attr'/>" + "        <pattern value='bar'>"
+                + "            <call-param-rule paramnumber='1' from-stack='false'/>" + "        </pattern>"
+                + "        <pattern value='foobar'>" + "            <object-create-rule classname='java.lang.String'/>"
                 + "            <pattern value='ping'>"
-                + "                <call-param-rule paramnumber='2' from-stack='true'/>"
-                + "            </pattern>"
-                + "         </pattern>"
-                + "   </pattern>"
-                + " </pattern>"
-                + "</digester-rules>";
-                
-        String xml = "<?xml version='1.0' ?>"
-                     + "<root><foo attr='long'><bar>short</bar><foobar><ping>tosh</ping></foobar></foo></root>";
-        
+                + "                <call-param-rule paramnumber='2' from-stack='true'/>" + "            </pattern>"
+                + "         </pattern>" + "   </pattern>" + " </pattern>" + "</digester-rules>";
+
+        String xml =
+            "<?xml version='1.0' ?>"
+                + "<root><foo attr='long'><bar>short</bar><foobar><ping>tosh</ping></foobar></foo></root>";
+
         CallParamTestObject testObject = new CallParamTestObject();
-        
-        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(rulesXml)));
-        digester.push(testObject);
-        digester.parse(new StringReader(xml));        
-                                                                        
-        assertEquals("Incorrect left value", "long", testObject.getLeft());
-        assertEquals("Incorrect middle value", "short", testObject.getMiddle());
-        assertEquals("Incorrect right value", "", testObject.getRight());
+
+        Digester digester = DigesterLoader.createDigester( new InputSource( new StringReader( rulesXml ) ) );
+        digester.push( testObject );
+        digester.parse( new StringReader( xml ) );
+
+        assertEquals( "Incorrect left value", "long", testObject.getLeft() );
+        assertEquals( "Incorrect middle value", "short", testObject.getMiddle() );
+        assertEquals( "Incorrect right value", "", testObject.getRight() );
     }
 
     @Test
-    public void testNodeCreateRule() throws Exception {
-        
-        URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester3/xmlrules/test-node-create-rules.xml");
-        URL input = getClass().getClassLoader().getResource("org/apache/commons/digester3/xmlrules/test-node-create-rules-input.xml");
-        assertNotNull("The test could not locate test-node-create-rules.xml", rules);
-        assertNotNull("The test could not locate test-node-create-rules-input.xml", input);
-        Digester digester = DigesterLoader.createDigester(rules);
-        digester.push(new ArrayList<Node>());
-        List<Node> nlist = digester.parse(input.openStream());
-
-        assertNotNull("root was null", nlist);
-
-        assertTrue("no nodes were captured.", nlist.size() > 0);
-        Node[] nodeArray = nlist.toArray(new Node[0]);
-        assertNotNull("resulting node array from array list was null", nodeArray);
-        
-        // test foo1 structure        
+    public void testNodeCreateRule()
+        throws Exception
+    {
+
+        URL rules =
+            getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/test-node-create-rules.xml" );
+        URL input =
+            getClass().getClassLoader().getResource( "org/apache/commons/digester3/xmlrules/test-node-create-rules-input.xml" );
+        assertNotNull( "The test could not locate test-node-create-rules.xml", rules );
+        assertNotNull( "The test could not locate test-node-create-rules-input.xml", input );
+        Digester digester = DigesterLoader.createDigester( rules );
+        digester.push( new ArrayList<Node>() );
+        List<Node> nlist = digester.parse( input.openStream() );
+
+        assertNotNull( "root was null", nlist );
+
+        assertTrue( "no nodes were captured.", nlist.size() > 0 );
+        Node[] nodeArray = nlist.toArray( new Node[0] );
+        assertNotNull( "resulting node array from array list was null", nodeArray );
+
+        // test foo1 structure
         Node foo1 = nodeArray[0];
-        assertTrue("foo1 didn't have any children", foo1.hasChildNodes());
-        
+        assertTrue( "foo1 didn't have any children", foo1.hasChildNodes() );
+
         Node foo1Bar1 = foo1.getFirstChild();
-        assertTrue("foo1's child was not named bar1", "bar1".equals(foo1Bar1.getNodeName()));
-        assertTrue("foo1/bar1 value was not bar-1-value", "bar1-value".equals(foo1Bar1.getFirstChild().getNodeValue()));       
-    }    
-    
-        
+        assertTrue( "foo1's child was not named bar1", "bar1".equals( foo1Bar1.getNodeName() ) );
+        assertTrue( "foo1/bar1 value was not bar-1-value",
+                    "bar1-value".equals( foo1Bar1.getFirstChild().getNodeValue() ) );
+    }
+
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterPatternStackTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterPatternStackTest.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterPatternStackTest.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterPatternStackTest.java Thu May 12 18:03:26 2011
@@ -18,95 +18,106 @@
 
 package org.apache.commons.digester3.xmlrules;
 
-
 import static org.junit.Assert.*;
 
 import org.apache.commons.digester3.xmlrules.DigesterRuleParser;
 import org.junit.Before;
 import org.junit.Test;
 
-
 /**
- * This test case tests the behavior of
- * DigesterRuleParser.PatternStack, a specialized stack whose
- * toString() method returns a /-separated representation of the
- * stack's elements. The tests ensure that
- * DigesterRuleParser.PatternStack.toString() returns the properly
- * formatted string.
+ * This test case tests the behavior of DigesterRuleParser.PatternStack, a specialized stack whose toString() method
+ * returns a /-separated representation of the stack's elements. The tests ensure that
+ * DigesterRuleParser.PatternStack.toString() returns the properly formatted string.
  */
-public class DigesterPatternStackTest {
+public class DigesterPatternStackTest
+{
 
     private DigesterRuleParser parser;
 
     @Before
-    public void setUp() {
+    public void setUp()
+    {
         parser = new DigesterRuleParser();
     }
 
     @Test
-    public void test1() throws Exception {
-        assertEquals("", parser.patternStack.toString());
+    public void test1()
+        throws Exception
+    {
+        assertEquals( "", parser.patternStack.toString() );
     }
 
     @Test
-    public void test2() throws Exception {
-        parser.patternStack.push("A");
-        assertEquals("A", parser.patternStack.toString());
+    public void test2()
+        throws Exception
+    {
+        parser.patternStack.push( "A" );
+        assertEquals( "A", parser.patternStack.toString() );
         parser.patternStack.pop();
-        assertEquals("", parser.patternStack.toString());
+        assertEquals( "", parser.patternStack.toString() );
     }
 
     @Test
-    public void test3() throws Exception {
-        parser.patternStack.push("A");
-        parser.patternStack.push("B");
-        assertEquals("A/B", parser.patternStack.toString());
+    public void test3()
+        throws Exception
+    {
+        parser.patternStack.push( "A" );
+        parser.patternStack.push( "B" );
+        assertEquals( "A/B", parser.patternStack.toString() );
 
         parser.patternStack.pop();
-        assertEquals("A", parser.patternStack.toString());
+        assertEquals( "A", parser.patternStack.toString() );
     }
 
     @Test
-    public void test4() throws Exception {
-        parser.patternStack.push("");
-        assertEquals("", parser.patternStack.toString());
+    public void test4()
+        throws Exception
+    {
+        parser.patternStack.push( "" );
+        assertEquals( "", parser.patternStack.toString() );
 
-        parser.patternStack.push("");
-        assertEquals("", parser.patternStack.toString());
+        parser.patternStack.push( "" );
+        assertEquals( "", parser.patternStack.toString() );
     }
 
     @Test
-    public void test5() throws Exception {
-        parser.patternStack.push("A");
-        assertEquals("A", parser.patternStack.toString());
+    public void test5()
+        throws Exception
+    {
+        parser.patternStack.push( "A" );
+        assertEquals( "A", parser.patternStack.toString() );
 
-        parser.patternStack.push("");
-        parser.patternStack.push("");
-        assertEquals("A", parser.patternStack.toString());
+        parser.patternStack.push( "" );
+        parser.patternStack.push( "" );
+        assertEquals( "A", parser.patternStack.toString() );
 
     }
 
     @Test
-    public void test6() throws Exception {
-        parser.patternStack.push("A");
-        parser.patternStack.push("B");
+    public void test6()
+        throws Exception
+    {
+        parser.patternStack.push( "A" );
+        parser.patternStack.push( "B" );
         parser.patternStack.clear();
-        assertEquals("", parser.patternStack.toString());
+        assertEquals( "", parser.patternStack.toString() );
     }
 
     @Test
-    public void test7() throws Exception {
-        parser.patternStack.push("///");
-        assertEquals("///", parser.patternStack.toString());
+    public void test7()
+        throws Exception
+    {
+        parser.patternStack.push( "///" );
+        assertEquals( "///", parser.patternStack.toString() );
 
-        parser.patternStack.push("/");
-        assertEquals("/////", parser.patternStack.toString());
+        parser.patternStack.push( "/" );
+        assertEquals( "/////", parser.patternStack.toString() );
 
         parser.patternStack.pop();
-        assertEquals("///", parser.patternStack.toString());
+        assertEquals( "///", parser.patternStack.toString() );
 
         parser.patternStack.pop();
-        assertEquals("", parser.patternStack.toString());
+        assertEquals( "", parser.patternStack.toString() );
     }
 
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterRulesSourceTestImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterRulesSourceTestImpl.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterRulesSourceTestImpl.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/DigesterRulesSourceTestImpl.java Thu May 12 18:03:26 2011
@@ -16,31 +16,32 @@
  * limitations under the License.
  */
 
-
 package org.apache.commons.digester3.xmlrules;
 
-
 import org.apache.commons.digester3.Digester;
 import org.apache.commons.digester3.xmlrules.DigesterRulesSource;
 
-
 /**
- * A test class, for validating FromXmlRuleSet's ability to 'include'
- * programmatically-created rules from within an XML rules file.
- *
+ * A test class, for validating FromXmlRuleSet's ability to 'include' programmatically-created rules from within an XML
+ * rules file.
+ * 
  * @author David H. Martin - Initial Contribution
- * @author Scott Sanders   - Added ASL, removed external dependencies
+ * @author Scott Sanders - Added ASL, removed external dependencies
  */
-public class DigesterRulesSourceTestImpl implements DigesterRulesSource {
+public class DigesterRulesSourceTestImpl
+    implements DigesterRulesSource
+{
 
     /**
      * Creates and adds Digester Rules to a given Rules object
+     * 
      * @param digester the Digester to add the new Rule objects to
      */
-    public void getRules(Digester digester) {
-        digester.addObjectCreate("/baz", ObjectTestImpl.class.getName());
-        digester.addSetNext("/baz", "add", "java.lang.Object");
-        digester.addSetProperties("/baz");
+    public void getRules( Digester digester )
+    {
+        digester.addObjectCreate( "/baz", ObjectTestImpl.class.getName() );
+        digester.addSetNext( "/baz", "add", "java.lang.Object" );
+        digester.addSetProperties( "/baz" );
     }
 
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/FromXmlRuleSetTest.java Thu May 12 18:03:26 2011
@@ -16,10 +16,8 @@
  * limitations under the License.
  */
 
-
 package org.apache.commons.digester3.xmlrules;
 
-
 import static org.junit.Assert.*;
 
 import java.io.StringReader;
@@ -33,59 +31,49 @@ import org.xml.sax.InputSource;
  * Tests loading Digester rules from an XML file.
  */
 
-public class FromXmlRuleSetTest {
+public class FromXmlRuleSetTest
+{
 
-    /** 
-     * Test the FromXmlRules.addRuleInstances(digester, path) method, ie
-     * test loading rules at a base position other than the root.
+    /**
+     * Test the FromXmlRules.addRuleInstances(digester, path) method, ie test loading rules at a base position other
+     * than the root.
      */
     @Test
-    public void testBasePath() throws Exception {
-        String xmlRules = 
-            "<?xml version='1.0'?>" +
-            "<digester-rules>" + 
-            "   <pattern value='foo'>" +
-            "      <call-method-rule " +
-            "              methodname='setProperty' " +
-            "              paramcount='0' />" +
-            "   </pattern>" +
-            "</digester-rules>";
-        
-        String xml = 
-            "<?xml version='1.0'?>" + 
-            "<root>" +
-            "  <foo>success</foo>" +
-            "</root>";
-            
+    public void testBasePath()
+        throws Exception
+    {
+        String xmlRules =
+            "<?xml version='1.0'?>" + "<digester-rules>" + "   <pattern value='foo'>" + "      <call-method-rule "
+                + "              methodname='setProperty' " + "              paramcount='0' />" + "   </pattern>"
+                + "</digester-rules>";
+
+        String xml = "<?xml version='1.0'?>" + "<root>" + "  <foo>success</foo>" + "</root>";
+
         // First try with no base path. The rule shouldn't match, because
         // foo is not the root element.
         {
-        ObjectTestImpl testObject = new ObjectTestImpl();
-        FromXmlRuleSet ruleset = 
-            new FromXmlRuleSet(
-                new InputSource(new StringReader(xmlRules)));
-        Digester digester = new Digester();
-        ruleset.addRuleInstances(digester);
-        
-        digester.push(testObject);    
-        digester.parse(new InputSource(new StringReader(xml)));
-        
-        assertEquals("", testObject.getProperty());
+            ObjectTestImpl testObject = new ObjectTestImpl();
+            FromXmlRuleSet ruleset = new FromXmlRuleSet( new InputSource( new StringReader( xmlRules ) ) );
+            Digester digester = new Digester();
+            ruleset.addRuleInstances( digester );
+
+            digester.push( testObject );
+            digester.parse( new InputSource( new StringReader( xml ) ) );
+
+            assertEquals( "", testObject.getProperty() );
         }
-        
+
         // Now try with a base path. The rule should now match.
         {
-        ObjectTestImpl testObject = new ObjectTestImpl();
-        FromXmlRuleSet ruleset = 
-            new FromXmlRuleSet(
-                new InputSource(new StringReader(xmlRules)));
-        Digester digester = new Digester();
-        ruleset.addRuleInstances(digester, "root");
-
-        digester.push(testObject);    
-        digester.parse(new InputSource(new StringReader(xml)));
-        
-        assertEquals("success", testObject.getProperty());
+            ObjectTestImpl testObject = new ObjectTestImpl();
+            FromXmlRuleSet ruleset = new FromXmlRuleSet( new InputSource( new StringReader( xmlRules ) ) );
+            Digester digester = new Digester();
+            ruleset.addRuleInstances( digester, "root" );
+
+            digester.push( testObject );
+            digester.parse( new InputSource( new StringReader( xml ) ) );
+
+            assertEquals( "success", testObject.getProperty() );
         }
     }
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/IncludeTest.java Thu May 12 18:03:26 2011
@@ -33,37 +33,42 @@ import org.xml.sax.InputSource;
 /**
  * Test for the include class functionality
  */
-public class IncludeTest {
+public class IncludeTest
+{
 
-    public static class TestDigesterRuleSource implements DigesterRulesSource {
-        public void getRules(Digester digester) {
-            digester.addRule("bar", 
-                new Rule() {
-                    @Override
-                    public void body(String namespace, String name, String text) {
-                        ((ArrayList<String>) this.getDigester().peek()).add(text);
-                    }
-                });
+    public static class TestDigesterRuleSource
+        implements DigesterRulesSource
+    {
+        public void getRules( Digester digester )
+        {
+            digester.addRule( "bar", new Rule()
+            {
+                @Override
+                public void body( String namespace, String name, String text )
+                {
+                    ( (ArrayList<String>) this.getDigester().peek() ).add( text );
+                }
+            } );
         }
     }
 
     @Test
-    public void testBasicInclude() throws Exception {
-        String rulesXml = "<?xml version='1.0'?>"
-                + "<digester-rules>"
-                + " <pattern value='root/foo'>"
+    public void testBasicInclude()
+        throws Exception
+    {
+        String rulesXml =
+            "<?xml version='1.0'?>" + "<digester-rules>" + " <pattern value='root/foo'>"
                 + "   <include class='org.apache.commons.digester3.xmlrules.IncludeTest$TestDigesterRuleSource'/>"
-                + " </pattern>"
-                + "</digester-rules>";
-                
+                + " </pattern>" + "</digester-rules>";
+
         String xml = "<?xml version='1.0' ?><root><foo><bar>short</bar></foo></root>";
-        
+
         ArrayList<String> list = new ArrayList<String>();
-        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(rulesXml)));
-        digester.push(list);
-        digester.parse(new StringReader(xml));        
-                                                                        
-        assertEquals("Number of entries", 1, list.size());
-        assertEquals("Entry value", "short", list.get(0));
+        Digester digester = DigesterLoader.createDigester( new InputSource( new StringReader( rulesXml ) ) );
+        digester.push( list );
+        digester.parse( new StringReader( xml ) );
+
+        assertEquals( "Number of entries", 1, list.size() );
+        assertEquals( "Entry value", "short", list.get( 0 ) );
     }
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ObjectTestImpl.java Thu May 12 18:03:26 2011
@@ -18,82 +18,97 @@
 
 package org.apache.commons.digester3.xmlrules;
 
-
 import java.util.ArrayList;
 import java.util.HashMap;
 
-
 /**
  * Test harness object for holding results of digestion.
- *
+ * 
  * @author David H. Martin - Initial Contribution
- * @author Scott Sanders   - Added ASL, removed external dependencies
+ * @author Scott Sanders - Added ASL, removed external dependencies
  * @author Tim O'Brien - Added bean property to test bean property setter rule
  */
-public class ObjectTestImpl {
+public class ObjectTestImpl
+{
 
     private ArrayList<Object> children = new ArrayList<Object>();
+
     private String value = "";
-    private Long longValue = new Long(-1L);
+
+    private Long longValue = new Long( -1L );
 
     private String property = "";
 
     private HashMap<String, String> mapValue = new HashMap<String, String>();
 
     private boolean pushed = false;
-    
-    public ObjectTestImpl() {
+
+    public ObjectTestImpl()
+    {
     }
 
     @Override
-    public String toString() {
+    public String toString()
+    {
         String str = value;
-        for (Object o : children) {
+        for ( Object o : children )
+        {
             str += " " + o;
         }
         return str;
     }
 
-    public void add(Object o) {
-        children.add(o);
+    public void add( Object o )
+    {
+        children.add( o );
     }
 
-    public void setValue(String val) {
+    public void setValue( String val )
+    {
         value = val;
     }
 
-    public void setLongValue(Long val) {
+    public void setLongValue( Long val )
+    {
         longValue = val;
     }
 
-    public Long getLongValue() {
+    public Long getLongValue()
+    {
         return longValue;
     }
 
-    public void setStringValue(String val) {
+    public void setStringValue( String val )
+    {
     }
 
-    public boolean isPushed() {
+    public boolean isPushed()
+    {
         return pushed;
     }
-    
-    public void push() {
+
+    public void push()
+    {
         pushed = true;
     }
 
-    public void setMapValue( String name, String value ) {
+    public void setMapValue( String name, String value )
+    {
         this.mapValue.put( name, value );
     }
 
-    public String getMapValue( String name ) {
+    public String getMapValue( String name )
+    {
         return this.mapValue.get( name );
     }
 
-    public String getProperty() {
+    public String getProperty()
+    {
         return property;
     }
 
-    public void setProperty(String pProperty) {
+    public void setProperty( String pProperty )
+    {
         property = pProperty;
     }
 }

Modified: commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ThrowExceptionCreationFactory.java
URL: http://svn.apache.org/viewvc/commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ThrowExceptionCreationFactory.java?rev=1102402&r1=1102401&r2=1102402&view=diff
==============================================================================
--- commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ThrowExceptionCreationFactory.java (original)
+++ commons/sandbox/digester3/trunk/src/test/java/org/apache/commons/digester3/xmlrules/ThrowExceptionCreationFactory.java Thu May 12 18:03:26 2011
@@ -23,17 +23,18 @@ import org.xml.sax.Attributes;
 
 /**
  * Object creation factory used for testing exception propagation.
- *
+ * 
  * @author Robert Burrell Donkin
  */
 
-public class ThrowExceptionCreationFactory extends AbstractObjectCreationFactory {
-    
+public class ThrowExceptionCreationFactory
+    extends AbstractObjectCreationFactory
+{
+
     @Override
-    public Object createObject(Attributes attributes) throws Exception {
+    public Object createObject( Attributes attributes )
+        throws Exception
+    {
         throw new RuntimeException();
     }
 }
-
-
-



Mime
View raw message