    1   package org.apache.commons.configuration;
    2
    3   /*
    4    * Copyright 2001-2004 The Apache Software Foundation.
    5    *
    6    * Licensed under the Apache License, Version 2.0 (the "License")
    7    * you may not use this file except in compliance with the License.
    8    * You may obtain a copy of the License at
    9    *
    10   *     http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18
    19  import junit.framework.TestCase;
    20
    21  /***
    22   * Test if non-string properties are handled correctly.
    23   *
    24   * @version $Id: BaseNonStringProperties.java,v 1.6 2004/08/16 22:16:31 henning Exp $
    25   */
    26  public abstract class BaseNonStringProperties extends TestCase
    27  {
    28
    29      protected NonStringTestHolder nonStringTestHolder = new NonStringTestHolder();
    30      public abstract void setUp() throws Exception;
    31
    32      public Configuration conf = null;
    33
    34      public void testBoolean() throws Exception
    35      {
    36          nonStringTestHolder.testBoolean();
    37      }
    38
    39      public void testBooleanDefaultValue() throws Exception
    40      {
    41          nonStringTestHolder.testBooleanDefaultValue();
    42      }
    43
    44      public void testBooleanArrayValue() throws Exception
    45      {
    46          boolean booleanValue = conf.getBoolean("test.boolean");
    47          assertEquals(true, booleanValue);
    48          assertEquals(2, conf.getList("test.boolean.array").size());
    49          assertEquals(2, conf.getVector("test.boolean.array").size());
    50      }
    51
    52      public void testByte() throws Exception
    53      {
    54          nonStringTestHolder.testByte();
    55      }
    56
    57      public void testByteArrayValue() throws Exception
    58      {
    59          byte testValue = 10;
    60          byte byteValue = conf.getByte("test.byte");
    61          assertEquals(testValue, byteValue);
    62          assertEquals(2, conf.getList("test.byte.array").size());
    63          assertEquals(2, conf.getVector("test.byte.array").size());
    64      }
    65
    66      public void testDouble() throws Exception
    67      {
    68          nonStringTestHolder.testDouble();
    69      }
    70
    71      public void testDoubleDefaultValue() throws Exception
    72      {
    73          nonStringTestHolder.testDoubleDefaultValue();
    74      }
    75
    76      public void testDoubleArrayValue() throws Exception
    77      {
    78          double testValue = 10.25;
    79          double doubleValue = conf.getDouble("test.double");
    80          assertEquals(testValue, doubleValue, 0.01);
    81          assertEquals(2, conf.getList("test.double.array").size());
    82          assertEquals(2, conf.getVector("test.double.array").size());
    83      }
    84
    85      public void testFloat() throws Exception
    86      {
    87          nonStringTestHolder.testFloat();
    88      }
    89
    90      public void testFloatDefaultValue() throws Exception
    91      {
    92          nonStringTestHolder.testFloatDefaultValue();
    93
    94      }
    95
    96      public void testFloatArrayValue() throws Exception
    97      {
    98          float testValue = (float) 20.25;
    99          float floatValue = conf.getFloat("test.float");
    100         assertEquals(testValue, floatValue, 0.01);
    101         assertEquals(2, conf.getList("test.float.array").size());
    102         assertEquals(2, conf.getVector("test.float.array").size());
    103     }
    104
    105     public void testInteger() throws Exception
    106     {
    107         nonStringTestHolder.testInteger();
    108     }
    109
    110     public void testIntegerDefaultValue() throws Exception
    111     {
    112         nonStringTestHolder.testIntegerDefaultValue();
    113     }
    114
    115     public void testIntegerArrayValue() throws Exception
    116     {
    117         int intValue = conf.getInt("test.integer");
    118         assertEquals(10, intValue);
    119         assertEquals(2, conf.getList("test.integer.array").size());
    120         assertEquals(2, conf.getVector("test.integer.array").size());
    121     }
    122
    123     public void testLong() throws Exception
    124     {
    125         nonStringTestHolder.testLong();
    126     }
    127     public void testLongDefaultValue() throws Exception
    128     {
    129         nonStringTestHolder.testLongDefaultValue();
    130     }
    131     public void testLongArrayValue() throws Exception
    132     {
    133         long longValue = conf.getLong("test.long");
    134         assertEquals(1000000, longValue);
    135         assertEquals(2, conf.getList("test.long.array").size());
    136         assertEquals(2, conf.getVector("test.long.array").size());
    137     }
    138
    139     public void testShort() throws Exception
    140     {
    141         nonStringTestHolder.testShort();
    142     }
    143
    144     public void testShortDefaultValue() throws Exception
    145     {
    146         nonStringTestHolder.testShortDefaultValue();
    147     }
    148     public void testShortArrayValue() throws Exception
    149     {
    150         short shortValue = conf.getShort("test.short");
    151         assertEquals(1, shortValue);
    152         assertEquals(2, conf.getList("test.short.array").size());
    153         assertEquals(2, conf.getVector("test.short.array").size());
    154     }
    155
    156     public void testListMissing() throws Exception
    157     {
    158         nonStringTestHolder.testListMissing();
    159     }
    160
    161     public void testVectorMissing() throws Exception
    162     {
    163         nonStringTestHolder.testVectorMissing();
    164     }
    165
    166     public void testSubset() throws Exception
    167     {
    168         nonStringTestHolder.testSubset();
    169     }
    170     public void testIsEmpty() throws Exception
    171     {
    172         nonStringTestHolder.testIsEmpty();
    173     }
    174 }