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 TestXMLIntrospector.java
Date Mon, 08 Sep 2003 14:00:47 GMT
rdonkin     2003/09/08 07:00:47

  Modified:    betwixt/src/test/org/apache/commons/betwixt/dotbetwixt
                        TestXmlToBean.java
               betwixt/src/test/org/apache/commons/betwixt/introspection
                        TestXMLIntrospector.java
  Log:
  Test cases for ClassNormalizer
  
  Revision  Changes    Path
  1.4       +10 -10    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestXmlToBean.java	24 Aug 2003 16:57:40 -0000	1.3
  +++ TestXmlToBean.java	8 Sep 2003 14:00:47 -0000	1.4
  @@ -193,11 +193,11 @@
       
       /** 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);
  +        //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"));
  @@ -213,7 +213,7 @@
           
           
           BeanReader reader = new BeanReader();
  -        reader.setLog(log);
  +        //reader.setLog(log);
           reader.getXMLIntrospector().setElementNameMapper(new HyphenatedNameMapper());
           reader.getXMLIntrospector().setWrapCollectionsInElement(false);
           reader.registerBeanClass( ExampleBean.class );
  
  
  
  1.6       +65 -5     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- TestXMLIntrospector.java	27 Jul 2003 17:55:51 -0000	1.5
  +++ TestXMLIntrospector.java	8 Sep 2003 14:00:47 -0000	1.6
  @@ -80,6 +80,9 @@
   import org.apache.commons.betwixt.ElementDescriptor;
   import org.apache.commons.betwixt.AttributeDescriptor;
   
  +import org.apache.commons.betwixt.strategy.ClassNormalizer;
  +import org.apache.commons.betwixt.strategy.ListedClassNormalizer;
  +
   import org.apache.commons.betwixt.io.BeanWriter;
   
   import org.apache.commons.logging.impl.SimpleLog;
  @@ -250,5 +253,62 @@
                       parseString(out.toString()));
           }
       }
  +    
  +    public void testDefaultClassNormalizer() throws Exception {
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        
  +        FaceImpl face = new FaceImpl();
  +        XMLBeanInfo info = introspector.introspect( face );
  +        ElementDescriptor elementDescriptor = info.getElementDescriptor();
  +    
  +        AttributeDescriptor[] attributeDescriptor = elementDescriptor.getAttributeDescriptors();
     
  +        ElementDescriptor[] children = elementDescriptor.getElementDescriptors();
  +        
  +        assertEquals("Expected no attributes", 0, attributeDescriptor.length);
  +        assertEquals("Expected two elements", 2, children.length);
  +    }	
  +    
  +    public void testClassNormalizer() throws Exception {
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        introspector.setClassNormalizer( new ClassNormalizer() {
  +                
  +                public Class normalize(Class clazz) {
  +                    if (IFace.class.isAssignableFrom( clazz )) {
  +                        return IFace.class;
  +                    }	
  +                    return super.normalize( clazz );
  +                }	
  +            });
  +        
  +        FaceImpl face = new FaceImpl();
  +        XMLBeanInfo info = introspector.introspect( face );
  +        ElementDescriptor elementDescriptor = info.getElementDescriptor();
  +        assertEquals("Expected only itself", 1, elementDescriptor.getElementDescriptors().length);
  +    
  +        AttributeDescriptor[] attributeDescriptor = elementDescriptor.getAttributeDescriptors();
     
  +        ElementDescriptor[] children = elementDescriptor.getElementDescriptors();
  +        
  +        assertEquals("Expected no attributes", 0, attributeDescriptor.length);
  +        assertEquals("Expected one elements", 1, children.length);
  +        assertEquals("Expected element", "name", children[0].getLocalName());
  +    }	
  +    
  +    public void testListedClassNormalizer() throws Exception {
  +        ListedClassNormalizer classNormalizer = new ListedClassNormalizer();
  +        classNormalizer.addSubstitution( IFace.class );
  +        XMLIntrospector introspector = new XMLIntrospector();
  +        introspector.setClassNormalizer(classNormalizer);
  +        
  +        FaceImpl face = new FaceImpl();
  +        
  +        XMLBeanInfo info = introspector.introspect( face );
  +        ElementDescriptor elementDescriptor = info.getElementDescriptor();
  +        AttributeDescriptor[] attributeDescriptor = elementDescriptor.getAttributeDescriptors();
     
  +        ElementDescriptor[] children = elementDescriptor.getElementDescriptors();
  +        
  +        assertEquals("Expected no attributes", 0, attributeDescriptor.length);
  +        assertEquals("Expected one elements", 1, children.length);
  +        assertEquals("Expected element", "name", children[0].getLocalName());
  +    }	    
   }
   
  
  
  

Mime
View raw message