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 BeanWithBeanInfoBean.java BeanWithBeanInfoBeanBeanInfo.java TestXMLIntrospector.java
Date Mon, 30 Dec 2002 20:32:30 GMT
rdonkin     2002/12/30 12:32:30

  Added:       betwixt/src/test/org/apache/commons/betwixt/introspection
                        BeanWithBeanInfoBean.java
                        BeanWithBeanInfoBeanBeanInfo.java
                        TestXMLIntrospector.java
  Removed:     betwixt/src/test/org/apache/commons/betwixt
                        TestXMLIntrospector.java
  Log:
  Start of test case for introspection of beans with BeanInfos.
  
  Revision  Changes    Path
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/BeanWithBeanInfoBean.java
  
  Index: BeanWithBeanInfoBean.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/BeanWithBeanInfoBean.java,v
1.1 2002/12/30 20:32:30 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/30 20:32:30 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: BeanWithBeanInfoBean.java,v 1.1 2002/12/30 20:32:30 rdonkin Exp $
   */
  package org.apache.commons.betwixt.introspection;
  
  
  /** <p>An example of a bean that has a BeanInfo for use with introspection.</p>
    *
    * <p>
    * Three different pseudo-properties:
    * <ul>
    * <li><strong>Alpha</strong> is a standard property.
    * <li><strong>Beta</strong> follows standard naming conventions but
should be ignored. 
    * <li><strong>Gamma</strong> doesn't follow standard naming conventions
    * </ul>
    * </p>
    *
    * @author Robert Burrell Donkin
    * @version $Revision: 1.1 $
    */
  public class BeanWithBeanInfoBean {
      
      private String alpha;
      private String beta;
      private String gamma;
      
      public BeanWithBeanInfoBean() {}
      
      public BeanWithBeanInfoBean(String alpha, String beta) {
          setAlpha(alpha);
          setBeta(beta);
          gammaSetter(gamma);
      }
      
      public String getAlpha() {
          return alpha;
      }
      
      public void setAlpha(String alpha) {
          this.alpha = alpha;
      } 
      
      public String getBeta() {
          return beta;
      }	
      
      public void setBeta(String beta) {
          this.beta = beta;
      }
      
      public String gammaGetter() {
          return gamma;
      }
      
      public void gammaSetter(String gamma) {
          this.gamma = gamma;
      }	
  }
  
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/BeanWithBeanInfoBeanBeanInfo.java
  
  Index: BeanWithBeanInfoBeanBeanInfo.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/BeanWithBeanInfoBeanBeanInfo.java,v
1.1 2002/12/30 20:32:30 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/30 20:32:30 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: BeanWithBeanInfoBeanBeanInfo.java,v 1.1 2002/12/30 20:32:30 rdonkin Exp $
   */
  package org.apache.commons.betwixt.introspection;
  
  import java.beans.SimpleBeanInfo;
  import java.beans.PropertyDescriptor;
  import java.beans.IntrospectionException;
  
  
  /** <p>Bean info for exmaple bean used in introspection.</p>
    *
    * @author Robert Burrell Donkin
    * @version $Revision: 1.1 $
    */
  public class BeanWithBeanInfoBeanBeanInfo extends SimpleBeanInfo {
      
      public PropertyDescriptor[] getPropertyDescriptors() {
          PropertyDescriptor[] descriptors = new PropertyDescriptor[2];
          try {
          
              descriptors[0] 
                  = new PropertyDescriptor("alpha", BeanWithBeanInfoBean.class, "getAlpha",
"setAlpha");
              descriptors[1] 
                  = new PropertyDescriptor("gamma", BeanWithBeanInfoBean.class, "gammaGetter",
"gammaSetter");
                  
          } catch (IntrospectionException e) {
              throw new RuntimeException(e.getMessage());
          }
          return descriptors;
      }	
  }
  
  
  
  
  1.1                  jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java
  
  Index: TestXMLIntrospector.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/introspection/TestXMLIntrospector.java,v
1.1 2002/12/30 20:32:30 rdonkin Exp $
   * $Revision: 1.1 $
   * $Date: 2002/12/30 20:32:30 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   * 
   * $Id: TestXMLIntrospector.java,v 1.1 2002/12/30 20:32:30 rdonkin Exp $
   */
  package org.apache.commons.betwixt.introspection;
  
  import java.beans.Introspector;
  import java.beans.PropertyDescriptor;
  import java.beans.BeanInfo;
  
  import junit.framework.Test;
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.betwixt.registry.DefaultXMLBeanInfoRegistry;
  import org.apache.commons.betwixt.registry.NoCacheRegistry;
  
  import org.apache.commons.betwixt.XMLBeanInfo;
  import org.apache.commons.betwixt.XMLIntrospector;
  import org.apache.commons.betwixt.AbstractTestCase;
  import org.apache.commons.betwixt.ElementDescriptor;
  import org.apache.commons.betwixt.AttributeDescriptor;
  
  
  /** Test harness for the XMLIntrospector
    *
    * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
    * @version $Revision: 1.1 $
    */
  public class TestXMLIntrospector extends AbstractTestCase {
      
      public static void main( String[] args ) {
          TestRunner.run( suite() );
      }
      
      public static Test suite() {
          return new TestSuite(TestXMLIntrospector.class);
      }
          
      public TestXMLIntrospector(String testName) {
          super(testName);
      }
      
      public void testIntrospector() throws Exception {
          XMLIntrospector introspector = new XMLIntrospector();
          introspector.setAttributesForPrimitives(true);
          
          Object bean = createBean();
          
          XMLBeanInfo info = introspector.introspect( bean );
          
          assertTrue( "Found XMLBeanInfo", info != null );
          
          ElementDescriptor descriptor = info.getElementDescriptor();
          
          assertTrue( "Found root element descriptor", descriptor != null );
          
          AttributeDescriptor[] attributes = descriptor.getAttributeDescriptors();
          
          assertTrue( "Found attributes", attributes != null && attributes.length
> 0 );
          
          // test second introspection with caching on
          info = introspector.introspect( bean );
          
          assertTrue( "Found XMLBeanInfo", info != null );
          
          descriptor = info.getElementDescriptor();
          
          assertTrue( "Found root element descriptor", descriptor != null );
          
          attributes = descriptor.getAttributeDescriptors();
          
          assertTrue( "Found attributes", attributes != null && attributes.length
> 0 );
  
  
          // test introspection with caching off      
          //introspector.setCachingEnabled(false);  
          introspector.setRegistry(new NoCacheRegistry());
          info = introspector.introspect( bean );
          
          assertTrue( "Found XMLBeanInfo", info != null );
          
          descriptor = info.getElementDescriptor();
          
          assertTrue( "Found root element descriptor", descriptor != null );
          
          attributes = descriptor.getAttributeDescriptors();
          
          assertTrue( "Found attributes", attributes != null && attributes.length
> 0 );
  
  
          // test introspection after flushing cache
  //        introspector.setCachingEnabled(true);
          introspector.setRegistry(new DefaultXMLBeanInfoRegistry()); 
          //introspector.flushCache();
          info = introspector.introspect( bean );
          
          assertTrue( "Found XMLBeanInfo", info != null );
          
          descriptor = info.getElementDescriptor();
          
          assertTrue( "Found root element descriptor", descriptor != null );
          
          attributes = descriptor.getAttributeDescriptors();
          
          assertTrue( "Found attributes", attributes != null && attributes.length
> 0 );
  
      }
      
      public void testBeanWithBeanInfo() throws Exception {
          // let's check that bean info's ok
          BeanInfo bwbiBeanInfo = Introspector.getBeanInfo(BeanWithBeanInfoBean.class);
          
          PropertyDescriptor[] descriptors = bwbiBeanInfo.getPropertyDescriptors();
  
          assertEquals("Wrong number of properties", 2 , descriptors.length);
          
          // order of properties isn't guarenteed 
          if ("alpha".equals(descriptors[0].getName())) {
          
              assertEquals("Second property name", "gamma" , descriptors[1].getName());
              
          } else {
          
              assertEquals("First property name", "gamma" , descriptors[0].getName());
              assertEquals("Second property name", "alpha" , descriptors[1].getName());
          }
      }
  }
  
  
  
  

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