commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/expression AdderBean.java TestUpdaters.java
Date Fri, 11 Apr 2003 21:29:46 GMT
rdonkin     2003/04/11 14:29:46

  Modified:    betwixt/src/test/org/apache/commons/betwixt AddressBean.java
                        TestBeanReader.java
  Added:       betwixt/src/test/org/apache/commons/betwixt MapBean.java
               betwixt/src/test/org/apache/commons/betwixt/expression
                        AdderBean.java TestUpdaters.java
  Log:
  Test cases for betwixt map reading and writing.
  
  Revision  Changes    Path
  1.3       +7 -0      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/AddressBean.java
  
  Index: AddressBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/AddressBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AddressBean.java	19 Nov 2002 20:13:18 -0000	1.2
  +++ AddressBean.java	11 Apr 2003 21:29:46 -0000	1.3
  @@ -78,6 +78,13 @@
       
       public AddressBean() {
       }
  +    
  +    public AddressBean(String street, String city, String country, String code) {
  +        setStreet(street);
  +        setCity(city);
  +        setCode(code);
  +        setCountry(country);
  +    }
   
       public String getStreet() {
           return street;
  
  
  
  1.11      +84 -0     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanReader.java
  
  Index: TestBeanReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanReader.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestBeanReader.java	24 Feb 2003 18:21:29 -0000	1.10
  +++ TestBeanReader.java	11 Apr 2003 21:29:46 -0000	1.11
  @@ -80,10 +80,15 @@
   import org.apache.commons.beanutils.ConvertUtils;
   import org.apache.commons.betwixt.io.BeanReader;
   import org.apache.commons.betwixt.io.BeanWriter;
  +import org.apache.commons.betwixt.io.BeanRuleSet;
  +import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
  +import org.apache.commons.betwixt.expression.MapEntryAdder;
   
   import org.apache.commons.digester.Rule;
   import org.apache.commons.digester.ExtendedBaseRules;
   
  +import org.apache.commons.logging.impl.SimpleLog;
  +
   import org.xml.sax.Attributes;
   
   
  @@ -355,6 +360,85 @@
           // test that the top objects are correct
           assertEquals("Rule one digester top object", listOfNames , ruleOne.getTop());
           assertEquals("Rule two digester top object", martinBean , ruleTwo.getTop());
  +    }
  +    
  +    public void testReadMap() throws Exception {
  +        // we might as well start by writing out 
  +        MapBean bean = new MapBean("drinkers");
  +        bean.addAddress(
  +                "Russell McManus", 
  +                new AddressBean("6, Westgate","Shipley", "United Kingdom", "BD17 5EJ"));
  +        bean.addAddress(
  +                "Alex Compbell", 
  +                new AddressBean("5, Kirkgate","Shipley", "United Kingdom", "BD18 3QW"));
  +        bean.addAddress(
  +                "Sid Gardner", 
  +                new AddressBean("Old House At Home, Otley Road","Shipley", "United Kingdom",
"BD18 2BJ"));
  +                
  +        StringWriter out = new StringWriter();
  +        out.write("<?xml version='1.0'?>");
  +        BeanWriter writer = new BeanWriter(out);
  +        writer.setWriteIDs(false);
  +        writer.write("address-book", bean);
  +        
  +        System.out.println(out.toString());
  +        
  +        String xml = "<?xml version='1.0'?><address-book><title>drinkers</title>"
  +            + "<addresses><entry><key>Sid Gardner</key><value><country>United
Kingdom</country>"
  +            + "<code>BD18 2BJ</code><city>Shipley</city><street>Old
House At Home, Otley Road</street>"
  +            + "</value></entry><entry><key>Alex Compbell</key><value><country>United
Kingdom</country>"
  +            + "<code>BD18 3QW</code><city>Shipley</city><street>5,
Kirkgate</street></value></entry>"
  +            + "<entry><key>Russell McManus</key><value><country>United
Kingdom</country><code>BD17 5EJ</code>"
  +            + "<city>Shipley</city><street>6, Westgate</street></value></entry></addresses></address-book>";
  +        
  +        xmlAssertIsomorphic(parseString(out.toString()), parseString(xml), true);
  +        
  +//        SimpleLog log = new SimpleLog("[testReadMap:BeanRuleSet]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        BeanRuleSet.setLog(log);
  +//        log = new SimpleLog("[testReadMap:XMLIntrospectorHelper]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        XMLIntrospectorHelper.setLog(log);
  +//        log = new SimpleLog("[testReadMap:MapEntryAdder]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        MapEntryAdder.setLog(log);
  +
  +        BeanReader reader = new BeanReader();
  +
  +//        log = new SimpleLog("[testReadMap:BeanReader]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        reader.setLog(log);
  +//        log = new SimpleLog("[testReadMap:XMLIntrospector]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        reader.getXMLIntrospector().setLog(log);
  +
  +        reader.setMatchIDs(false);
  +        reader.registerBeanClass("address-book", MapBean.class);
  +        bean = (MapBean) reader.parse(new StringReader(xml));
  +        
  +        assertEquals("Title property is incorrect", "drinkers", bean.getTitle());
  +        assertEquals("Map entries", 3, bean.getAddresses().size());
  +        
  +        AddressBean address = (AddressBean) bean.getAddresses().get("Russell McManus");
  +        assertNotNull("Missing entry for 'Russell McManus'", address);
  +        assertEquals("Bad address (1)", "6, Westgate", address.getStreet());
  +        assertEquals("Bad address (2)", "Shipley", address.getCity());
  +        assertEquals("Bad address (3)",  "United Kingdom", address.getCountry());
  +        assertEquals("Bad address (4)", "BD17 5EJ", address.getCode());
  +                    
  +        address = (AddressBean) bean.getAddresses().get("Alex Compbell");
  +        assertNotNull("Missing entry for 'Alex Compbell'", address);
  +        assertEquals("Bad address (5)", "5, Kirkgate", address.getStreet());
  +        assertEquals("Bad address (6)", "Shipley", address.getCity());
  +        assertEquals("Bad address (7)",  "United Kingdom", address.getCountry());
  +        assertEquals("Bad address (8)", "BD18 3QW", address.getCode());
  +         
  +        address = (AddressBean) bean.getAddresses().get("Sid Gardner");
  +        assertNotNull("Missing entry for 'Sid Gardner'", address);
  +        assertEquals("Bad address (9)", "Old House At Home, Otley Road", address.getStreet());
  +        assertEquals("Bad address (10)", "Shipley", address.getCity());
  +        assertEquals("Bad address (11)",  "United Kingdom", address.getCountry());
  +        assertEquals("Bad address (12)", "BD18 2BJ", address.getCode());
       }
       
       /** 
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/MapBean.java
  
  Index: MapBean.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/MapBean.java,v
1.1 2003/04/11 21:29:46 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 21:29:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 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/>.
   * 
   * $Id: MapBean.java,v 1.1 2003/04/11 21:29:46 rdonkin Exp $
   */
  package org.apache.commons.betwixt;
  
  import java.util.Map;
  import java.util.HashMap;
  
  /** <p><code>MapBean</code> is a sample bean used for testing maps.</p>
    *
    * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
    * @version $Revision: 1.1 $
    */
  public class MapBean {
      
      private String title = "**UNSET**";
      
      private Map addresses = new HashMap();
      
      public MapBean() {}
      
      public MapBean(String title) {
          setTitle(title);
      }	
      
      public String getTitle() {
          return title;
      }
      
      public void setTitle(String title) {
          this.title = title;
      }	
      
      public Map getAddresses() {
          return addresses;
      }	
      
      public void addAddress(String name, AddressBean address) {
          addresses.put(name, address);
      }
  }
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/expression/AdderBean.java
  
  Index: AdderBean.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/expression/AdderBean.java,v
1.1 2003/04/11 21:29:46 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 21:29:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 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/>.
   * 
   * $Id: AdderBean.java,v 1.1 2003/04/11 21:29:46 rdonkin Exp $
   */
  package org.apache.commons.betwixt.expression;
  
  /** <p><code>AdderBean</code> used to test map updates.</p>
    *
    * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
    */
  public class AdderBean {
  
      private String key;
      private String value;
      
      public String getKey() {
          return key;
      }	
      
      public String getValue() {
          return value;
      }
      
      public void add(String key, String value) {
          this.key = key;
          this.value = value;
      }
  }
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/expression/TestUpdaters.java
  
  Index: TestUpdaters.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/expression/TestUpdaters.java,v
1.1 2003/04/11 21:29:46 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2003/04/11 21:29:46 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 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/>.
   * 
   * $Id: TestUpdaters.java,v 1.1 2003/04/11 21:29:46 rdonkin Exp $
   */
  package org.apache.commons.betwixt.expression;
  
  import java.lang.reflect.Method;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  
  import org.apache.commons.betwixt.AbstractTestCase;
  
  /** Test harness for map updating 
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class TestUpdaters extends AbstractTestCase {
      
      public static Test suite() {
          return new TestSuite(TestUpdaters.class);
      }
      
      public TestUpdaters(String testName) {
          super(testName);
      }
      
      public void testMapUpdate() throws Exception {	
          Class[] params = { String.class, String.class } ;
          Method method = AdderBean.class.getMethod("add", params);
          MapEntryAdder adder = new MapEntryAdder(method);
          
          AdderBean bean = new AdderBean();
          bean.add("UNSET", "UNSET");
          
          Updater keyUpdater = adder.getKeyUpdater();
          Updater valueUpdater = adder.getValueUpdater();
          
          Context context = new Context();
          context.setBean(bean);
          
          keyUpdater.update(context, "key");
          valueUpdater.update(context, "value");
          
          assertEquals("AdderBean not updated (1)", "key", bean.getKey());
          assertEquals("AdderBean not updated (2)", "value", bean.getValue());
          
          keyUpdater.update(context, "new-key");
          valueUpdater.update(context, "new-value");
          
          assertEquals("AdderBean not updated (1)", "new-key", bean.getKey());
          assertEquals("AdderBean not updated (2)", "new-value", bean.getValue());       

          
      }
  }
  
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message