epugh       2003/03/11 09:40:20

  Modified:    configuration/src/test/org/apache/commons/configuration
                        TestCompositeConfiguration.java
                        TestNonStringProperties.java
  Added:       configuration/src/test/org/apache/commons/configuration
                        BaseNonStringProperties.java
                        TestCompositeConfigurationNonStringProperties.java
  Log:
  refactored testing of properties.  Also added more testing for 
CompositeConfiguration.
  
  Revision  Changes    Path
  1.2       +43 -21    
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java
  
  Index: TestCompositeConfiguration.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfiguration.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestCompositeConfiguration.java   28 Feb 2003 20:24:12 -0000      1.1
  +++ TestCompositeConfiguration.java   11 Mar 2003 17:40:20 -0000      1.2
  @@ -65,7 +65,8 @@
    * @author <a href="mailto:[EMAIL PROTECTED]">Eric Pugh</a>
    * @version $Id$
    */
  -public class TestCompositeConfiguration extends TestCase {
  +public class TestCompositeConfiguration extends TestCase
  +{
        protected BasePropertiesConfiguration conf1;
        protected BasePropertiesConfiguration conf2;
        protected DOM4JConfiguration dom4jConf;
  @@ -78,18 +79,21 @@
        private String testPropertiesXML =
                new File("conf/test.xml").getAbsolutePath();
   
  -     public TestCompositeConfiguration(String s) {
  +     public TestCompositeConfiguration(String s)
  +     {
                super(s);
        }
   
  -     protected void setUp() throws Exception {
  +     protected void setUp() throws Exception
  +     {
                cc = new CompositeConfiguration();
                conf1 = new PropertiesConfiguration(testProperties);
                conf2 = new PropertiesConfiguration(testProperties2);
                dom4jConf = new DOM4JConfiguration(new File(testPropertiesXML));
        }
   
  -     public void testAddRemoveConfigurations() throws Exception {
  +     public void testAddRemoveConfigurations() throws Exception
  +     {
   
                cc.addConfiguration(conf1);
                assertEquals(1, cc.getNumberOfConfigurations());
  @@ -103,7 +107,8 @@
                assertEquals(0, cc.getNumberOfConfigurations());
        }
   
  -     public void testGetProperty() throws Exception {
  +     public void testGetProperty() throws Exception
  +     {
                cc.addConfiguration(conf1);
                cc.addConfiguration(conf2);
                assertEquals(
  @@ -120,13 +125,17 @@
                        cc.getString("packages"));
        }
   
  -     public void testGetPropertyMissing() throws Exception {
  +     public void testGetPropertyMissing() throws Exception
  +     {
                cc.addConfiguration(conf1);
                cc.addConfiguration(conf2);
  -             try {
  +             try
  +             {
                        cc.getString("bogus.property");
                        fail("Should have thrown a java.util.NoSuchElementException");
  -             } catch (java.util.NoSuchElementException nsee) {
  +             }
  +             catch (java.util.NoSuchElementException nsee)
  +             {
   
                }
        }
  @@ -134,7 +143,8 @@
        /**
         * Tests <code>Vector</code> parsing.
         */
  -     public void testMultipleTypesOfConfigs() throws Exception {
  +     public void testMultipleTypesOfConfigs() throws Exception
  +     {
                cc.addConfiguration(conf1);
                cc.addConfiguration(dom4jConf);
                assertEquals(
  @@ -150,16 +160,28 @@
                        8,
                        cc.getInt("test.short"));
        }
  -     
  +
  +     /**
  +      * Tests <code>Vector</code> parsing.
  +      */
  +     public void testPropertyExistsInOnlyOneConfig() throws Exception
  +     {
  +             cc.addConfiguration(conf1);
  +             cc.addConfiguration(dom4jConf);
  +             assertEquals("value", cc.getString("element"));
  +     }
  +
        /**
  -              * Tests <code>Vector</code> parsing.
  -              */
  -             public void testPropertyExistsInOnlyOneConfig() throws Exception {
  -                     cc.addConfiguration(conf1);
  -                     cc.addConfiguration(dom4jConf);
  -                     assertEquals(
  -                             
  -                             "value",
  -                             cc.getString("element"));
  -             }       
  +      * Tests getting a default when the key doesn't exist
  +      */
  +     public void testDefaultValueWhenKeyMissing() throws Exception
  +     {
  +             cc.addConfiguration(conf1);
  +             cc.addConfiguration(dom4jConf);
  +             assertEquals("default", cc.getString("bogus","default"));
  +             assertTrue(1.4==cc.getDouble("bogus",1.4));
  +             assertTrue(1.4==cc.getDouble("bogus",1.4));
  +     }
  +
  +     
   }
  
  
  
  1.3       +7 -5      
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestNonStringProperties.java
  
  Index: TestNonStringProperties.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestNonStringProperties.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestNonStringProperties.java      7 Jan 2003 22:53:52 -0000       1.2
  +++ TestNonStringProperties.java      11 Mar 2003 17:40:20 -0000      1.3
  @@ -56,8 +56,6 @@
   
   import java.io.File;
   
  -import junit.framework.TestCase;
  -
   /**
    * test if non-string properties are handled correctly
    *
  @@ -65,7 +63,7 @@
    * @version $Id$
    */
   public class TestNonStringProperties
  -    extends TestCase
  +    extends BaseNonStringProperties
   {
       /** The File that we test with */
       private String testProperties = 
  @@ -78,7 +76,11 @@
         throws Exception
       {
           super(s);
  -        conf = new PropertiesConfiguration(testProperties);
  +       
  +    }
  +    
  +    public void setUp() throws Exception{
  +             conf = new PropertiesConfiguration(testProperties);
       }
   
       public void testBoolean()
  
  
  
  1.1                  
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/BaseNonStringProperties.java
  
  Index: BaseNonStringProperties.java
  ===================================================================
  package org.apache.commons.configuration;
  
  /* ====================================================================
   * 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 [EMAIL PROTECTED]
   *
   * 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/>.
   */
  
  import junit.framework.TestCase;
  
  /**
   * test if non-string properties are handled correctly
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
   * @version $Id: BaseNonStringProperties.java,v 1.1 2003/03/11 17:40:20 epugh Exp $
   */
  public abstract class BaseNonStringProperties
      extends TestCase
  {
      
      public abstract void setUp() throws Exception;
      
      public Configuration conf = null;
  
      public BaseNonStringProperties(String s)
        throws Exception
      {
          super(s);
          
      }
  
      public void testBoolean()
        throws Exception
      {
          boolean booleanValue = conf.getBoolean("test.boolean");
          assertEquals(true, booleanValue);
          assertEquals(1, conf.getVector("test.boolean").size());
      }
  
      public void testBooleanArrayValue()
        throws Exception
      {
          boolean booleanValue = conf.getBoolean("test.boolean.array");
          assertEquals(false, booleanValue);
          assertEquals(2, conf.getVector("test.boolean.array").size());
      }
  
      public void testByte()
        throws Exception
      {
          byte testValue = 10;
          byte byteValue = conf.getByte("test.byte");
          assertEquals(testValue, byteValue);
          assertEquals(1, conf.getVector("test.byte").size());
      }
  
      public void testByteArrayValue()
        throws Exception
      {
          byte testValue = 20;
          byte byteValue = conf.getByte("test.byte.array");
          assertEquals(testValue, byteValue);
          assertEquals(2, conf.getVector("test.byte.array").size());
      }
  
      public void testDouble()
        throws Exception
      {
          double testValue = 10.25;
          double doubleValue = conf.getDouble("test.double");
          assertEquals(testValue, doubleValue, 0.01);
          assertEquals(1, conf.getVector("test.double").size());
      }
  
      public void testDoubleArrayValue()
        throws Exception
      {
          double testValue = 20.35;
          double doubleValue = conf.getDouble("test.double.array");
          assertEquals(testValue, doubleValue, 0.01);
          assertEquals(2, conf.getVector("test.double.array").size());
      }
  
      public void testFloat()
        throws Exception
      {
          float testValue = (float) 20.25;
          float floatValue = conf.getFloat("test.float");
          assertEquals(testValue, floatValue, 0.01);
          assertEquals(1, conf.getVector("test.float").size());
      }
  
      public void testFloatArrayValue()
        throws Exception
      {
          float testValue = (float) 30.35;
          float floatValue = conf.getFloat("test.float.array");
          assertEquals(testValue, floatValue, 0.01);
          assertEquals(2, conf.getVector("test.float.array").size());
      }
  
      public void testInteger()
        throws Exception
      {
          int intValue = conf.getInt("test.integer");
          assertEquals(10, intValue);
          assertEquals(1, conf.getVector("test.integer").size());
      }
  
      public void testIntegerArrayValue()
        throws Exception
      {
          int intValue = conf.getInt("test.integer.array");
          assertEquals(20, intValue);
          assertEquals(2, conf.getVector("test.integer.array").size());
      }
  
      public void testLong()
        throws Exception
      {
          long longValue = conf.getLong("test.long");
          assertEquals(1000000, longValue);
          assertEquals(1, conf.getVector("test.long").size());
      }
  
      public void testLongArrayValue()
        throws Exception
      {
          long longValue = conf.getLong("test.long.array");
          assertEquals(2000000, longValue);
          assertEquals(2, conf.getVector("test.long.array").size());
      }
  
      public void testShort()
        throws Exception
      {
          short shortValue = conf.getShort("test.short");
          assertEquals(1, shortValue);
          assertEquals(1, conf.getVector("test.short").size());
      }
  
      public void testShortArrayValue()
        throws Exception
      {
          short shortValue = conf.getShort("test.short.array");
          assertEquals(2, shortValue);
          assertEquals(2, conf.getVector("test.short.array").size());
      }
  }
  
  
  
  1.1                  
jakarta-commons-sandbox/configuration/src/test/org/apache/commons/configuration/TestCompositeConfigurationNonStringProperties.java
  
  Index: TestCompositeConfigurationNonStringProperties.java
  ===================================================================
  package org.apache.commons.configuration;
  
  /* ====================================================================
   * 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 [EMAIL PROTECTED]
   *
   * 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/>.
   */
  
  import java.io.File;
  
  /**
   * test if non-string properties are handled correctly
   *
   * @author <a href="mailto:[EMAIL PROTECTED]">Henning P. Schmiedehausen</a>
   * @version $Id: TestCompositeConfigurationNonStringProperties.java,v 1.1 2003/03/11 
17:40:20 epugh Exp $
   */
  public class TestCompositeConfigurationNonStringProperties extends 
BaseNonStringProperties
  {
        /** The File that we test with */
        private String testProperties =
                new File("conf/test.properties").getAbsolutePath();
  
        
  
        public TestCompositeConfigurationNonStringProperties(String s)
                throws Exception
        {
                super(s);
  
        }
  
        public void setUp() throws Exception
        {
                PropertiesConfiguration pc =
                        new PropertiesConfiguration(testProperties);
                CompositeConfiguration cc = new CompositeConfiguration();
                cc.addConfiguration(pc);
                conf = (Configuration) cc;
        }
  
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to