You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by cr...@apache.org on 2001/11/14 20:54:06 UTC

cvs commit: jakarta-commons/digester/src/test/org/apache/commons/digester BeanPropertySetterRuleTestCase.java SimpleTestBean.java TestRule.java

craigmcc    01/11/14 11:54:05

  Modified:    digester build.xml
               digester/src/java/org/apache/commons/digester Digester.java
               digester/src/test/org/apache/commons/digester TestRule.java
  Added:       digester/src/java/org/apache/commons/digester
                        BeanPropertySetterRule.java
               digester/src/test/org/apache/commons/digester
                        BeanPropertySetterRuleTestCase.java
                        SimpleTestBean.java
  Log:
  Add the BeanPropertySetterRule and associated tests.  NOTE:  The test case
  curently fails (target "test.bpsr") -- could someone take a look and see
  what I screwed up in incorporating this stuff?
  
  Submitted by:	Robert Burrell Donkin
  
  Revision  Changes    Path
  1.15      +12 -1     jakarta-commons/digester/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/build.xml,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- build.xml	2001/10/16 23:58:01	1.14
  +++ build.xml	2001/11/14 19:54:05	1.15
  @@ -3,7 +3,7 @@
   
   <!--
           "Digester" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.14 2001/10/16 23:58:01 craigmcc Exp $
  +        $Id: build.xml,v 1.15 2001/11/14 19:54:05 craigmcc Exp $
   -->
   
   
  @@ -237,6 +237,17 @@
                                  test.rule
                                 "
      description="Run all unit test cases">
  +  </target>
  +
  +
  +  <target name="test.bpsr" depends="compile.tests"
  +   description="Run tests for BeanPropertySetterRule ...">
  +    <echo message="Running BeanPropertySetterRule tests ..."/>
  +    <java classname="${test.runner}" fork="yes"
  +        failonerror="${test.failonerror}">
  +      <arg value="org.apache.commons.digester.BeanPropertySetterRuleTestCase"/>
  +      <classpath refid="test.classpath"/>
  +    </java>
     </target>
   
   
  
  
  
  1.25      +31 -4     jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java
  
  Index: Digester.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Digester.java	2001/11/14 18:42:16	1.24
  +++ Digester.java	2001/11/14 19:54:05	1.25
  @@ -1,7 +1,7 @@
   /*
  - * $Header: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v 1.24 2001/11/14 18:42:16 craigmcc Exp $
  - * $Revision: 1.24 $
  - * $Date: 2001/11/14 18:42:16 $
  + * $Header: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/Digester.java,v 1.25 2001/11/14 19:54:05 craigmcc Exp $
  + * $Revision: 1.25 $
  + * $Date: 2001/11/14 19:54:05 $
    *
    * ====================================================================
    *
  @@ -108,7 +108,7 @@
    *
    * @author Craig McClanahan
    * @author Scott Sanders
  - * @version $Revision: 1.24 $ $Date: 2001/11/14 18:42:16 $
  + * @version $Revision: 1.25 $ $Date: 2001/11/14 19:54:05 $
    */
   
   public class Digester extends DefaultHandler {
  @@ -1294,6 +1294,33 @@
   
       }
   
  +
  +    /**
  +     * Add a "bean property setter" rule for the specified parameters.
  +     *
  +     * @param pattern Element matching pattern
  +     */
  +    public void addBeanPropertySetter(String pattern) {
  +
  +        addRule(pattern,
  +                new BeanPropertySetterRule(this));
  +
  +    }
  +
  +
  +    /**
  +     * Add a "bean property setter" rule for the specified parameters.
  +     *
  +     * @param pattern Element matching pattern
  +     * @param propertyName Name of property to set
  +     */
  +    public void addBeanPropertySetter(String pattern,
  +                                      String propertyName) {
  +
  +        addRule(pattern,
  +                new BeanPropertySetterRule(this, propertyName));
  +
  +    }
   
   
       /**
  
  
  
  1.1                  jakarta-commons/digester/src/java/org/apache/commons/digester/BeanPropertySetterRule.java
  
  Index: BeanPropertySetterRule.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/digester/src/java/org/apache/commons/digester/BeanPropertySetterRule.java,v 1.1 2001/11/14 19:54:05 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/11/14 19:54:05 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.commons.digester;
  
  import java.util.HashMap;
  import org.xml.sax.Attributes;
  import org.apache.commons.beanutils.BeanUtils;
  
  
  /**
   * <p> Rule implements sets a body property on the top object 
   * to the body text.</p>
   *
   * <p> The property set:</p>
   * <ul><li>can be specified when the rule is created</li>
   * <li>or can match the current element when the rule is called.</li></ul>
   *
   * <p> Using the second method and the {@link ExtendedBaseRules} child match
   * pattern, all the child elements can be automatically mapped to properties
   * on the parent object.</p>
   *
   * @author Robert Burrell Donkin
   * @version $Revision: 1.1 $ $Date: 2001/11/14 19:54:05 $
   */
  
  public class BeanPropertySetterRule extends Rule {
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /** 
       * <p>Construct rule that sets the given property from the body text.</p>
       * 
       * @param digester associated <code>Digester</code>
       * @param propertyName name of property to set 
       */
      public BeanPropertySetterRule(Digester digester, String propertyName) {
              
              super(digester);
              this.propertyName=propertyName;
  
      }
  
      /** 
       * <p>Construct rule that automatically sets a property from the body text.
       * 
       * <p> This construct creates a rule that sets the property
       * on the top object named the same as the current element.
       *
       * @param digester associated <code>Digester</code>
       */
      public BeanPropertySetterRule(Digester digester) {
  
              this(digester, null);
  
      }
   
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * Set this property on the top object.
       */
      protected String propertyName = null;
  
  
      /**
       * The body text used to set the property.
       */
      protected String bodyText = null;
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Process the body text of this element.
       *
       * @param bodyText The body text of this element
       */
      public void body(String bodyText) throws Exception {
  
              // log some debugging information
              if (digester.debug>9)
                  digester.log("[BeanPropertySetterRule] Called with text " +
                               bodyText);
  
  	    this.bodyText = bodyText.trim();
  
      }
  
  
      /**
       * Process the end of this element.
       */
      public void end() throws Exception {
          
          String property=propertyName;    
  
          if (property==null) {
              // If we don't have a specific property name,
              // use the element name.
              String match = digester.match;
              int slash = match.lastIndexOf('/');
              if (slash >= 0)
                  match = match.substring(slash+1);
                  
              property=match;
              
  	}
  
          // log some debugging information
          if (digester.debug>1)
              digester.log("[BeanPropertySetterRule] setting property " +
                           property + " with text " + bodyText);
  
          // going to use beanutils so need to specify property using map
          HashMap map=new HashMap();
          map.put(property,bodyText);
          
          // examine top object
          Object top=digester.peek();
          if (top==null) {
              // don't try to set property if null
              // just log and return
              if (digester.debug>3)
                  digester.log("[BeanPropertySetterRule] Top object is null.");
              return;
          }
          
          // populate property on top object
          BeanUtils.populate(top,map);
          
      }
  
  
      /**
       * Clean up after parsing is complete.
       */
      public void finish() throws Exception {
  
  	bodyText = null;
  
      }
  
  
      /**
       * Render a printable version of this Rule.
       */
      public String toString() {
          
          StringBuffer sb = new StringBuffer("BeanPropertySetterRule[");
          sb.append("propertyName=");
          sb.append(propertyName);
          sb.append("]");
          return (sb.toString());
  
      }
  
  }
  
  
  
  1.3       +82 -6     jakarta-commons/digester/src/test/org/apache/commons/digester/TestRule.java
  
  Index: TestRule.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/digester/src/test/org/apache/commons/digester/TestRule.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestRule.java	2001/09/05 03:33:26	1.2
  +++ TestRule.java	2001/11/14 19:54:05	1.3
  @@ -59,22 +59,34 @@
   package org.apache.commons.digester;
   
   
  +import java.util.List;
  +import org.xml.sax.Attributes;
  +
  +
   /**
    * <p>This rule implementation is intended to help test digester.
    * The idea is that you can test which rule matches by looking
    * at the identifier.</p>
    *
    * @author Robert Burrell Donkin
  - * @revision $Revision: 1.2 $ $Date: 2001/09/05 03:33:26 $
  + * @revision $Revision: 1.3 $ $Date: 2001/11/14 19:54:05 $
    */
   
   public class TestRule extends Rule {
   
       // ----------------------------------------------------- Instance Variables
       
  +
       /** String identifing this particular <code>TestRule</code> */
       private String identifier;
   
  +    /** Used when testing body text */
  +    private String bodyText;
  +
  +    /** Used when testing call orders */
  +    private List order;
  +
  +
       // ----------------------------------------------------------- Constructors
   
   
  @@ -98,7 +110,8 @@
        * @param identifier Used to tell which TestRule is which
        * @param namespaceURI Set rule namespace
        */
  -    public TestRule(Digester digester, String identifier,
  +    public TestRule(Digester digester,
  +                    String identifier,
                       String namespaceURI) {
   
           super(digester);
  @@ -108,21 +121,84 @@
       }
       
   
  +    // ------------------------------------------------ Rule Implementation
  +
  +
  +    /**
  +     * 'Begin' call.
  +     */
  +    public void begin(Attributes attributes) {
  +        appendCall();
  +    }
  +
  +
  +    /**
  +     * 'Body' call.
  +     */
  +    public void body(String text) {
  +        this.bodyText = bodyText;
  +        appendCall();
  +    }
  +
  +
  +    /**
  +     * 'End' call.
  +     */
  +    public void end() {
  +        appendCall();
  +    }
  +
  +
       // ------------------------------------------------ Methods
       
  +
       /**
  +     * If a list has been set, append this to the list.
  +     */
  +    protected void appendCall() {
  +        if (order != null)
  +            order.add(this);
  +    }
  +
  +
  +    /**
  +     * Get the body text that was set.
  +     */
  +    public String getBodyText() {
  +        return bodyText;
  +    }
  +
  +
  +    /**
        * Get the identifier associated with this test.
        */
  -    public String getIdentifier()
  -    {
  +    public String getIdentifier() {
           return identifier;
       }
   
  +
  +    /**
  +     * Get call order list.
  +     */
  +    public List getOrder() {
  +        return order;
  +    }
  +
  +
  +    /**
  +     * Set call order list
  +     */
  +    public void setOrder(List order) {
  +        this.order = order;
  +    }
  +
  +
       /** 
        * Return the identifier.
        */
  -    public String toString()
  -    {
  +    public String toString() {
           return identifier;
       }
  +
  +
   }
  
  
  
  1.1                  jakarta-commons/digester/src/test/org/apache/commons/digester/BeanPropertySetterRuleTestCase.java
  
  Index: BeanPropertySetterRuleTestCase.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.commons.digester;
  
  
  import java.util.ArrayList;
  import java.util.List;
  import java.io.StringBufferInputStream;
  import java.io.InputStream;
  import java.io.IOException;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  
  /** 
   * <p> Test case for <code>BeanPropertySetterRule</code>.
   * This contains tests for the main applications of the rule
   * and two more general tests of digester functionality used by this rule.
   */
  public class BeanPropertySetterRuleTestCase extends TestCase {
  
  
      // ----------------------------------------------------- Instance Variables
  
      /**
       * Simple test xml document used in the tests.
       */
      protected final static String TEST_XML =
          "<?xml version='1.0'?><root>ROOT BODY<alpha>ALPHA BODY</alpha><beta>BETA BODY</beta><gamma>GAMMA BODY</gamma></root>";
  
  
      /**
       * The digester instance we will be processing.
       */
      protected Digester digester = null;
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new instance of this test case.
       *
       * @param name Name of the test case
       */
      public BeanPropertySetterRuleTestCase(String name) {
  
          super(name);
  
      }
  
  
      // --------------------------------------------------- Overall Test Methods
  
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp() {
  
          digester = new Digester();
  
      }
  
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
  
          return (new TestSuite(BeanPropertySetterRuleTestCase.class));
  
      }
  
  
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown() {
  
          digester = null;
  
      }
  
  
  
      // ------------------------------------------------ Individual Test Methods
  
  
      /**
       * This is a general digester test but it fits into here pretty well.
       * This tests that the rule calling order is properly enforced.
       */
      public void testDigesterRuleCallOrder() {
          
          List callOrder = new ArrayList();
      
          // use the standard rules
          digester.setRules(new RulesBase());
  
          // add first test rule 
          TestRule firstRule=new TestRule(digester,"first");
          firstRule.setOrder(callOrder);
          digester.addRule("root/alpha",firstRule);
  
          // add second test rule 
          TestRule secondRule=new TestRule(digester,"second");
          secondRule.setOrder(callOrder);
          digester.addRule("root/alpha",secondRule);
  
          // add third test rule 
          TestRule thirdRule=new TestRule(digester,"third");
          thirdRule.setOrder(callOrder);
          digester.addRule("root/alpha",thirdRule);
  
          
          try {
              digester.parse(xmlTestStream());
              
          } catch (Throwable t) {
              fail("Exception prevented test execution: " + t);
          }        
          
          // we should have nine entries in our list of calls
          
           assertEquals(	
                      "Nine calls should have been made.",
                      9,
                      callOrder.size());       
          
          // begin should be called in the order added
          assertEquals(	
                      "First rule begin not called first.",
                      "first",
                      ((TestRule)callOrder.get(0)).getIdentifier());
                      
          assertEquals(	
                      "Second rule begin not called second.",
                      "second",
                      ((TestRule)callOrder.get(1)).getIdentifier());
                      
          assertEquals(	
                      "Third rule begin not called third.",
                      "third",
                      ((TestRule)callOrder.get(2)).getIdentifier());
  
           // body text should be called in the order added
          assertEquals(	
                      "First rule body text not called first.",
                      "first",
                      ((TestRule)callOrder.get(3)).getIdentifier());
                      
          assertEquals(	
                      "Second rule body text not called second.",
                      "second",
                      ((TestRule)callOrder.get(4)).getIdentifier());
                      
          assertEquals(	
                      "Third rule body text not called third.",
                      "third",
                      ((TestRule)callOrder.get(5)).getIdentifier());
  
           // end should be called in reverse order
          assertEquals(	
                      "Third rule end not called first.",
                      "third",
                      ((TestRule)callOrder.get(6)).getIdentifier());
                      
          assertEquals(	
                      "Second rule end not called second.",
                      "second",
                      ((TestRule)callOrder.get(7)).getIdentifier());
                      
          assertEquals(	
                      "First rule end not called third.",
                      "first",
                      ((TestRule)callOrder.get(8)).getIdentifier());
  
         
      }
      
  
      /**
       * This is a general digester test but it fits into here pretty well.
       * This tests that the body text stack is functioning correctly.
       */
      public void testDigesterBodyTextStack() {
  
          // use the standard rules
          digester.setRules(new RulesBase());
  
          // add test rule to catch body text
          TestRule rootRule=new TestRule(digester,"root");
          digester.addRule("root",rootRule);
  
          // add test rule to catch body text
          TestRule alphaRule=new TestRule(digester,"root/alpha");
          digester.addRule("root/alpha",alphaRule);
  
          // add test rule to catch body text
          TestRule betaRule=new TestRule(digester,"root/beta");
          digester.addRule("root/beta",betaRule);
  
          // add test rule to catch body text
          TestRule gammaRule=new TestRule(digester,"root/gamma");
          digester.addRule("root/gamma",gammaRule);
          
          try {
              digester.parse(xmlTestStream());
              
          } catch (Throwable t) {
              fail("Exception prevented test execution: " + t);
          }        
          
          assertEquals(	
                      "Root body text not set correct.",
                      "ROOT BODY",
                      rootRule.getBodyText());
          
          assertEquals(	
                      "Alpha body text not set correct.",
                      "ALPHA BODY",
                      alphaRule.getBodyText());
  
          assertEquals(	
                      "Beta body text not set correct.",
                      "BETA BODY",
                      betaRule.getBodyText());
                      
          assertEquals(	
                      "Gamma body text not set correct.",
                      "GAMMA BODY",
                      gammaRule.getBodyText());
          
      }
      
  
      /**
       * Test that you can successfully set a given property
       */
      public void testSetGivenProperty() {
      
          // use the standard rules
          digester.setRules(new RulesBase());
          
          // going to be setting properties on a SimpleTestBean 
          digester.addObjectCreate("root","org.apache.commons.digester.SimpleTestBean");
          
          // we'll set property alpha with the body text of root
          digester.addRule("root",new BeanPropertySetterRule(digester,"alpha"));
          
          // we'll set property beta with the body text of child element alpha
          digester.addRule("root/alpha",new BeanPropertySetterRule(digester,"beta"));
          
          // we'll leave property gamma alone
  
          
          SimpleTestBean bean = null;
          try {
              bean = (SimpleTestBean) digester.parse(xmlTestStream());
              
          } catch (Throwable t) {
              fail("Exception prevented test execution: " + t);
          }
          
          
          
          // check properties are set correctly
          assertEquals(	
                      "Property alpha not set correctly",
                      "ROOT BODY",
                      bean.getAlpha());
          
          assertEquals(	
                      "Property beta not set correctly",
                      "ALPHA BODY",
                      bean.getBeta());
          
          assertTrue(	
                      "Property gamma not set correctly",
                      bean.getGamma()==null);        
          
      }
      
      /**
       * Test that you can successfully automatically set properties.
       */ 
      public void testAutomaticallySetProperties() {
          
          // need the extended rules
          digester.setRules(new ExtendedBaseRules());
          
          // going to be setting properties on a SimpleTestBean 
          digester.addObjectCreate("root","org.apache.commons.digester.SimpleTestBean");
          
          // match all children of root with this rule
          digester.addRule("root/?",new BeanPropertySetterRule(digester));
          
          
          SimpleTestBean bean = null;
          try {
              bean = (SimpleTestBean) digester.parse(xmlTestStream());
              
          } catch (Throwable t) {
              fail("Exception prevented test execution: " + t);
          }
  
  
          // check properties are set correctly
          assertEquals(	
                      "Property alpha not set correctly",
                      "ALPHA BODY",
                      bean.getAlpha());
          
          assertEquals(	
                      "Property beta not set correctly",
                      "BETA BODY",
                      bean.getBeta());
          
          assertEquals(	
                      "Property gamma not set correctly",
                      "GAMMA BODY",
                      bean.getGamma());       
                      
          
  
      }
  
      /**
       * Get input stream from {@link #TEST_XML}.
       */
      private InputStream xmlTestStream() throws IOException
      {
          return new StringBufferInputStream(TEST_XML);
      }
      
  }
  
  
  
  
  
  1.1                  jakarta-commons/digester/src/test/org/apache/commons/digester/SimpleTestBean.java
  
  Index: SimpleTestBean.java
  ===================================================================
  /*
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */
  
  
  package org.apache.commons.digester;
  
  
  /**
   * <p> As it's name suggests just a simple bean used for testing.
   */
  public class SimpleTestBean {
  
      private String alpha;
      
      private String beta;
      
      private String gamma;
  
      public String getAlpha()
      {
          return alpha;
      }
  
      public void setAlpha(String alpha)
      {
          this.alpha = alpha;
      }
  
      public String getBeta()
      {
          return beta;
      }
      
      public void setBeta(String beta)
      {
          this.beta=beta;
      }
      
      public String getGamma()
      {
          return gamma;
      }
      
      public void setGamma(String gamma)
      {
          this.gamma=gamma;
      }
      
      public String toString()
      {
          StringBuffer sb = new StringBuffer("[SimpleTestBean]");
          sb.append(" alpha=");
          sb.append(alpha);
          sb.append(" beta=");
          sb.append(beta);
          sb.append(" gamma=");
          sb.append(gamma);
          
          return sb.toString();
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>