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/dotbetwixt TestBeanToXml.java TestXmlToBean.java
Date Sun, 24 Aug 2003 16:57:41 GMT
rdonkin     2003/08/24 09:57:41

  Modified:    betwixt/src/test/org/apache/commons/betwixt/dotbetwixt
                        TestBeanToXml.java TestXmlToBean.java
  Log:
  Test cases for implementation class attribute
  
  Revision  Changes    Path
  1.12      +33 -4     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java
  
  Index: TestBeanToXml.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestBeanToXml.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- TestBeanToXml.java	13 Jul 2003 21:30:27 -0000	1.11
  +++ TestBeanToXml.java	24 Aug 2003 16:57:40 -0000	1.12
  @@ -68,6 +68,7 @@
   
   import org.apache.commons.betwixt.io.BeanWriter;
   import org.apache.commons.betwixt.xmlunit.XmlTestCase;
  +import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
   
   
   /** 
  @@ -198,5 +199,33 @@
                       parseString(out.toString()));
           }
       
  +    /** Tests basic use of an implementation for an interface */
  +    public void testBasicInterfaceImpl() throws Exception {
  +        ExampleBean bean = new ExampleBean("Alice");
  +        bean.addExample(new ExampleImpl(1, "Mad Hatter"));
  +        bean.addExample(new ExampleImpl(2, "March Hare"));
  +        bean.addExample(new ExampleImpl(3, "Dormouse"));
  +        
  +        StringWriter out = new StringWriter();
  +        out.write("<?xml version='1.0' encoding='UTF-8'?>");
  +        
  +        BeanWriter writer = new BeanWriter( out );
  +        writer.getXMLIntrospector().setElementNameMapper(new HyphenatedNameMapper());
  +        writer.getXMLIntrospector().setWrapCollectionsInElement(false);
  +        
  +        writer.write( bean );
  +        
  +        String xml = "<?xml version='1.0' encoding='UTF-8'?>"
  +            + "<example-bean><name>Alice</name>"
  +            + "<example><id>1</id><name>Mad Hatter</name></example>"
  +            + "<example><id>2</id><name>March Hare</name></example>"
  +            + "<example><id>3</id><name>Dormouse</name></example>"
  +            + "</example-bean>";
  +        
  +        xmlAssertIsomorphicContent(
  +                    parseString(xml),
  +                    parseString(out.toString()),
  +                    true);
  +    }        
   }
   
  
  
  
  1.3       +40 -4     jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestXmlToBean.java
  
  Index: TestXmlToBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/dotbetwixt/TestXmlToBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestXmlToBean.java	13 Jul 2003 21:30:27 -0000	1.2
  +++ TestXmlToBean.java	24 Aug 2003 16:57:40 -0000	1.3
  @@ -74,6 +74,8 @@
   import org.apache.commons.betwixt.io.BeanWriter;
   import org.apache.commons.betwixt.io.BeanReader;
   import org.apache.commons.betwixt.io.BeanRuleSet;
  +import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
  +
   import org.apache.commons.betwixt.xmlunit.XmlTestCase;
   
   import org.apache.commons.logging.impl.SimpleLog;
  @@ -187,5 +189,39 @@
           assertEquals("Property Beta matches", "The Universe And Everything", result.getBeta());
           assertEquals("Property Gamma matches", 42, result.getGamma());
       }
  +    
  +    
  +    /** Tests basic use of an implementation for an interface */
  +    public void testBasicInterfaceImpl() throws Exception {
  +        SimpleLog log = new SimpleLog("[testBasicInterfaceImpl:BeanRuleSet]");
  +        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        BeanRuleSet.setLog(log);
  +        log = new SimpleLog("[testBasicInterfaceImpl:BeanReader]");
  +        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +    
  +        ExampleBean bean = new ExampleBean("Alice");
  +        bean.addExample(new ExampleImpl(1, "Mad Hatter"));
  +        bean.addExample(new ExampleImpl(2, "March Hare"));
  +        bean.addExample(new ExampleImpl(3, "Dormouse"));
  +        
  +        String xml = "<?xml version='1.0' encoding='UTF-8'?>"
  +            + "<example-bean><name>Alice</name>"
  +            + "<example><id>1</id><name>Mad Hatter</name></example>"
  +            + "<example><id>2</id><name>March Hare</name></example>"
  +            + "<example><id>3</id><name>Dormouse</name></example>"
  +            + "</example-bean>";
  +        
  +        
  +        BeanReader reader = new BeanReader();
  +        reader.setLog(log);
  +        reader.getXMLIntrospector().setElementNameMapper(new HyphenatedNameMapper());
  +        reader.getXMLIntrospector().setWrapCollectionsInElement(false);
  +        reader.registerBeanClass( ExampleBean.class );
  +        
  +        StringReader in = new StringReader( xml );
  +        ExampleBean out = (ExampleBean) reader.parse( in ); 
  +        assertEquals("Interface read failed", bean, out);
  +        
  +    }      
   }
   
  
  
  

Mime
View raw message