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/introspection test-bwbi-output.xml BeanWithBeanInfoBean.java TestXMLIntrospector.java
Date Mon, 30 Dec 2002 22:45:05 GMT
rdonkin     2002/12/30 14:45:05

  Modified:    betwixt/src/test/org/apache/commons/betwixt/dotbetwixt
                        TestBeanToXml.java
               betwixt/src/test/org/apache/commons/betwixt/introspection
                        BeanWithBeanInfoBean.java TestXMLIntrospector.java
  Added:       betwixt/src/test/org/apache/commons/betwixt/introspection
                        test-bwbi-output.xml
  Log:
  Added new test case for introspection case where bean has custom beaninfo class
  
  Revision  Changes    Path
  1.7       +4 -11     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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- TestBeanToXml.java	30 Dec 2002 18:16:48 -0000	1.6
  +++ TestBeanToXml.java	30 Dec 2002 22:45:05 -0000	1.7
  @@ -78,8 +78,6 @@
     */
   public class TestBeanToXml extends XmlTestCase {
   
  -    private final static boolean debug = true;
  -
   //--------------------------------- Test Suite
       
       public static Test suite() {
  @@ -117,11 +115,6 @@
           writer.write(bean);
           out.flush();
           String xml = out.toString();
  -
  -        if (debug) {
  -            System.out.println("************testSimpleBean************");
  -            System.out.println(xml);
  -        }
           
           xmlAssertIsomorphicContent(
                       parseFile("src/test/org/apache/commons/betwixt/dotbetwixt/simpletestone.xml"),
  
  
  
  1.2       +6 -6      jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/BeanWithBeanInfoBean.java
  
  Index: BeanWithBeanInfoBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/BeanWithBeanInfoBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BeanWithBeanInfoBean.java	30 Dec 2002 20:32:30 -0000	1.1
  +++ BeanWithBeanInfoBean.java	30 Dec 2002 22:45:05 -0000	1.2
  @@ -84,7 +84,7 @@
       
       public BeanWithBeanInfoBean() {}
       
  -    public BeanWithBeanInfoBean(String alpha, String beta) {
  +    public BeanWithBeanInfoBean(String alpha, String beta, String gamma) {
           setAlpha(alpha);
           setBeta(beta);
           gammaSetter(gamma);
  
  
  
  1.2       +65 -11    jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java
  
  Index: TestXMLIntrospector.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestXMLIntrospector.java	30 Dec 2002 20:32:30 -0000	1.1
  +++ TestXMLIntrospector.java	30 Dec 2002 22:45:05 -0000	1.2
  @@ -61,6 +61,8 @@
    */
   package org.apache.commons.betwixt.introspection;
   
  +import java.io.StringWriter;
  +
   import java.beans.Introspector;
   import java.beans.PropertyDescriptor;
   import java.beans.BeanInfo;
  @@ -69,6 +71,8 @@
   import junit.framework.TestSuite;
   import junit.textui.TestRunner;
   
  +import org.apache.commons.logging.impl.SimpleLog;
  +
   import org.apache.commons.betwixt.registry.DefaultXMLBeanInfoRegistry;
   import org.apache.commons.betwixt.registry.NoCacheRegistry;
   
  @@ -78,6 +82,8 @@
   import org.apache.commons.betwixt.ElementDescriptor;
   import org.apache.commons.betwixt.AttributeDescriptor;
   
  +import org.apache.commons.betwixt.io.BeanWriter;
  +
   
   /** Test harness for the XMLIntrospector
     *
  @@ -165,23 +171,71 @@
       }
       
       public void testBeanWithBeanInfo() throws Exception {
  +        
           // let's check that bean info's ok
           BeanInfo bwbiBeanInfo = Introspector.getBeanInfo(BeanWithBeanInfoBean.class);
           
  -        PropertyDescriptor[] descriptors = bwbiBeanInfo.getPropertyDescriptors();
  +        PropertyDescriptor[] propertyDescriptors = bwbiBeanInfo.getPropertyDescriptors();
   
  -        assertEquals("Wrong number of properties", 2 , descriptors.length);
  +        assertEquals("Wrong number of properties", 2 , propertyDescriptors.length);
           
           // order of properties isn't guarenteed 
  -        if ("alpha".equals(descriptors[0].getName())) {
  +        if ("alpha".equals(propertyDescriptors[0].getName())) {
           
  -            assertEquals("Second property name", "gamma" , descriptors[1].getName());
  +            assertEquals("Second property name", "gamma" , propertyDescriptors[1].getName());
               
           } else {
           
  -            assertEquals("First property name", "gamma" , descriptors[0].getName());
  -            assertEquals("Second property name", "alpha" , descriptors[1].getName());
  +            assertEquals("First property name", "gamma" , propertyDescriptors[0].getName());
  +            assertEquals("Second property name", "alpha" , propertyDescriptors[1].getName());
           }
  +        
  +        // finished with the descriptors
  +        propertyDescriptors = null;
  +
  +//        SimpleLog log = new SimpleLog("[testBeanWithBeanInfo:XMLIntrospector]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_TRACE);
  +
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        introspector.setAttributesForPrimitives(false);
  +//        introspector.setLog(log);
  +        
  +        XMLBeanInfo xmlBeanInfo = introspector.introspect(BeanWithBeanInfoBean.class);
  +        
  +        ElementDescriptor[] elementDescriptors = xmlBeanInfo.getElementDescriptor().getElementDescriptors();
  +        
  +//        log = new SimpleLog("[testBeanWithBeanInfo]");
  +//        log.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
  +        
  +//        log.debug("XMLBeanInfo:");
  +//        log.debug(xmlBeanInfo);
  +//        log.debug("Elements:");
  +//        log.debug(elementDescriptors[0].getPropertyName());
  +//        log.debug(elementDescriptors[1].getPropertyName());
  +        
  +        assertEquals("Wrong number of elements", 2 , elementDescriptors.length);
  +
  +        // order of properties isn't guarenteed 
  +        if ("alpha".equals(elementDescriptors[0].getPropertyName())) {
  +        
  +            assertEquals("Second element name", "gamma" , elementDescriptors[1].getPropertyName());
  +            
  +        } else {
  +        
  +            assertEquals("First element name", "gamma" , elementDescriptors[0].getPropertyName());
  +            assertEquals("Second element name", "alpha" , elementDescriptors[1].getPropertyName());
  +        }
  +        
  +        // might as well give test output
  +        StringWriter out = new StringWriter();
  +        BeanWriter writer = new BeanWriter(out);
  +        writer.setWriteIDs(false);
  +        BeanWithBeanInfoBean bean = new BeanWithBeanInfoBean("alpha value","beta value","gamma
value");
  +        writer.write(bean);
  +        
  +        xmlAssertIsomorphicContent(
  +                    parseFile("src/test/org/apache/commons/betwixt/introspection/test-bwbi-output.xml"),
  +                    parseString(out.toString()));
       }
   }
   
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/test-bwbi-output.xml
  
  Index: test-bwbi-output.xml
  ===================================================================
  <?xml version='1.0'?>
  <BeanWithBeanInfoBean>
  	<gamma>gamma value</gamma>
  	<alpha>alpha value</alpha>
  </BeanWithBeanInfoBean>
  
  

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


Mime
View raw message