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