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 TestBeanWriter.java
Date Thu, 24 Apr 2003 08:52:21 GMT
rdonkin     2003/04/24 01:52:20

  Modified:    betwixt/src/java/org/apache/commons/betwixt/io
                        AbstractBeanWriter.java
               betwixt/src/test/org/apache/commons/betwixt
                        TestBeanWriter.java
  Log:
  Fixed bug in writing lists introduced by adding not writing empty elements.
  
  Revision  Changes    Path
  1.16      +13 -5     jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java
  
  Index: AbstractBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/io/AbstractBeanWriter.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- AbstractBeanWriter.java	19 Mar 2003 22:59:02 -0000	1.15
  +++ AbstractBeanWriter.java	24 Apr 2003 08:52:20 -0000	1.16
  @@ -74,6 +74,7 @@
   import org.apache.commons.betwixt.expression.Context;
   import org.apache.commons.betwixt.expression.Expression;
   import org.apache.commons.betwixt.io.id.SequentialIDGenerator;
  +import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
   import org.apache.commons.collections.ArrayStack;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
  @@ -851,6 +852,12 @@
               }
           }
           
  +        // always write out loops - even when they have no elements
  +        if ( XMLIntrospectorHelper.isLoopType( descriptor.getPropertyType() ) ) {
  +            log.trace("Loop type so not empty.");
  +            return false;
  +        }
  +        
           // now test child elements
           // an element is empty if it has no non-empty child elements
           if ( descriptor.hasChildren() ) {
  @@ -862,6 +869,7 @@
               }
           }
           
  +        log.trace( "Element is empty." );
           return true;
       }
       
  
  
  
  1.11      +107 -0    jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanWriter.java
  
  Index: TestBeanWriter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanWriter.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- TestBeanWriter.java	15 Apr 2003 21:51:45 -0000	1.10
  +++ TestBeanWriter.java	24 Apr 2003 08:52:20 -0000	1.11
  @@ -72,6 +72,7 @@
   import org.apache.commons.betwixt.io.BeanWriter;
   import org.apache.commons.betwixt.io.CyclicReferenceException;
   import org.apache.commons.logging.impl.SimpleLog;
  +import org.apache.commons.betwixt.digester.XMLIntrospectorHelper;
   
   
   /** Test harness for the BeanWriter
  @@ -353,6 +354,112 @@
            + "<String>That</String>" 
            + "<String>The Other</String>" 
            +"</Array>";
  +         
  +        xmlAssertIsomorphicContent(
  +                            parseString(out.getBuffer().toString()),
  +                            parseString(xml), 
  +                            true);
  +    }
  +    
  +    
  +    /** Test nested case for writing empty elements */
  +    public void testListedWriteEmptyElements() throws Exception {
  +        ListOfNames names = new ListOfNames();
  +        names.addName(new NameBean("Tom"));
  +        names.addName(new NameBean("Dick"));
  +        names.addName(new NameBean("Harry"));
  +        names.addName(new NameBean(""));
  +    
  +        StringWriter out = new StringWriter();
  +        out.write("<?xml version='1.0'?>");
  +
  +        BeanWriter writer = new BeanWriter(out);
  +        
  +        //SimpleLog log = new SimpleLog("[testListedWriteEmptyElements:AbstractBeanWriter]");
  +        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        //writer.setAbstractBeanWriterLog(log);
  +        
  +        //log = new SimpleLog("[testListedWriteEmptyElements:XMLIntrospector]");
  +        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        //writer.getXMLIntrospector().setLog(log);
  +        
  +        //log = new SimpleLog("[testListedWriteEmptyElements:XMLIntrospectorHelper]");
  +        //log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +        //XMLIntrospectorHelper.setLog(log);
  +        
  +        writer.setWriteEmptyElements(false);
  +        writer.getXMLIntrospector().setWrapCollectionsInElement(false);
  +        writer.setWriteIDs(false);
  +        writer.write("Names", names);
  +        
  +        String xml = "<?xml version='1.0'?><Names>"
  +         + "<name><name>Tom</name></name>" 
  +         + "<name><name>Dick</name></name>" 
  +         + "<name><name>Harry</name></name>" 
  +         +"</Names>";
  +         
  +        xmlAssertIsomorphicContent(
  +                            parseString(out.getBuffer().toString()),
  +                            parseString(xml), 
  +                            true);
  +                            
  +        out = new StringWriter();
  +        out.write("<?xml version='1.0'?>");
  +
  +        writer = new BeanWriter(out);
  +        writer.setWriteEmptyElements(true);
  +        writer.getXMLIntrospector().setWrapCollectionsInElement(false);
  +        writer.setWriteIDs(false);
  +        writer.write("Names", names);
  +        
  +        xml = "<?xml version='1.0'?><Names>"
  +         + "<name><name>Tom</name></name>" 
  +         + "<name><name>Dick</name></name>" 
  +         + "<name><name>Harry</name></name>" 
  +         + "<name><name/></name>"
  +         +"</Names>";
  +         
  +        xmlAssertIsomorphicContent(
  +                            parseString(out.getBuffer().toString()),
  +                            parseString(xml), 
  +                            true);
  +                            
  +        out = new StringWriter();
  +        out.write("<?xml version='1.0'?>");
  +
  +        writer = new BeanWriter(out);
  +        writer.setWriteEmptyElements(true);
  +        writer.getXMLIntrospector().setWrapCollectionsInElement(true);
  +        writer.setWriteIDs(false);
  +        writer.write("Names", names);
  +        
  +        xml = "<?xml version='1.0'?><Names><names>"
  +         + "<name><name>Tom</name></name>" 
  +         + "<name><name>Dick</name></name>" 
  +         + "<name><name>Harry</name></name>" 
  +         + "<name><name/></name></names>"
  +         +"</Names>";
  +         
  +        xmlAssertIsomorphicContent(
  +                            parseString(out.getBuffer().toString()),
  +                            parseString(xml), 
  +                            true);
  +                            
  +        out = new StringWriter();
  +        out.write("<?xml version='1.0'?>");
  +
  +        writer = new BeanWriter(out);
  +        writer.setWriteEmptyElements(false);
  +        writer.getXMLIntrospector().setWrapCollectionsInElement(true);
  +        writer.setWriteIDs(false);
  +        writer.write("Names", names);
  +        
  +        xml = "<?xml version='1.0'?><Names><names>"
  +         + "<name><name>Tom</name></name>" 
  +         + "<name><name>Dick</name></name>" 
  +         + "<name><name>Harry</name></name>" 
  +         + "</names>"
  +         +"</Names>";
            
           xmlAssertIsomorphicContent(
                               parseString(out.getBuffer().toString()),
  
  
  

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