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/recursion ElementBean.java TestRecursion.java
Date Tue, 01 Jul 2003 19:12:39 GMT
rdonkin     2003/07/01 12:12:39

  Modified:    betwixt/src/test/org/apache/commons/betwixt/recursion
                        ElementBean.java TestRecursion.java
  Log:
  Improved unit tests by checking xml created.
  
  Revision  Changes    Path
  1.3       +5 -5      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/recursion/ElementBean.java
  
  Index: ElementBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/recursion/ElementBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ElementBean.java	26 Sep 2002 19:29:34 -0000	1.2
  +++ ElementBean.java	1 Jul 2003 19:12:36 -0000	1.3
  @@ -91,7 +91,7 @@
   
       public String toString()
       {
  -       return "list : "+getElements();
  +       return "list : " + getElements();
       }
       
   
  
  
  
  1.8       +69 -10    jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/recursion/TestRecursion.java
  
  Index: TestRecursion.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/recursion/TestRecursion.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- TestRecursion.java	13 Feb 2003 18:41:48 -0000	1.7
  +++ TestRecursion.java	1 Jul 2003 19:12:36 -0000	1.8
  @@ -61,6 +61,8 @@
    */
   package org.apache.commons.betwixt.recursion;
   
  +import java.util.List;
  +
   import java.io.StringWriter;
   import java.io.Writer;
   
  @@ -72,6 +74,10 @@
   import org.apache.commons.betwixt.io.BeanReader;
   import org.apache.commons.betwixt.io.BeanWriter;
   import org.apache.commons.betwixt.io.CyclicReferenceException;
  +import org.apache.commons.betwixt.io.BeanRuleSet;
  +
  +import org.apache.commons.logging.impl.SimpleLog;
  +import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
   
   
   /**
  @@ -119,15 +125,68 @@
       public void testReadWithoutCollectionsInElementRoundTrip()
       throws Exception
       {
  -        System.out.println("\ntestReadWithoutCollectionsInElement()\n");
  +//        SimpleLog log = new SimpleLog("[testReadWithoutCollectionsInElementRoundTrip:BeanRuleSet]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        BeanRuleSet.setLog(log);
  +        
  +//	log = new SimpleLog("[testReadWithoutCollectionsInElementRoundTrip:XMLIntrospector]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  + 
           XMLIntrospector intro = createXMLIntrospector();
  +        intro.setWrapCollectionsInElement(false);
  +//        intro.setLog(log);
  +//        log = new SimpleLog("[testReadWithoutCollectionsInElementRoundTrip:XMLIntrospectorHelper]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        XMLIntrospectorHelper.setLog(log);
           BeanReader reader = new BeanReader();
  -        reader.registerBeanClass(ElementBean.class);
  +//        log = new SimpleLog("[testReadWithoutCollectionsInElementRoundTrip:BeanReader]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +//        reader.setLog(log);
           reader.setXMLIntrospector(intro);
  -        Object object = reader.parse(getTestFileURL("src/test/org/apache/commons/betwixt/recursion/recursion2.xml"));
  +        reader.registerBeanClass(ElementBean.class);
  +        ElementBean bean = (ElementBean) reader.
  +                        parse(getTestFileURL("src/test/org/apache/commons/betwixt/recursion/recursion2.xml"));
  +        List elements = bean.getElements();
  +        assertEquals("Number of elements in root bean", 2, elements.size());
  +        Element elementOne = (Element) bean.elements.get(0);
  +        assertEquals("First element name", "element1", elementOne.getName());
  +        Element elementTwo = (Element) bean.elements.get(1);
  +        assertEquals("Second element name", "element2", elementTwo.getName());
  +        
  +        elements = elementOne.getElements();
  +        assertEquals("Number of child elements in first element", 2, elements.size());
  +        Element elementOneOne = (Element) elements.get(0);
  +        assertEquals("11 element name", "element11", elementOneOne.getName());
  +        Element elementOneTwo = (Element) elements.get(1);
  +        assertEquals("12 element name", "element12", elementOneTwo.getName());
  +        
  +        elements = elementOneOne.getElements();
  +        assertEquals("Number of child elements in element 11", 2, elements.size());
  +        Element elementOneOneOne = (Element) elements.get(0);
  +        assertEquals("111 element name", "element111", elementOneOneOne.getName());
  +
  +        assertEquals("111 child elements ", 0, elementOneOneOne.getElements().size());
  +        
  +        Element elementOneOneTwo = (Element) elements.get(1);
  +        assertEquals("112 element name", "element112", elementOneOneTwo.getName());
  +        assertEquals("112 child elements ", 0, elementOneOneTwo.getElements().size());
  +        
  +        elements = elementOneTwo.getElements();
  +        assertEquals("Number of child elements in element 12", 0, elements.size());
  +        
  +        elements = elementTwo.getElements();
  +        assertEquals("Number of child elements in element 2", 0, elements.size());
  +        
           StringWriter buffer = new StringWriter();
  -        write (object, buffer, false);
  -        System.out.println("buffer : "+buffer);
  +        buffer.write("<?xml version='1.0'?>");
  +        write (bean, buffer, false);
  + 
  +        String xml = "<ElementBean><element name='element1'><element name='element11'><element
name='element111' />"
  +                + "<element name='element112' /> </element><element name='element12'
/> </element>"
  +                + "<element name='element2' /> </ElementBean>";
  +        
  +        xmlAssertIsomorphic(parseString(xml), parseString(buffer.getBuffer().toString()),
true);
  +        
       }
       
       /**
  
  
  

---------------------------------------------------------------------
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