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 TestRecursion.java recursion.xml
Date Sun, 06 Jul 2003 21:10:35 GMT
rdonkin     2003/07/06 14:10:35

  Modified:    betwixt/src/test/org/apache/commons/betwixt/recursion
                        TestRecursion.java recursion.xml
  Log:
  Improved unit tests by adding automated testing of xml output.
  
  Revision  Changes    Path
  1.9       +57 -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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- TestRecursion.java	1 Jul 2003 19:12:36 -0000	1.8
  +++ TestRecursion.java	6 Jul 2003 21:10:34 -0000	1.9
  @@ -108,16 +108,63 @@
       public void testReadwithCollectionsInElementRoundTrip()
       throws Exception
       {
  +        //SimpleLog log = new SimpleLog("[testReadwithCollectionsInElementRoundTrip:XMLIntrospectorHelper]");
  +        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        //XMLIntrospectorHelper.setLog(log);
  +        
  +        //log = new SimpleLog("[testReadwithCollectionsInElementRoundTrip:XMLIntrospector]");
  +        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +    
           XMLIntrospector intro = createXMLIntrospector();
  -        //((SimpleLog) intro.getLog()).setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        //intro.setLog(log);
           intro.setWrapCollectionsInElement(true);
  +        
  +        //log = new SimpleLog("[testReadwithCollectionsInElementRoundTrip:BeanReader]");
  +        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        
           BeanReader reader = new BeanReader();
  -        reader.registerBeanClass(ElementBean.class);
           reader.setXMLIntrospector(intro);
  -        Object object = reader.parse(getTestFileURL("src/test/org/apache/commons/betwixt/recursion/recursion.xml"));
  +        //reader.setLog(log);
  +        reader.registerBeanClass(ElementBean.class);
  +        
  +        ElementBean bean = (ElementBean) reader.parse(
  +                    getTestFileURL("src/test/org/apache/commons/betwixt/recursion/recursion.xml"));
  +        
  +        List elements = bean.getElements();
  +        assertEquals("Root elements size", 2, elements.size());
  +        Element elementOne = (Element) elements.get(0);
  +        assertEquals("Element one name", "element1", elementOne.getName());
  +        Element elementTwo = (Element) elements.get(1);
  +        assertEquals("Element two name", "element2", elementTwo.getName());
  +        assertEquals("Element two children", 0, elementTwo.getElements().size());
  +        elements = elementOne.getElements();
  +        assertEquals("Element one children", 2, elements.size());
  +        Element elementOneOne = (Element) elements.get(0);
  +        assertEquals("Element one one name", "element11", elementOneOne.getName());
  +        Element elementOneTwo = (Element) elements.get(1);
  +        assertEquals("Element one two name", "element12", elementOneTwo.getName());
  +        assertEquals("Element one two children", 0, elementOneTwo.getElements().size());
  +        elements = elementOneOne.getElements();
  +        assertEquals("Element one one children", 2, elements.size());
  +        Element elementOneOneOne = (Element) elements.get(0);
  +        assertEquals("Element one one one name", "element111", elementOneOneOne.getName());
  +        Element elementOneOneTwo = (Element) elements.get(1);
  +        assertEquals("Element one one two name", "element112", elementOneOneTwo.getName());
       
  +        
           StringWriter buffer = new StringWriter();
  -        write (object, buffer, true);
  -        System.out.println("buffer : "+buffer);
  +        write (bean, buffer, true);
  +            
  +        String xml = "<?xml version='1.0'?><ElementBean><elements><element
name='element1'>"
  +                    + "<elements><element name='element11'><elements><element
name='element111'>"
  +                    + "<elements/></element><element name='element112'><elements/></element>"
  +                    + "</elements></element><element name='element12'><elements/></element>"
  +                    + "</elements></element><element name='element2'><elements/>"
  +                    + "</element></elements></ElementBean>";
  +        
  +        xmlAssertIsomorphic(	
  +                    parseString(xml), 
  +                    parseString(buffer.getBuffer().toString()), 
  +                    true);
       }
       /**
        * This will test reading a simple recursive xml file
  
  
  
  1.2       +5 -3      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/recursion/recursion.xml
  
  Index: recursion.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/recursion/recursion.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- recursion.xml	30 Jul 2002 22:47:41 -0000	1.1
  +++ recursion.xml	6 Jul 2003 21:10:34 -0000	1.2
  @@ -5,8 +5,10 @@
       <element name="element1">
         <elements>
           <element name="element11">
  -          <element name="element111"/>
  -          <element name="element112"/>
  +          <elements>
  +            <element name="element111"/>
  +            <element name="element112"/>
  +          </elements>
           </element>
           <element name="element12"/>
         </elements>
  
  
  

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