1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.configuration;
19  
20  import java.awt.Color;
21  import java.math.BigDecimal;
22  import java.math.BigInteger;
23  import java.net.InetAddress;
24  import java.net.URL;
25  import java.text.DateFormat;
26  import java.text.SimpleDateFormat;
27  import java.util.ArrayList;
28  import java.util.Calendar;
29  import java.util.Date;
30  import java.util.Iterator;
31  import java.util.List;
32  import java.util.Locale;
33  import java.util.NoSuchElementException;
34  
35  import org.apache.commons.lang.SystemUtils;
36  
37  import junit.framework.TestCase;
38  import junitx.framework.ArrayAssert;
39  import junitx.framework.ListAssert;
40  
41  /***
42   * @author Emmanuel Bourg
43   * @version $Revision: 530207 $, $Date: 2007-04-19 01:53:50 +0200 (Do, 19 Apr 2007) $
44   */
45  public class TestDataConfiguration extends TestCase
46  {
47      private DataConfiguration conf;
48  
49      protected void setUp() throws Exception
50      {
51          conf = new DataConfiguration(new BaseConfiguration());
52  
53          // empty value
54          conf.addProperty("empty", "");
55  
56          // lists of boolean
57          conf.addProperty("boolean.list1", "true");
58          conf.addProperty("boolean.list1", "false");
59          conf.addProperty("boolean.list2", "true, false");
60          conf.addProperty("boolean.list3", Boolean.TRUE);
61          conf.addProperty("boolean.list3", Boolean.FALSE);
62          conf.addPropertyDirect("boolean.list4", new Boolean[] { Boolean.TRUE, Boolean.FALSE });
63          conf.addPropertyDirect("boolean.list5", new boolean[] { true, false });
64          List booleans = new ArrayList();
65          booleans.add(Boolean.TRUE);
66          booleans.add(Boolean.FALSE);
67          conf.addProperty("boolean.list6", booleans);
68          conf.addProperty("boolean.string", "true");
69          conf.addProperty("boolean.object", Boolean.TRUE);
70          conf.addProperty("boolean.list.interpolated", "${boolean.string},false");
71  
72          // lists of bytes
73          conf.addProperty("byte.list1", "1");
74          conf.addProperty("byte.list1", "2");
75          conf.addProperty("byte.list2", "1, 2");
76          conf.addProperty("byte.list3", new Byte("1"));
77          conf.addProperty("byte.list3", new Byte("2"));
78          conf.addPropertyDirect("byte.list4", new Byte[] { new Byte("1"), new Byte("2") });
79          conf.addPropertyDirect("byte.list5", new byte[] { 1, 2 });
80          List bytes = new ArrayList();
81          bytes.add(new Byte("1"));
82          bytes.add(new Byte("2"));
83          conf.addProperty("byte.list6", bytes);
84          conf.addProperty("byte.string", "1");
85          conf.addProperty("byte.object", new Byte("1"));
86          conf.addProperty("byte.list.interpolated", "${byte.string},2");
87  
88          // lists of shorts
89          conf.addProperty("short.list1", "1");
90          conf.addProperty("short.list1", "2");
91          conf.addProperty("short.list2", "1, 2");
92          conf.addProperty("short.list3", new Short("1"));
93          conf.addProperty("short.list3", new Short("2"));
94          conf.addPropertyDirect("short.list4", new Short[] { new Short("1"), new Short("2") });
95          conf.addPropertyDirect("short.list5", new short[] { 1, 2 });
96          List shorts = new ArrayList();
97          shorts.add(new Short("1"));
98          shorts.add(new Short("2"));
99          conf.addProperty("short.list6", shorts);
100         conf.addProperty("short.string", "1");
101         conf.addProperty("short.object", new Short("1"));
102         conf.addProperty("short.list.interpolated", "${short.string},2");
103 
104         // lists of integers
105         conf.addProperty("integer.list1", "1");
106         conf.addProperty("integer.list1", "2");
107         conf.addProperty("integer.list2", "1, 2");
108         conf.addProperty("integer.list3", new Integer("1"));
109         conf.addProperty("integer.list3", new Integer("2"));
110         conf.addPropertyDirect("integer.list4", new Integer[] { new Integer("1"), new Integer("2") });
111         conf.addPropertyDirect("integer.list5", new int[] { 1, 2 });
112         List integers = new ArrayList();
113         integers.add(new Integer("1"));
114         integers.add(new Integer("2"));
115         conf.addProperty("integer.list6", integers);
116         conf.addProperty("integer.string", "1");
117         conf.addProperty("integer.object", new Integer("1"));
118         conf.addProperty("integer.list.interpolated", "${integer.string},2");
119 
120         // lists of longs
121         conf.addProperty("long.list1", "1");
122         conf.addProperty("long.list1", "2");
123         conf.addProperty("long.list2", "1, 2");
124         conf.addProperty("long.list3", new Long("1"));
125         conf.addProperty("long.list3", new Long("2"));
126         conf.addPropertyDirect("long.list4", new Long[] { new Long("1"), new Long("2") });
127         conf.addPropertyDirect("long.list5", new long[] { 1, 2 });
128         List longs = new ArrayList();
129         longs.add(new Long("1"));
130         longs.add(new Long("2"));
131         conf.addProperty("long.list6", longs);
132         conf.addProperty("long.string", "1");
133         conf.addProperty("long.object", new Long("1"));
134         conf.addProperty("long.list.interpolated", "${long.string},2");
135 
136         // lists of floats
137         conf.addProperty("float.list1", "1");
138         conf.addProperty("float.list1", "2");
139         conf.addProperty("float.list2", "1, 2");
140         conf.addProperty("float.list3", new Float("1"));
141         conf.addProperty("float.list3", new Float("2"));
142         conf.addPropertyDirect("float.list4", new Float[] { new Float("1"), new Float("2") });
143         conf.addPropertyDirect("float.list5", new float[] { 1, 2 });
144         List floats = new ArrayList();
145         floats.add(new Float("1"));
146         floats.add(new Float("2"));
147         conf.addProperty("float.list6", floats);
148         conf.addProperty("float.string", "1");
149         conf.addProperty("float.object", new Float("1"));
150         conf.addProperty("float.list.interpolated", "${float.string},2");
151 
152         // lists of doubles
153         conf.addProperty("double.list1", "1");
154         conf.addProperty("double.list1", "2");
155         conf.addProperty("double.list2", "1, 2");
156         conf.addProperty("double.list3", new Double("1"));
157         conf.addProperty("double.list3", new Double("2"));
158         conf.addPropertyDirect("double.list4", new Double[] { new Double("1"), new Double("2") });
159         conf.addPropertyDirect("double.list5", new double[] { 1, 2 });
160         List doubles = new ArrayList();
161         doubles.add(new Double("1"));
162         doubles.add(new Double("2"));
163         conf.addProperty("double.list6", doubles);
164         conf.addProperty("double.string", "1");
165         conf.addProperty("double.object", new Double("1"));
166         conf.addProperty("double.list.interpolated", "${double.string},2");
167 
168         // lists of big integers
169         conf.addProperty("biginteger.list1", "1");
170         conf.addProperty("biginteger.list1", "2");
171         conf.addProperty("biginteger.list2", "1, 2");
172         conf.addProperty("biginteger.list3", new BigInteger("1"));
173         conf.addProperty("biginteger.list3", new BigInteger("2"));
174         conf.addPropertyDirect("biginteger.list4", new BigInteger[] { new BigInteger("1"), new BigInteger("2") });
175         List bigintegers = new ArrayList();
176         bigintegers.add(new BigInteger("1"));
177         bigintegers.add(new BigInteger("2"));
178         conf.addProperty("biginteger.list6", bigintegers);
179         conf.addProperty("biginteger.string", "1");
180         conf.addProperty("biginteger.object", new BigInteger("1"));
181         conf.addProperty("biginteger.list.interpolated", "${biginteger.string},2");
182 
183         // lists of big decimals
184         conf.addProperty("bigdecimal.list1", "1");
185         conf.addProperty("bigdecimal.list1", "2");
186         conf.addProperty("bigdecimal.list2", "1, 2");
187         conf.addProperty("bigdecimal.list3", new BigDecimal("1"));
188         conf.addProperty("bigdecimal.list3", new BigDecimal("2"));
189         conf.addPropertyDirect("bigdecimal.list4", new BigDecimal[] { new BigDecimal("1"), new BigDecimal("2") });
190         List bigdecimals = new ArrayList();
191         bigdecimals.add(new BigDecimal("1"));
192         bigdecimals.add(new BigDecimal("2"));
193         conf.addProperty("bigdecimal.list6", bigdecimals);
194         conf.addProperty("bigdecimal.string", "1");
195         conf.addProperty("bigdecimal.object", new BigDecimal("1"));
196         conf.addProperty("bigdecimal.list.interpolated", "${bigdecimal.string},2");
197 
198         // URLs
199         String url1 = "http://jakarta.apache.org";
200         String url2 = "http://www.apache.org";
201         conf.addProperty("url.string", url1);
202         conf.addProperty("url.string.interpolated", "${url.string}");
203         conf.addProperty("url.object", new URL(url1));
204         conf.addProperty("url.list1", url1);
205         conf.addProperty("url.list1", url2);
206         conf.addProperty("url.list2", url1 + ", " + url2);
207         conf.addProperty("url.list3", new URL(url1));
208         conf.addProperty("url.list3", new URL(url2));
209         conf.addPropertyDirect("url.list4", new URL[] { new URL(url1), new URL(url2) });
210         List urls = new ArrayList();
211         urls.add(new URL(url1));
212         urls.add(new URL(url2));
213         conf.addProperty("url.list6", urls);
214         conf.addProperty("url.list.interpolated", "${url.string}," + url2);
215 
216         // Locales
217         conf.addProperty("locale.string", "fr");
218         conf.addProperty("locale.string.interpolated", "${locale.string}");
219         conf.addProperty("locale.object", Locale.FRENCH);
220         conf.addProperty("locale.list1", "fr");
221         conf.addProperty("locale.list1", "de");
222         conf.addProperty("locale.list2", "fr, de");
223         conf.addProperty("locale.list3", Locale.FRENCH);
224         conf.addProperty("locale.list3", Locale.GERMAN);
225         conf.addPropertyDirect("locale.list4", new Locale[] { Locale.FRENCH, Locale.GERMAN });
226         List locales = new ArrayList();
227         locales.add(Locale.FRENCH);
228         locales.add(Locale.GERMAN);
229         conf.addProperty("locale.list6", locales);
230         conf.addProperty("locale.list.interpolated", "${locale.string},de");
231 
232         // Colors
233         String color1 = "FF0000";
234         String color2 = "0000FF";
235         conf.addProperty("color.string", color1);
236         conf.addProperty("color.string.interpolated", "${color.string}");
237         conf.addProperty("color.object", Color.red);
238         conf.addProperty("color.list1", color1);
239         conf.addProperty("color.list1", color2);
240         conf.addProperty("color.list2", color1 + ", " + color2);
241         conf.addProperty("color.list3", Color.red);
242         conf.addProperty("color.list3", Color.blue);
243         conf.addPropertyDirect("color.list4", new Color[] { Color.red, Color.blue });
244         List colors = new ArrayList();
245         colors.add(Color.red);
246         colors.add(Color.blue);
247         conf.addProperty("color.list6", colors);
248         conf.addProperty("color.list.interpolated", "${color.string}," + color2);
249 
250         // Dates & Calendars
251         String pattern = "yyyy-MM-dd";
252         DateFormat format = new SimpleDateFormat(pattern);
253         conf.setProperty(DataConfiguration.DATE_FORMAT_KEY, pattern);
254 
255         Date date1 = format.parse("2004-01-01");
256         Date date2 = format.parse("2004-12-31");
257         Calendar calendar1 = Calendar.getInstance();
258         calendar1.setTime(date1);
259         Calendar calendar2 = Calendar.getInstance();
260         calendar2.setTime(date2);
261 
262         conf.addProperty("date.string", "2004-01-01");
263         conf.addProperty("date.string.interpolated", "${date.string}");
264         conf.addProperty("date.object", date1);
265         conf.addProperty("date.list1", "2004-01-01");
266         conf.addProperty("date.list1", "2004-12-31");
267         conf.addProperty("date.list2", "2004-01-01, 2004-12-31");
268         conf.addProperty("date.list3", date1);
269         conf.addProperty("date.list3", date2);
270         conf.addPropertyDirect("date.list4", new Date[] { date1, date2 });
271         conf.addPropertyDirect("date.list5", new Calendar[] { calendar1, calendar2 });
272         List dates = new ArrayList();
273         dates.add(date1);
274         dates.add(date2);
275         conf.addProperty("date.list6", dates);
276         conf.addProperty("date.list.interpolated", "${date.string},2004-12-31");
277         conf.addPropertyDirect("date.list7", new String[] { "2004-01-01", "2004-12-31" });
278 
279         conf.addProperty("calendar.string", "2004-01-01");
280         conf.addProperty("calendar.string.interpolated", "${calendar.string}");
281         conf.addProperty("calendar.object", calendar1);
282         conf.addProperty("calendar.list1", "2004-01-01");
283         conf.addProperty("calendar.list1", "2004-12-31");
284         conf.addProperty("calendar.list2", "2004-01-01, 2004-12-31");
285         conf.addProperty("calendar.list3", calendar1);
286         conf.addProperty("calendar.list3", calendar2);
287         conf.addPropertyDirect("calendar.list4", new Calendar[] { calendar1, calendar2 });
288         conf.addPropertyDirect("calendar.list5", new Date[] { date1, date2 });
289         List calendars = new ArrayList();
290         calendars.add(date1);
291         calendars.add(date2);
292         conf.addProperty("calendar.list6", calendars);
293         conf.addProperty("calendar.list.interpolated", "${calendar.string},2004-12-31");
294         conf.addPropertyDirect("calendar.list7", new String[] { "2004-01-01", "2004-12-31" });
295 
296         // host address
297         conf.addProperty("ip.string", "127.0.0.1");
298         conf.addProperty("ip.string.interpolated", "${ip.string}");
299         conf.addProperty("ip.object", InetAddress.getByName("127.0.0.1"));
300 
301         // email address (tested on Java 1.4+)
302         if (SystemUtils.isJavaVersionAtLeast(1.4f))
303         {
304             conf.addProperty("email.string", "ebourg@apache.org");
305             conf.addProperty("email.string.interpolated", "${email.string}");
306             conf.addProperty("email.object", createInternetAddress("ebourg@apache.org"));
307         }
308     }
309 
310     public void testGetConfiguration()
311     {
312         Configuration baseconf = new BaseConfiguration();
313         DataConfiguration conf = new DataConfiguration(baseconf);
314 
315         assertEquals("base configuration", baseconf, conf.getConfiguration());
316     }
317 
318     public void testIsEmpty()
319     {
320         Configuration baseconf = new BaseConfiguration();
321         DataConfiguration conf = new DataConfiguration(baseconf);
322 
323         assertTrue("not empty", conf.isEmpty());
324 
325         baseconf.setProperty("foo", "bar");
326 
327         assertFalse("empty", conf.isEmpty());
328     }
329 
330     public void testContainsKey()
331     {
332         Configuration baseconf = new BaseConfiguration();
333         DataConfiguration conf = new DataConfiguration(baseconf);
334 
335         assertFalse(conf.containsKey("foo"));
336 
337         baseconf.setProperty("foo", "bar");
338 
339         assertTrue(conf.containsKey("foo"));
340     }
341 
342     public void testGetKeys()
343     {
344         Configuration baseconf = new BaseConfiguration();
345         DataConfiguration conf = new DataConfiguration(baseconf);
346 
347         baseconf.setProperty("foo", "bar");
348 
349         Iterator it = conf.getKeys();
350         assertTrue("the iterator is empty", it.hasNext());
351         assertEquals("unique key", "foo", it.next());
352         assertFalse("the iterator is not exhausted", it.hasNext());
353     }
354 
355     public void testGet()
356     {
357         try
358         {
359             conf.get(Boolean.class, "url.object", null);
360             fail("No ConversionException thrown despite the wrong type of the property");
361         }
362         catch (ConversionException e)
363         {
364             // expected
365         }
366 
367         assertNull("non null object for a missing key", conf.get(Object.class, "unknownkey"));
368 
369         conf.setThrowExceptionOnMissing(true);
370 
371         try
372         {
373             conf.get(Object.class, "unknownkey");
374             fail("NoSuchElementException should be thrown for missing properties");
375         }
376         catch (NoSuchElementException e)
377         {
378             // expected
379         }
380     }
381 
382     public void testGetArray()
383     {
384         try
385         {
386             conf.getArray(Boolean.class, "unknownkey", new URL[] {});
387             fail("No ConversionException thrown despite the wrong type of the default value");
388         }
389         catch (Exception e)
390         {
391             // expected
392         }
393     }
394 
395     public void testGetPrimitiveArray()
396     {
397         try
398         {
399             conf.getArray(Boolean.TYPE, "calendar.list4");
400             fail("No ConversionException thrown despite the wrong type of the property");
401         }
402         catch (ConversionException e)
403         {
404             // expected
405         }
406     }
407 
408     public void testGetBooleanArray()
409     {
410         // missing list
411         boolean[] defaultValue = new boolean[] { false, true };
412         ArrayAssert.assertEquals(defaultValue, conf.getBooleanArray("boolean.list", defaultValue));
413 
414         boolean[] expected = new boolean[] { true, false };
415 
416         // list of strings
417         ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list1"));
418 
419         // list of strings, comma separated
420         ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list2"));
421 
422         // list of Boolean objects
423         ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list3"));
424 
425         // array of Boolean objects
426         ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list4"));
427 
428         // array of boolean primitives
429         ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list5"));
430 
431         // list of Boolean objects
432         ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list6"));
433 
434         // list of interpolated values
435         ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list.interpolated"));
436 
437         // single boolean values
438         ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.string"));
439         ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.object"));
440 
441         // empty array
442         ArrayAssert.assertEquals(new boolean[] { }, conf.getBooleanArray("empty"));
443     }
444 
445     public void testGetBooleanList()
446     {
447         // missing list
448         ListAssert.assertEquals(null, conf.getBooleanList("boolean.list", null));
449 
450         List expected = new ArrayList();
451         expected.add(Boolean.TRUE);
452         expected.add(Boolean.FALSE);
453 
454         // list of strings
455         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list1"));
456 
457         // list of strings, comma separated
458         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list2"));
459 
460         // list of Boolean objects
461         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list3"));
462 
463         // array of Boolean objects
464         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list4"));
465 
466         // array of boolean primitives
467         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list5"));
468 
469         // list of Boolean objects
470         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list6"));
471 
472         // list of interpolated values
473         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list.interpolated"));
474 
475         // single boolean values
476         expected = new ArrayList();
477         expected.add(Boolean.TRUE);
478         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.string"));
479         ListAssert.assertEquals(expected, conf.getBooleanList("boolean.object"));
480 
481         // empty list
482         ListAssert.assertEquals(new ArrayList(), conf.getBooleanList("empty"));
483     }
484 
485     public void testGetByteArray()
486     {
487         // missing list
488         byte[] defaultValue = new byte[] { 1, 2};
489         ArrayAssert.assertEquals(defaultValue, conf.getByteArray("byte.list", defaultValue));
490 
491         byte[] expected = new byte[] { 1, 2 };
492 
493         // list of strings
494         ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list1"));
495 
496         // list of strings, comma separated
497         ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list2"));
498 
499         // list of Byte objects
500         ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list3"));
501 
502         // array of Byte objects
503         ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list4"));
504 
505         // array of byte primitives
506         ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list5"));
507 
508         // list of Byte objects
509         ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list6"));
510 
511         // list of interpolated values
512         ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list.interpolated"));
513 
514         // single byte values
515         ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.string"));
516         ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.object"));
517 
518         // empty array
519         ArrayAssert.assertEquals(new byte[] { }, conf.getByteArray("empty"));
520     }
521 
522     public void testGetByteList()
523     {
524         // missing list
525         ListAssert.assertEquals(null, conf.getByteList("byte.list", null));
526 
527         List expected = new ArrayList();
528         expected.add(new Byte("1"));
529         expected.add(new Byte("2"));
530 
531         // list of strings
532         ListAssert.assertEquals(expected, conf.getByteList("byte.list1"));
533 
534         // list of strings, comma separated
535         ListAssert.assertEquals(expected, conf.getByteList("byte.list2"));
536 
537         // list of Byte objects
538         ListAssert.assertEquals(expected, conf.getByteList("byte.list3"));
539 
540         // array of Byte objects
541         ListAssert.assertEquals(expected, conf.getByteList("byte.list4"));
542 
543         // array of byte primitives
544         ListAssert.assertEquals(expected, conf.getByteList("byte.list5"));
545 
546         // list of Byte objects
547         ListAssert.assertEquals(expected, conf.getByteList("byte.list6"));
548 
549         // list of interpolated values
550         ListAssert.assertEquals(expected, conf.getByteList("byte.list.interpolated"));
551 
552         // single byte values
553         expected = new ArrayList();
554         expected.add(new Byte("1"));
555         ListAssert.assertEquals(expected, conf.getByteList("byte.string"));
556         ListAssert.assertEquals(expected, conf.getByteList("byte.object"));
557 
558         // empty list
559         ListAssert.assertEquals(new ArrayList(), conf.getByteList("empty"));
560     }
561 
562     public void testGetShortArray()
563     {
564         // missing list
565         short[] defaultValue = new short[] { 2, 1};
566         ArrayAssert.assertEquals(defaultValue, conf.getShortArray("short.list", defaultValue));
567 
568         short[] expected = new short[] { 1, 2 };
569 
570         // list of strings
571         ArrayAssert.assertEquals(expected, conf.getShortArray("short.list1"));
572 
573         // list of strings, comma separated
574         ArrayAssert.assertEquals(expected, conf.getShortArray("short.list2"));
575 
576         // list of Byte objects
577         ArrayAssert.assertEquals(expected, conf.getShortArray("short.list3"));
578 
579         // array of Byte objects
580         ArrayAssert.assertEquals(expected, conf.getShortArray("short.list4"));
581 
582         // array of byte primitives
583         ArrayAssert.assertEquals(expected, conf.getShortArray("short.list5"));
584 
585         // list of Byte objects
586         ArrayAssert.assertEquals(expected, conf.getShortArray("short.list6"));
587 
588         // list of interpolated values
589         ArrayAssert.assertEquals(expected, conf.getShortArray("short.list.interpolated"));
590 
591         // single byte values
592         ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.string"));
593         ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.object"));
594 
595         // empty array
596         ArrayAssert.assertEquals(new short[] { }, conf.getShortArray("empty"));
597     }
598 
599     public void testGetShortList()
600     {
601         // missing list
602         ListAssert.assertEquals(null, conf.getShortList("short.list", null));
603 
604         List expected = new ArrayList();
605         expected.add(new Short("1"));
606         expected.add(new Short("2"));
607 
608         // list of strings
609         ListAssert.assertEquals(expected, conf.getShortList("short.list1"));
610 
611         // list of strings, comma separated
612         ListAssert.assertEquals(expected, conf.getShortList("short.list2"));
613 
614         // list of Short objects
615         ListAssert.assertEquals(expected, conf.getShortList("short.list3"));
616 
617         // array of Short objects
618         ListAssert.assertEquals(expected, conf.getShortList("short.list4"));
619 
620         // array of short primitives
621         ListAssert.assertEquals(expected, conf.getShortList("short.list5"));
622 
623         // list of Short objects
624         ListAssert.assertEquals(expected, conf.getShortList("short.list6"));
625 
626         // list of interpolated values
627         ListAssert.assertEquals(expected, conf.getShortList("short.list.interpolated"));
628 
629         // single short values
630         expected = new ArrayList();
631         expected.add(new Short("1"));
632         ListAssert.assertEquals(expected, conf.getShortList("short.string"));
633         ListAssert.assertEquals(expected, conf.getShortList("short.object"));
634 
635         // empty list
636         ListAssert.assertEquals(new ArrayList(), conf.getShortList("empty"));
637     }
638 
639     public void testGetIntegerArray()
640     {
641         // missing list
642         int[] defaultValue = new int[] { 2, 1};
643         ArrayAssert.assertEquals(defaultValue, conf.getIntArray("integer.list", defaultValue));
644 
645         int[] expected = new int[] { 1, 2 };
646 
647         // list of strings
648         ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list1"));
649 
650         // list of strings, comma separated
651         ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list2"));
652 
653         // list of Integer objects
654         ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list3"));
655 
656         // array of Integer objects
657         ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list4"));
658 
659         // array of int primitives
660         ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list5"));
661 
662         // list of Integer objects
663         ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list6"));
664 
665         // list of interpolated values
666         ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list.interpolated"));
667 
668         // single int values
669         ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.string"));
670         ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.object"));
671 
672         // empty array
673         ArrayAssert.assertEquals(new int[] { }, conf.getIntArray("empty"));
674     }
675 
676     public void testGetIntegerList()
677     {
678         // missing list
679         ListAssert.assertEquals(null, conf.getIntegerList("integer.list", null));
680 
681         List expected = new ArrayList();
682         expected.add(new Integer("1"));
683         expected.add(new Integer("2"));
684 
685         // list of strings
686         ListAssert.assertEquals(expected, conf.getIntegerList("integer.list1"));
687 
688         // list of strings, comma separated
689         ListAssert.assertEquals(expected, conf.getIntegerList("integer.list2"));
690 
691         // list of Integer objects
692         ListAssert.assertEquals(expected, conf.getIntegerList("integer.list3"));
693 
694         // array of Integer objects
695         ListAssert.assertEquals(expected, conf.getIntegerList("integer.list4"));
696 
697         // array of int primitives
698         ListAssert.assertEquals(expected, conf.getIntegerList("integer.list5"));
699 
700         // list of Integer objects
701         ListAssert.assertEquals(expected, conf.getIntegerList("integer.list6"));
702 
703         // list of interpolated values
704         ListAssert.assertEquals(expected, conf.getIntegerList("integer.list.interpolated"));
705 
706         // single int values
707         expected = new ArrayList();
708         expected.add(new Integer("1"));
709         ListAssert.assertEquals(expected, conf.getIntegerList("integer.string"));
710         ListAssert.assertEquals(expected, conf.getIntegerList("integer.object"));
711 
712         // empty list
713         ListAssert.assertEquals(new ArrayList(), conf.getIntegerList("empty"));
714     }
715 
716     public void testGetLongArray()
717     {
718         // missing list
719         long[] defaultValue = new long[] { 2, 1};
720         ArrayAssert.assertEquals(defaultValue, conf.getLongArray("long.list", defaultValue));
721 
722         long[] expected = new long[] { 1, 2 };
723 
724         // list of strings
725         ArrayAssert.assertEquals(expected, conf.getLongArray("long.list1"));
726 
727         // list of strings, comma separated
728         ArrayAssert.assertEquals(expected, conf.getLongArray("long.list2"));
729 
730         // list of Long objects
731         ArrayAssert.assertEquals(expected, conf.getLongArray("long.list3"));
732 
733         // array of Long objects
734         ArrayAssert.assertEquals(expected, conf.getLongArray("long.list4"));
735 
736         // array of long primitives
737         ArrayAssert.assertEquals(expected, conf.getLongArray("long.list5"));
738 
739         // list of Long objects
740         ArrayAssert.assertEquals(expected, conf.getLongArray("long.list6"));
741 
742         // list of interpolated values
743         ArrayAssert.assertEquals(expected, conf.getLongArray("long.list.interpolated"));
744 
745         // single long values
746         ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.string"));
747         ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.object"));
748 
749         // empty array
750         ArrayAssert.assertEquals(new long[] { }, conf.getLongArray("empty"));
751     }
752 
753     public void testGetLongList()
754     {
755         // missing list
756         ListAssert.assertEquals(null, conf.getLongList("long.list", null));
757 
758         List expected = new ArrayList();
759         expected.add(new Long("1"));
760         expected.add(new Long("2"));
761 
762         // list of strings
763         ListAssert.assertEquals(expected, conf.getLongList("long.list1"));
764 
765         // list of strings, comma separated
766         ListAssert.assertEquals(expected, conf.getLongList("long.list2"));
767 
768         // list of Long objects
769         ListAssert.assertEquals(expected, conf.getLongList("long.list3"));
770 
771         // array of Long objects
772         ListAssert.assertEquals(expected, conf.getLongList("long.list4"));
773 
774         // array of long primitives
775         ListAssert.assertEquals(expected, conf.getLongList("long.list5"));
776 
777         // list of Long objects
778         ListAssert.assertEquals(expected, conf.getLongList("long.list6"));
779 
780         // list of interpolated values
781         ListAssert.assertEquals(expected, conf.getLongList("long.list.interpolated"));
782 
783         // single long values
784         expected = new ArrayList();
785         expected.add(new Long("1"));
786         ListAssert.assertEquals(expected, conf.getLongList("long.string"));
787         ListAssert.assertEquals(expected, conf.getLongList("long.object"));
788 
789         // empty list
790         ListAssert.assertEquals(new ArrayList(), conf.getLongList("empty"));
791     }
792 
793     public void testGetFloatArray()
794     {
795         // missing list
796         float[] defaultValue = new float[] { 2, 1};
797         ArrayAssert.assertEquals(defaultValue, conf.getFloatArray("float.list", defaultValue), 0);
798 
799         float[] expected = new float[] { 1, 2 };
800 
801         // list of strings
802         ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list1"), 0);
803 
804         // list of strings, comma separated
805         ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list2"), 0);
806 
807         // list of Float objects
808         ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list3"), 0);
809 
810         // array of Float objects
811         ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list4"), 0);
812 
813         // array of float primitives
814         ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list5"), 0);
815 
816         // list of Float objects
817         ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list6"), 0);
818 
819         // list of interpolated values
820         ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list.interpolated"), 0);
821 
822         // single float values
823         ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.string"), 0);
824         ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.object"), 0);
825 
826         // empty array
827         ArrayAssert.assertEquals(new float[] { }, conf.getFloatArray("empty"), 0);
828     }
829 
830     public void testGetFloatList()
831     {
832         // missing list
833         ListAssert.assertEquals(null, conf.getFloatList("float.list", null));
834 
835         List expected = new ArrayList();
836         expected.add(new Float("1"));
837         expected.add(new Float("2"));
838 
839         // list of strings
840         ListAssert.assertEquals(expected, conf.getFloatList("float.list1"));
841 
842         // list of strings, comma separated
843         ListAssert.assertEquals(expected, conf.getFloatList("float.list2"));
844 
845         // list of Float objects
846         ListAssert.assertEquals(expected, conf.getFloatList("float.list3"));
847 
848         // array of Float objects
849         ListAssert.assertEquals(expected, conf.getFloatList("float.list4"));
850 
851         // array of float primitives
852         ListAssert.assertEquals(expected, conf.getFloatList("float.list5"));
853 
854         // list of Float objects
855         ListAssert.assertEquals(expected, conf.getFloatList("float.list6"));
856 
857         // list of interpolated values
858         ListAssert.assertEquals(expected, conf.getFloatList("float.list.interpolated"));
859 
860         // single float values
861         expected = new ArrayList();
862         expected.add(new Float("1"));
863         ListAssert.assertEquals(expected, conf.getFloatList("float.string"));
864         ListAssert.assertEquals(expected, conf.getFloatList("float.object"));
865 
866         // empty list
867         ListAssert.assertEquals(new ArrayList(), conf.getFloatList("empty"));
868     }
869 
870     public void testGetDoubleArray()
871     {
872         // missing list
873         double[] defaultValue = new double[] { 2, 1 };
874         ArrayAssert.assertEquals(defaultValue, conf.getDoubleArray("double.list", defaultValue), 0);
875 
876         double[] expected = new double[] { 1, 2 };
877 
878         // list of strings
879         ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list1"), 0);
880 
881         // list of strings, comma separated
882         ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list2"), 0);
883 
884         // list of Double objects
885         ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list3"), 0);
886 
887         // array of Double objects
888         ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list4"), 0);
889 
890         // array of double primitives
891         ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list5"), 0);
892 
893         // list of Double objects
894         ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list6"), 0);
895 
896         // list of interpolated values
897         ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list.interpolated"), 0);
898 
899         // single double values
900         ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.string"), 0);
901         ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.object"), 0);
902 
903         // empty array
904         ArrayAssert.assertEquals(new double[] { }, conf.getDoubleArray("empty"), 0);
905     }
906 
907     public void testGetDoubleList()
908     {
909         // missing list
910         ListAssert.assertEquals(null, conf.getDoubleList("double.list", null));
911 
912         List expected = new ArrayList();
913         expected.add(new Double("1"));
914         expected.add(new Double("2"));
915 
916         // list of strings
917         ListAssert.assertEquals(expected, conf.getDoubleList("double.list1"));
918 
919         // list of strings, comma separated
920         ListAssert.assertEquals(expected, conf.getDoubleList("double.list2"));
921 
922         // list of Double objects
923         ListAssert.assertEquals(expected, conf.getDoubleList("double.list3"));
924 
925         // array of Double objects
926         ListAssert.assertEquals(expected, conf.getDoubleList("double.list4"));
927 
928         // array of double primitives
929         ListAssert.assertEquals(expected, conf.getDoubleList("double.list5"));
930 
931         // list of Double objects
932         ListAssert.assertEquals(expected, conf.getDoubleList("double.list6"));
933 
934         // list of interpolated values
935         ListAssert.assertEquals(expected, conf.getDoubleList("double.list.interpolated"));
936 
937         // single double values
938         expected = new ArrayList();
939         expected.add(new Double("1"));
940         ListAssert.assertEquals(expected, conf.getDoubleList("double.string"));
941         ListAssert.assertEquals(expected, conf.getDoubleList("double.object"));
942 
943         // empty list
944         ListAssert.assertEquals(new ArrayList(), conf.getDoubleList("empty"));
945     }
946 
947     public void testGetBigIntegerArray()
948     {
949         // missing list
950         BigInteger[] defaultValue = new BigInteger[] { new BigInteger("2"), new BigInteger("1") };
951         ArrayAssert.assertEquals(defaultValue, conf.getBigIntegerArray("biginteger.list", defaultValue));
952 
953         BigInteger[] expected = new BigInteger[] { new BigInteger("1"), new BigInteger("2") };
954 
955         // list of strings
956         ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list1"));
957 
958         // list of strings, comma separated
959         ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list2"));
960 
961         // list of BigInteger objects
962         ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list3"));
963 
964         // array of BigInteger objects
965         ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list4"));
966 
967         // list of BigInteger objects
968         ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list6"));
969 
970         // list of interpolated values
971         ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list.interpolated"));
972 
973         // single BigInteger values
974         ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.string"));
975         ArrayAssert.assertEquals(new BigInteger[] { new BigInteger("1") }, conf.getBigIntegerArray("biginteger.object"));
976 
977         // empty array
978         ArrayAssert.assertEquals(new BigInteger[] { }, conf.getBigIntegerArray("empty"));
979     }
980 
981     public void testGetBigIntegerList()
982     {
983         // missing list
984         ListAssert.assertEquals(null, conf.getBigIntegerList("biginteger.list", null));
985 
986         List expected = new ArrayList();
987         expected.add(new BigInteger("1"));
988         expected.add(new BigInteger("2"));
989 
990         // list of strings
991         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list1"));
992 
993         // list of strings, comma separated
994         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list2"));
995 
996         // list of BigInteger objects
997         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list3"));
998 
999         // array of BigInteger objects
1000         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list4"));
1001 
1002         // list of BigInteger objects
1003         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list6"));
1004 
1005         // list of interpolated values
1006         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list.interpolated"));
1007 
1008         // single BigInteger values
1009         expected = new ArrayList();
1010         expected.add(new BigInteger("1"));
1011         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.string"));
1012         ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.object"));
1013 
1014         // empty list
1015         ListAssert.assertEquals(new ArrayList(), conf.getBigIntegerList("empty"));
1016     }
1017 
1018     public void testGetBigDecimalArray()
1019     {
1020         // missing list
1021         BigDecimal[] defaultValue = new BigDecimal[] { new BigDecimal("2"), new BigDecimal("1") };
1022         ArrayAssert.assertEquals(defaultValue, conf.getBigDecimalArray("bigdecimal.list", defaultValue));
1023 
1024         BigDecimal[] expected = new BigDecimal[] { new BigDecimal("1"), new BigDecimal("2") };
1025 
1026         // list of strings
1027         ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list1"));
1028 
1029         // list of strings, comma separated
1030         ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list2"));
1031 
1032         // list of BigDecimal objects
1033         ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list3"));
1034 
1035         // array of BigDecimal objects
1036         ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list4"));
1037 
1038         // list of BigDecimal objects
1039         ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list6"));
1040 
1041         // list of interpolated values
1042         ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list.interpolated"));
1043 
1044         // single BigDecimal values
1045         ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.string"));
1046         ArrayAssert.assertEquals(new BigDecimal[] { new BigDecimal("1") }, conf.getBigDecimalArray("bigdecimal.object"));
1047 
1048         // empty array
1049         ArrayAssert.assertEquals(new BigDecimal[] { }, conf.getBigDecimalArray("empty"));
1050     }
1051 
1052     public void testGetBigDecimalList()
1053     {
1054         // missing list
1055         ListAssert.assertEquals(null, conf.getBigDecimalList("bigdecimal.list", null));
1056 
1057         List expected = new ArrayList();
1058         expected.add(new BigDecimal("1"));
1059         expected.add(new BigDecimal("2"));
1060 
1061         // list of strings
1062         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list1"));
1063 
1064         // list of strings, comma separated
1065         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list2"));
1066 
1067         // list of BigDecimal objects
1068         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list3"));
1069 
1070         // array of BigDecimal objects
1071         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list4"));
1072 
1073         // list of BigDecimal objects
1074         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list6"));
1075 
1076         // list of interpolated values
1077         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list.interpolated"));
1078 
1079         // single BigDecimal values
1080         expected = new ArrayList();
1081         expected.add(new BigDecimal("1"));
1082         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.string"));
1083         ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.object"));
1084 
1085         // empty list
1086         ListAssert.assertEquals(new ArrayList(), conf.getBigDecimalList("empty"));
1087     }
1088 
1089     public void testGetURL() throws Exception
1090     {
1091         // missing URL
1092         URL defaultValue = new URL("http://www.google.com");
1093         assertEquals(defaultValue, conf.getURL("url", defaultValue));
1094 
1095         URL expected = new URL("http://jakarta.apache.org");
1096 
1097         // URL string
1098         assertEquals(expected, conf.getURL("url.string"));
1099 
1100         // URL object
1101         assertEquals(expected, conf.getURL("url.object"));
1102 
1103         // interpolated value
1104         assertEquals(expected, conf.getURL("url.string.interpolated"));
1105     }
1106 
1107     public void testGetURLArray() throws Exception
1108     {
1109         // missing list
1110         URL[] defaultValue = new URL[] { new URL("http://www.apache.org"), new URL("http://jakarta.apache.org") };
1111         ArrayAssert.assertEquals(defaultValue, conf.getURLArray("url.list", defaultValue));
1112 
1113         URL[] expected = new URL[] { new URL("http://jakarta.apache.org"), new URL("http://www.apache.org") };
1114 
1115         // list of strings
1116         ArrayAssert.assertEquals(expected, conf.getURLArray("url.list1"));
1117 
1118         // list of strings, comma separated
1119         ArrayAssert.assertEquals(expected, conf.getURLArray("url.list2"));
1120 
1121         // list of URL objects
1122         ArrayAssert.assertEquals(expected, conf.getURLArray("url.list3"));
1123 
1124         // array of URL objects
1125         ArrayAssert.assertEquals(expected, conf.getURLArray("url.list4"));
1126 
1127         // list of URL objects
1128         ArrayAssert.assertEquals(expected, conf.getURLArray("url.list6"));
1129 
1130         // list of interpolated values
1131         ArrayAssert.assertEquals(expected, conf.getURLArray("url.list.interpolated"));
1132 
1133         // single URL values
1134         ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.string"));
1135         ArrayAssert.assertEquals(new URL[] { new URL("http://jakarta.apache.org") }, conf.getURLArray("url.object"));
1136 
1137         // empty array
1138         ArrayAssert.assertEquals(new URL[] { }, conf.getURLArray("empty"));
1139     }
1140 
1141     public void testGetURLList() throws Exception
1142     {
1143         // missing list
1144         ListAssert.assertEquals(null, conf.getURLList("url.list", null));
1145 
1146         List expected = new ArrayList();
1147         expected.add(new URL("http://jakarta.apache.org"));
1148         expected.add(new URL("http://www.apache.org"));
1149 
1150         // list of strings
1151         ListAssert.assertEquals(expected, conf.getURLList("url.list1"));
1152 
1153         // list of strings, comma separated
1154         ListAssert.assertEquals(expected, conf.getURLList("url.list2"));
1155 
1156         // list of URL objects
1157         ListAssert.assertEquals(expected, conf.getURLList("url.list3"));
1158 
1159         // array of URL objects
1160         ListAssert.assertEquals(expected, conf.getURLList("url.list4"));
1161 
1162         // list of URL objects
1163         ListAssert.assertEquals(expected, conf.getURLList("url.list6"));
1164 
1165         // list of interpolated values
1166         ListAssert.assertEquals(expected, conf.getURLList("url.list.interpolated"));
1167 
1168         // single URL values
1169         expected = new ArrayList();
1170         expected.add(new URL("http://jakarta.apache.org"));
1171         ListAssert.assertEquals(expected, conf.getURLList("url.string"));
1172         ListAssert.assertEquals(expected, conf.getURLList("url.object"));
1173 
1174         // empty list
1175         ListAssert.assertEquals(new ArrayList(), conf.getURLList("empty"));
1176     }
1177 
1178     public void testGetLocale()
1179     {
1180         // language
1181         conf.setProperty("locale", "fr");
1182         assertEquals("language", new Locale("fr", ""), conf.getLocale("locale"));
1183 
1184         // language + variant
1185         conf.setProperty("locale", "fr__POSIX");
1186         assertEquals("language + variant", new Locale("fr", "", "POSIX"), conf.getLocale("locale"));
1187 
1188         // country
1189         conf.setProperty("locale", "_FR");
1190         assertEquals("country", new Locale("", "FR"), conf.getLocale("locale"));
1191 
1192         // country + variant
1193         conf.setProperty("locale", "_FR_WIN");
1194         assertEquals("country + variant", new Locale("", "FR", "WIN"), conf.getLocale("locale"));
1195 
1196         // language + country
1197         conf.setProperty("locale", "fr_FR");
1198         assertEquals("language + country", new Locale("fr", "FR"), conf.getLocale("locale"));
1199 
1200         // language + country + variant
1201         conf.setProperty("locale", "fr_FR_MAC");
1202         assertEquals("language + country + variant", new Locale("fr", "FR", "MAC"), conf.getLocale("locale"));
1203 
1204         // default value
1205         conf.setProperty("locale", "fr");
1206         assertEquals("Existing key with default value", Locale.FRENCH, conf.getLocale("locale", Locale.GERMAN));
1207         assertEquals("Missing key with default value", Locale.GERMAN, conf.getLocale("localeNotInConfig", Locale.GERMAN));
1208 
1209         // interpolated value
1210         assertEquals(Locale.FRENCH, conf.getLocale("locale.string.interpolated"));
1211     }
1212 
1213     public void testGetLocaleArray() throws Exception
1214     {
1215         // missing list
1216         Locale[] defaultValue = new Locale[] { Locale.GERMAN, Locale.FRENCH };
1217         ArrayAssert.assertEquals(defaultValue, conf.getLocaleArray("locale.list", defaultValue));
1218 
1219         Locale[] expected = new Locale[] { Locale.FRENCH, Locale.GERMAN };
1220 
1221         // list of strings
1222         ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list1"));
1223 
1224         // list of strings, comma separated
1225         ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list2"));
1226 
1227         // list of Locale objects
1228         ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list3"));
1229 
1230         // array of Locale objects
1231         ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list4"));
1232 
1233         // list of Locale objects
1234         ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list6"));
1235 
1236         // list of interpolated values
1237         ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list.interpolated"));
1238 
1239         // single Locale values
1240         ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.string"));
1241         ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.object"));
1242 
1243         // empty array
1244         ArrayAssert.assertEquals(new Locale[] { }, conf.getLocaleArray("empty"));
1245     }
1246 
1247     public void testGetLocaleList() throws Exception
1248     {
1249         // missing list
1250         ListAssert.assertEquals(null, conf.getLocaleList("locale.list", null));
1251 
1252         List expected = new ArrayList();
1253         expected.add(Locale.FRENCH);
1254         expected.add(Locale.GERMAN);
1255 
1256         // list of strings
1257         ListAssert.assertEquals(expected, conf.getLocaleList("locale.list1"));
1258 
1259         // list of strings, comma separated
1260         ListAssert.assertEquals(expected, conf.getLocaleList("locale.list2"));
1261 
1262         // list of Locale objects
1263         ListAssert.assertEquals(expected, conf.getLocaleList("locale.list3"));
1264 
1265         // array of Locale objects
1266         ListAssert.assertEquals(expected, conf.getLocaleList("locale.list4"));
1267 
1268         // list of Locale objects
1269         ListAssert.assertEquals(expected, conf.getLocaleList("locale.list6"));
1270 
1271         // list of interpolated values
1272         ListAssert.assertEquals(expected, conf.getLocaleList("locale.list.interpolated"));
1273 
1274         // single Locale values
1275         expected = new ArrayList();
1276         expected.add(Locale.FRENCH);
1277         ListAssert.assertEquals(expected, conf.getLocaleList("locale.string"));
1278         ListAssert.assertEquals(expected, conf.getLocaleList("locale.object"));
1279 
1280         // empty list
1281         ListAssert.assertEquals(new ArrayList(), conf.getLocaleList("empty"));
1282     }
1283 
1284     public void testGetColor()
1285     {
1286         // RRGGBB
1287         conf.setProperty("color", "FF0000");
1288         assertEquals("color", Color.red, conf.getColor("color"));
1289 
1290         // #RRGGBB
1291         conf.setProperty("color", "#00FF00");
1292         assertEquals("color", Color.green, conf.getColor("color"));
1293 
1294         // #RRGGBBAA
1295         conf.setProperty("color", "#01030507");
1296         Color color = conf.getColor("color");
1297         assertNotNull("null color", color);
1298         assertEquals("red",   1, color.getRed());
1299         assertEquals("green", 3, color.getGreen());
1300         assertEquals("blue",  5, color.getBlue());
1301         assertEquals("alpha", 7, color.getAlpha());
1302 
1303         // interpolated value
1304         assertEquals(Color.red, conf.getColor("color.string.interpolated"));
1305 
1306         // default value
1307         assertEquals(Color.cyan, conf.getColor("unknownkey", Color.cyan));
1308     }
1309 
1310     public void testGetColorArray() throws Exception
1311     {
1312         // missing list
1313         Color[] defaultValue = new Color[] { Color.red, Color.blue };
1314         ArrayAssert.assertEquals(defaultValue, conf.getColorArray("color.list", defaultValue));
1315 
1316         Color[] expected = new Color[] { Color.red, Color.blue };
1317 
1318         // list of strings
1319         ArrayAssert.assertEquals(expected, conf.getColorArray("color.list1"));
1320 
1321         // list of strings, comma separated
1322         ArrayAssert.assertEquals(expected, conf.getColorArray("color.list2"));
1323 
1324         // list of Color objects
1325         ArrayAssert.assertEquals(expected, conf.getColorArray("color.list3"));
1326 
1327         // array of Color objects
1328         ArrayAssert.assertEquals(expected, conf.getColorArray("color.list4"));
1329 
1330         // list of Color objects
1331         ArrayAssert.assertEquals(expected, conf.getColorArray("color.list6"));
1332 
1333         // list of interpolated values
1334         ArrayAssert.assertEquals(expected, conf.getColorArray("color.list.interpolated"));
1335 
1336         // single Color values
1337         ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.string"));
1338         ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.object"));
1339 
1340         // empty array
1341         ArrayAssert.assertEquals(new Color[] { }, conf.getColorArray("empty"));
1342     }
1343 
1344     public void testGetColorList() throws Exception
1345     {
1346         // missing list
1347         ListAssert.assertEquals(null, conf.getColorList("color.list", null));
1348 
1349         List expected = new ArrayList();
1350         expected.add(Color.red);
1351         expected.add(Color.blue);
1352 
1353         // list of strings
1354         ListAssert.assertEquals(expected, conf.getColorList("color.list1"));
1355 
1356         // list of strings, comma separated
1357         ListAssert.assertEquals(expected, conf.getColorList("color.list2"));
1358 
1359         // list of Color objects
1360         ListAssert.assertEquals(expected, conf.getColorList("color.list3"));
1361 
1362         // array of Color objects
1363         ListAssert.assertEquals(expected, conf.getColorList("color.list4"));
1364 
1365         // list of Color objects
1366         ListAssert.assertEquals(expected, conf.getColorList("color.list6"));
1367 
1368         // list of interpolated values
1369         ListAssert.assertEquals(expected, conf.getColorList("color.list.interpolated"));
1370 
1371         // single Color values
1372         expected = new ArrayList();
1373         expected.add(Color.red);
1374         ListAssert.assertEquals(expected, conf.getColorList("color.string"));
1375         ListAssert.assertEquals(expected, conf.getColorList("color.object"));
1376 
1377         // empty list
1378         ListAssert.assertEquals(new ArrayList(), conf.getColorList("empty"));
1379     }
1380 
1381     public void testGetDate() throws Exception
1382     {
1383         DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1384 
1385         // missing Date
1386         Date defaultValue = new Date();
1387         assertEquals(defaultValue, conf.getDate("date", defaultValue));
1388         assertNull("non null object for a missing key", conf.getDate("unknownkey", "yyyy-MM-dd"));
1389 
1390         conf.setThrowExceptionOnMissing(true);
1391 
1392         try
1393         {
1394             conf.getDate("unknownkey", "yyyy-MM-dd");
1395             fail("NoSuchElementException should be thrown for missing properties");
1396         }
1397         catch (NoSuchElementException e)
1398         {
1399             // expected
1400         }
1401 
1402         Date expected = format.parse("2004-01-01");
1403 
1404         // Date string
1405         assertEquals(expected, conf.getDate("date.string"));
1406         assertEquals(expected, conf.getDate("date.string", "yyyy-MM-dd"));
1407 
1408         // Date object
1409         assertEquals(expected, conf.getDate("date.object"));
1410 
1411         // Calendar object
1412         assertEquals(expected, conf.getDate("calendar.object"));
1413 
1414         // interpolated value
1415         assertEquals(expected, conf.getDate("date.string.interpolated"));
1416     }
1417 
1418     public void testGetDateArray() throws Exception
1419     {
1420         DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1421         Date date1 = format.parse("2004-01-01");
1422         Date date2 = format.parse("2004-12-31");
1423 
1424         // missing list
1425         Date[] defaultValue = new Date[] { date2, date1 };
1426         ArrayAssert.assertEquals(defaultValue, conf.getDateArray("date.list", defaultValue));
1427 
1428         Date[] expected = new Date[] { date1, date2 };
1429 
1430         // list of strings
1431         ArrayAssert.assertEquals(expected, conf.getDateArray("date.list1"));
1432 
1433         // list of strings, comma separated
1434         ArrayAssert.assertEquals(expected, conf.getDateArray("date.list2"));
1435 
1436         // list of Date objects
1437         ArrayAssert.assertEquals(expected, conf.getDateArray("date.list3"));
1438 
1439         // array of Date objects
1440         ArrayAssert.assertEquals(expected, conf.getDateArray("date.list4"));
1441 
1442         // list of Calendar objects
1443         ArrayAssert.assertEquals(expected, conf.getDateArray("date.list5"));
1444 
1445         // list of Date objects
1446         ArrayAssert.assertEquals(expected, conf.getDateArray("date.list6"));
1447 
1448         // list of interpolated values
1449         ArrayAssert.assertEquals(expected, conf.getDateArray("date.list.interpolated"));
1450 
1451         // single Date values
1452         ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.string"));
1453         ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.object"));
1454 
1455         // empty array
1456         ArrayAssert.assertEquals(new Date[] { }, conf.getDateArray("empty"));
1457     }
1458 
1459     public void testGetDateArrayWithFormat() throws Exception
1460     {
1461         DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
1462         Date date1 = format.parse("01/01/2004");
1463         Date date2 = format.parse("12/31/2004");
1464         Date[] expected = new Date[] { date1, date2 };
1465 
1466         conf.addProperty("date.format", "01/01/2004");
1467         conf.addProperty("date.format", "12/31/2004");
1468         ArrayAssert.assertEquals("Wrong dates with format", expected, conf.getDateArray("date.format", "MM/dd/yyyy"));
1469     }
1470 
1471     public void testGetDateList() throws Exception
1472     {
1473         DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1474         Date date1 = format.parse("2004-01-01");
1475         Date date2 = format.parse("2004-12-31");
1476 
1477         // missing list
1478         ListAssert.assertEquals(null, conf.getDateList("date.list", (List) null));
1479 
1480         List expected = new ArrayList();
1481         expected.add(date1);
1482         expected.add(date2);
1483 
1484         // list of strings
1485         ListAssert.assertEquals(expected, conf.getDateList("date.list1"));
1486         ListAssert.assertEquals(expected, conf.getList(Date.class, "date.list1"));
1487 
1488         // list of strings, comma separated
1489         ListAssert.assertEquals(expected, conf.getDateList("date.list2"));
1490 
1491         // list of Date objects
1492         ListAssert.assertEquals(expected, conf.getDateList("date.list3"));
1493 
1494         // array of Date objects
1495         ListAssert.assertEquals(expected, conf.getDateList("date.list4"));
1496 
1497         // list of Calendar objects
1498         ListAssert.assertEquals(expected, conf.getDateList("date.list5"));
1499 
1500         // list of Date objects
1501         ListAssert.assertEquals(expected, conf.getDateList("date.list6"));
1502 
1503         // array of strings
1504         ListAssert.assertEquals(expected, conf.getList(Date.class, "date.list7"));
1505 
1506         // list of interpolated values
1507         ListAssert.assertEquals(expected, conf.getDateList("date.list.interpolated"));
1508 
1509         // single Date values
1510         expected = new ArrayList();
1511         expected.add(date1);
1512         ListAssert.assertEquals(expected, conf.getDateList("date.string"));
1513         ListAssert.assertEquals(expected, conf.getDateList("date.object"));
1514 
1515         // empty list
1516         ListAssert.assertEquals(new ArrayList(), conf.getDateList("empty"));
1517     }
1518 
1519     public void testGetCalendar() throws Exception
1520     {
1521         DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1522 
1523         // missing Date
1524         Calendar defaultValue = Calendar.getInstance();
1525         defaultValue.setTime(new Date());
1526         assertEquals(defaultValue, conf.getCalendar("calendar", defaultValue));
1527         assertNull("non null object for a missing key", conf.getCalendar("unknownkey", "yyyy-MM-dd"));
1528 
1529         conf.setThrowExceptionOnMissing(true);
1530 
1531         try
1532         {
1533             conf.getCalendar("unknownkey", "yyyy-MM-dd");
1534             fail("NoSuchElementException should be thrown for missing properties");
1535         }
1536         catch (NoSuchElementException e)
1537         {
1538             // expected
1539         }
1540 
1541         Calendar expected = Calendar.getInstance();
1542         expected.setTime(format.parse("2004-01-01"));
1543 
1544         // Calendar string
1545         assertEquals(expected, conf.getCalendar("calendar.string"));
1546         assertEquals(expected, conf.getCalendar("calendar.string",  "yyyy-MM-dd"));
1547 
1548         // Calendar object
1549         assertEquals(expected, conf.getCalendar("calendar.object"));
1550 
1551         // Date object
1552         assertEquals(expected, conf.getCalendar("date.object"));
1553 
1554         // interpolated value
1555         assertEquals(expected, conf.getCalendar("calendar.string.interpolated"));
1556     }
1557 
1558     public void testGetCalendarArray() throws Exception
1559     {
1560         DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1561         Date date1 = format.parse("2004-01-01");
1562         Date date2 = format.parse("2004-12-31");
1563         Calendar calendar1 = Calendar.getInstance();
1564         calendar1.setTime(date1);
1565         Calendar calendar2 = Calendar.getInstance();
1566         calendar2.setTime(date2);
1567 
1568         // missing list
1569         Calendar[] defaultValue = new Calendar[] { calendar2, calendar1 };
1570         ArrayAssert.assertEquals(defaultValue, conf.getCalendarArray("calendar.list", defaultValue));
1571 
1572         Calendar[] expected = new Calendar[] { calendar1, calendar2 };
1573 
1574         // list of strings
1575         ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list1"));
1576 
1577         // list of strings, comma separated
1578         ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list2"));
1579 
1580         // list of Calendar objects
1581         ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list3"));
1582 
1583         // array of Calendar objects
1584         ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list4"));
1585 
1586         // list of Date objects
1587         ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list5"));
1588 
1589         // list of Calendar objects
1590         ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list6"));
1591 
1592         // list of interpolated values
1593         ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list.interpolated"));
1594 
1595         // single Calendar values
1596         ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.string"));
1597         ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.object"));
1598 
1599         // empty array
1600         ArrayAssert.assertEquals(new Calendar[] { }, conf.getCalendarArray("empty"));
1601     }
1602 
1603     public void testGetCalendarArrayWithFormat() throws Exception
1604     {
1605         DateFormat format = new SimpleDateFormat("MM/dd/yyyy");
1606         Date date1 = format.parse("01/01/2004");
1607         Date date2 = format.parse("12/31/2004");
1608 
1609         Calendar calendar1 = Calendar.getInstance();
1610         calendar1.setTime(date1);
1611         Calendar calendar2 = Calendar.getInstance();
1612         calendar2.setTime(date2);
1613         Calendar[] expected = new Calendar[] { calendar1, calendar2 };
1614 
1615         conf.addProperty("calendar.format", "01/01/2004");
1616         conf.addProperty("calendar.format", "12/31/2004");
1617         ArrayAssert.assertEquals("Wrong calendars with format", expected, conf.getCalendarArray("calendar.format", "MM/dd/yyyy"));
1618     }
1619 
1620     public void testGetCalendarList() throws Exception
1621     {
1622         DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
1623         Date date1 = format.parse("2004-01-01");
1624         Date date2 = format.parse("2004-12-31");
1625         Calendar calendar1 = Calendar.getInstance();
1626         calendar1.setTime(date1);
1627         Calendar calendar2 = Calendar.getInstance();
1628         calendar2.setTime(date2);
1629 
1630         // missing list
1631         ListAssert.assertEquals(null, conf.getCalendarList("calendar.list", (List) null));
1632 
1633         List expected = new ArrayList();
1634         expected.add(calendar1);
1635         expected.add(calendar2);
1636 
1637         // list of strings
1638         ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list1"));
1639         ListAssert.assertEquals(expected, conf.getList(Calendar.class, "calendar.list1"));
1640 
1641         // list of strings, comma separated
1642         ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list2"));
1643 
1644         // list of Calendar objects
1645         ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list3"));
1646 
1647         // array of Calendar objects
1648         ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list4"));
1649 
1650         // list of Date objects
1651         ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list5"));
1652 
1653         // list of Calendar objects
1654         ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list6"));
1655 
1656         // array of strings
1657         ListAssert.assertEquals(expected, conf.getList(Calendar.class, "calendar.list7"));
1658 
1659         // list of interpolated values
1660         ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list.interpolated"));
1661 
1662         // single Calendar values
1663         expected = new ArrayList();
1664         expected.add(calendar1);
1665         ListAssert.assertEquals(expected, conf.getCalendarList("date.string"));
1666         ListAssert.assertEquals(expected, conf.getCalendarList("date.object"));
1667 
1668         // empty list
1669         ListAssert.assertEquals(new ArrayList(), conf.getCalendarList("empty"));
1670     }
1671 
1672     public void testGetInetAddress() throws Exception
1673     {
1674         InetAddress expected = InetAddress.getByName("127.0.0.1");
1675 
1676         // address as string
1677         assertEquals(expected, conf.get(InetAddress.class, "ip.string"));
1678 
1679         // address object
1680         assertEquals(expected, conf.get(InetAddress.class, "ip.object"));
1681 
1682         // interpolated value
1683         assertEquals(expected, conf.get(InetAddress.class, "ip.string.interpolated"));
1684 
1685         conf.setProperty("ip.unknownhost", "foo");
1686         try
1687         {
1688             conf.get(InetAddress.class, "ip.unknownhost");
1689             fail("ConversionException should be thrown for unknown hosts");
1690         }
1691         catch (ConversionException e)
1692         {
1693             // expected
1694         }
1695     }
1696 
1697     public void testGetInternetAddress() throws Exception
1698     {
1699         if (!SystemUtils.isJavaVersionAtLeast(1.4f))
1700         {
1701             // skip the test on Java 1.3
1702             return;
1703         }
1704 
1705         Object expected = createInternetAddress("ebourg@apache.org");
1706 
1707         // address as string
1708         assertEquals(expected, conf.get(expected.getClass(), "email.string"));
1709 
1710         // address object
1711         assertEquals(expected, conf.get(expected.getClass(), "email.object"));
1712 
1713         // interpolated value
1714         assertEquals(expected, conf.get(expected.getClass(), "email.string.interpolated"));
1715 
1716         conf.setProperty("email.invalid", "ebourg@apache@org");
1717         try
1718         {
1719             conf.get(expected.getClass(), "email.invalid");
1720             fail("ConversionException should be thrown for invalid emails");
1721         }
1722         catch (ConversionException e)
1723         {
1724             // expected
1725         }
1726     }
1727 
1728     /***
1729      * Create an instance of InternetAddress. This trick is necessary to
1730      * compile and run the test with Java 1.3 and the javamail-1.4 which
1731      * is not compatible with Java 1.3
1732      */
1733     private Object createInternetAddress(String email) throws Exception
1734     {
1735         Class cls = Class.forName("javax.mail.internet.InternetAddress");
1736         return cls.getConstructor(new Class[]{String.class}).newInstance(new Object[]{email});
1737     }
1738 
1739     public void testConversionException() throws Exception
1740     {
1741         conf.addProperty("key1", new Object());
1742         conf.addProperty("key2", "xxxxxx");
1743 
1744         try
1745         {
1746             conf.getBooleanArray("key1");
1747             fail("getBooleanArray didn't throw a ConversionException");
1748         }
1749         catch (ConversionException e)
1750         {
1751             // expected
1752         }
1753 
1754         try
1755         {
1756             conf.getBooleanArray("key2");
1757             fail("getBooleanArray didn't throw a ConversionException");
1758         }
1759         catch (ConversionException e)
1760         {
1761             // expected
1762         }
1763 
1764         try
1765         {
1766             conf.getBooleanList("key1");
1767             fail("getBooleanList didn't throw a ConversionException");
1768         }
1769         catch (ConversionException e)
1770         {
1771             // expected
1772         }
1773 
1774         try
1775         {
1776             conf.getBooleanList("key2");
1777             fail("getBooleanList didn't throw a ConversionException");
1778         }
1779         catch (ConversionException e)
1780         {
1781             // expected
1782         }
1783 
1784         try
1785         {
1786             conf.getByteArray("key1");
1787             fail("getByteArray didn't throw a ConversionException");
1788         }
1789         catch (ConversionException e)
1790         {
1791             // expected
1792         }
1793 
1794         try
1795         {
1796             conf.getByteArray("key2");
1797             fail("getByteArray didn't throw a ConversionException");
1798         }
1799         catch (ConversionException e)
1800         {
1801             // expected
1802         }
1803 
1804         try
1805         {
1806             conf.getByteList("key1");
1807             fail("getByteList didn't throw a ConversionException");
1808         }
1809         catch (ConversionException e)
1810         {
1811             // expected
1812         }
1813 
1814         try
1815         {
1816             conf.getByteList("key2");
1817             fail("getByteList didn't throw a ConversionException");
1818         }
1819         catch (ConversionException e)
1820         {
1821             // expected
1822         }
1823 
1824         try
1825         {
1826             conf.getShortArray("key1");
1827             fail("getShortArray didn't throw a ConversionException");
1828         }
1829         catch (ConversionException e)
1830         {
1831             // expected
1832         }
1833 
1834         try
1835         {
1836             conf.getShortArray("key2");
1837             fail("getShortArray didn't throw a ConversionException");
1838         }
1839         catch (ConversionException e)
1840         {
1841             // expected
1842         }
1843 
1844         try
1845         {
1846             conf.getShortList("key1");
1847             fail("getShortList didn't throw a ConversionException");
1848         }
1849         catch (ConversionException e)
1850         {
1851             // expected
1852         }
1853 
1854         try
1855         {
1856             conf.getShortList("key2");
1857             fail("getShortList didn't throw a ConversionException");
1858         }
1859         catch (ConversionException e)
1860         {
1861             // expected
1862         }
1863 
1864         try
1865         {
1866             conf.getIntArray("key1");
1867             fail("getIntArray didn't throw a ConversionException");
1868         }
1869         catch (ConversionException e)
1870         {
1871             // expected
1872         }
1873 
1874         try
1875         {
1876             conf.getIntArray("key2");
1877             fail("getIntArray didn't throw a ConversionException");
1878         }
1879         catch (ConversionException e)
1880         {
1881             // expected
1882         }
1883 
1884         try
1885         {
1886             conf.getIntegerList("key1");
1887             fail("getIntegerList didn't throw a ConversionException");
1888         }
1889         catch (ConversionException e)
1890         {
1891             // expected
1892         }
1893 
1894         try
1895         {
1896             conf.getIntegerList("key2");
1897             fail("getIntegerList didn't throw a ConversionException");
1898         }
1899         catch (ConversionException e)
1900         {
1901             // expected
1902         }
1903 
1904         try
1905         {
1906             conf.getLongArray("key1");
1907             fail("getLongArray didn't throw a ConversionException");
1908         }
1909         catch (ConversionException e)
1910         {
1911             // expected
1912         }
1913 
1914         try
1915         {
1916             conf.getLongArray("key2");
1917             fail("getLongArray didn't throw a ConversionException");
1918         }
1919         catch (ConversionException e)
1920         {
1921             // expected
1922         }
1923 
1924         try
1925         {
1926             conf.getLongList("key1");
1927             fail("getLongList didn't throw a ConversionException");
1928         }
1929         catch (ConversionException e)
1930         {
1931             // expected
1932         }
1933 
1934         try
1935         {
1936             conf.getLongList("key2");
1937             fail("getLongList didn't throw a ConversionException");
1938         }
1939         catch (ConversionException e)
1940         {
1941             // expected
1942         }
1943 
1944         try
1945         {
1946             conf.getFloatArray("key1");
1947             fail("getFloatArray didn't throw a ConversionException");
1948         }
1949         catch (ConversionException e)
1950         {
1951             // expected
1952         }
1953 
1954         try
1955         {
1956             conf.getFloatArray("key2");
1957             fail("getFloatArray didn't throw a ConversionException");
1958         }
1959         catch (ConversionException e)
1960         {
1961             // expected
1962         }
1963 
1964         try
1965         {
1966             conf.getFloatList("key1");
1967             fail("getFloatList didn't throw a ConversionException");
1968         }
1969         catch (ConversionException e)
1970         {
1971             // expected
1972         }
1973 
1974         try
1975         {
1976             conf.getFloatList("key2");
1977             fail("getFloatList didn't throw a ConversionException");
1978         }
1979         catch (ConversionException e)
1980         {
1981             // expected
1982         }
1983 
1984         try
1985         {
1986             conf.getDoubleArray("key1");
1987             fail("getDoubleArray didn't throw a ConversionException");
1988         }
1989         catch (ConversionException e)
1990         {
1991             // expected
1992         }
1993 
1994         try
1995         {
1996             conf.getDoubleArray("key2");
1997             fail("getDoubleArray didn't throw a ConversionException");
1998         }
1999         catch (ConversionException e)
2000         {
2001             // expected
2002         }
2003 
2004         try
2005         {
2006             conf.getDoubleList("key1");
2007             fail("getDoubleList didn't throw a ConversionException");
2008         }
2009         catch (ConversionException e)
2010         {
2011             // expected
2012         }
2013 
2014         try
2015         {
2016             conf.getDoubleList("key2");
2017             fail("getDoubleList didn't throw a ConversionException");
2018         }
2019         catch (ConversionException e)
2020         {
2021             // expected
2022         }
2023 
2024         try
2025         {
2026             conf.getBigIntegerArray("key1");
2027             fail("getBigIntegerArray didn't throw a ConversionException");
2028         }
2029         catch (ConversionException e)
2030         {
2031             // expected
2032         }
2033 
2034         try
2035         {
2036             conf.getBigIntegerArray("key2");
2037             fail("getBigIntegerArray didn't throw a ConversionException");
2038         }
2039         catch (ConversionException e)
2040         {
2041             // expected
2042         }
2043 
2044         try
2045         {
2046             conf.getBigIntegerList("key1");
2047             fail("getBigIntegerList didn't throw a ConversionException");
2048         }
2049         catch (ConversionException e)
2050         {
2051             // expected
2052         }
2053 
2054         try
2055         {
2056             conf.getBigIntegerList("key2");
2057             fail("getBigIntegerList didn't throw a ConversionException");
2058         }
2059         catch (ConversionException e)
2060         {
2061             // expected
2062         }
2063 
2064         try
2065         {
2066             conf.getBigDecimalArray("key1");
2067             fail("getBigDecimalArray didn't throw a ConversionException");
2068         }
2069         catch (ConversionException e)
2070         {
2071             // expected
2072         }
2073 
2074         try
2075         {
2076             conf.getBigDecimalArray("key2");
2077             fail("getBigDecimalArray didn't throw a ConversionException");
2078         }
2079         catch (ConversionException e)
2080         {
2081             // expected
2082         }
2083 
2084         try
2085         {
2086             conf.getBigDecimalList("key1");
2087             fail("getBigDecimalList didn't throw a ConversionException");
2088         }
2089         catch (ConversionException e)
2090         {
2091             // expected
2092         }
2093 
2094         try
2095         {
2096             conf.getBigDecimalList("key2");
2097             fail("getBigDecimalList didn't throw a ConversionException");
2098         }
2099         catch (ConversionException e)
2100         {
2101             // expected
2102         }
2103 
2104         try
2105         {
2106             conf.getURLArray("key1");
2107             fail("getURLArray didn't throw a ConversionException");
2108         }
2109         catch (ConversionException e)
2110         {
2111             // expected
2112         }
2113 
2114         try
2115         {
2116             conf.getURLArray("key2");
2117             fail("getURLArray didn't throw a ConversionException");
2118         }
2119         catch (ConversionException e)
2120         {
2121             // expected
2122         }
2123 
2124         try
2125         {
2126             conf.getURLList("key1");
2127             fail("getURLList didn't throw a ConversionException");
2128         }
2129         catch (ConversionException e)
2130         {
2131             // expected
2132         }
2133 
2134         try
2135         {
2136             conf.getURLList("key2");
2137             fail("getURLList didn't throw a ConversionException");
2138         }
2139         catch (ConversionException e)
2140         {
2141             // expected
2142         }
2143 
2144         try
2145         {
2146             conf.getLocaleArray("key1");
2147             fail("getLocaleArray didn't throw a ConversionException");
2148         }
2149         catch (ConversionException e)
2150         {
2151             // expected
2152         }
2153 
2154         try
2155         {
2156             conf.getLocaleArray("key2");
2157             fail("getLocaleArray didn't throw a ConversionException");
2158         }
2159         catch (ConversionException e)
2160         {
2161             // expected
2162         }
2163 
2164         try
2165         {
2166             conf.getLocaleList("key1");
2167             fail("getLocaleList didn't throw a ConversionException");
2168         }
2169         catch (ConversionException e)
2170         {
2171             // expected
2172         }
2173 
2174         try
2175         {
2176             conf.getLocaleList("key2");
2177             fail("getLocaleList didn't throw a ConversionException");
2178         }
2179         catch (ConversionException e)
2180         {
2181             // expected
2182         }
2183 
2184         try
2185         {
2186             conf.getColorArray("key1");
2187             fail("getColorArray didn't throw a ConversionException");
2188         }
2189         catch (ConversionException e)
2190         {
2191             // expected
2192         }
2193 
2194         try
2195         {
2196             conf.getColorArray("key2");
2197             fail("getColorArray didn't throw a ConversionException");
2198         }
2199         catch (ConversionException e)
2200         {
2201             // expected
2202         }
2203 
2204         try
2205         {
2206             conf.getColorList("key1");
2207             fail("getColorList didn't throw a ConversionException");
2208         }
2209         catch (ConversionException e)
2210         {
2211             // expected
2212         }
2213 
2214         try
2215         {
2216             conf.getColorList("key2");
2217             fail("getColorList didn't throw a ConversionException");
2218         }
2219         catch (ConversionException e)
2220         {
2221             // expected
2222         }
2223 
2224         try
2225         {
2226             conf.getDateArray("key1");
2227             fail("getDateArray didn't throw a ConversionException");
2228         }
2229         catch (ConversionException e)
2230         {
2231             // expected
2232         }
2233 
2234         try
2235         {
2236             conf.getDate("key1", "yyyy-MM-dd");
2237             fail("getDate didn't throw a ConversionException");
2238         }
2239         catch (ConversionException e)
2240         {
2241             // expected
2242         }
2243 
2244         try
2245         {
2246             conf.getDate("key2", "yyyy-MM-dd");
2247             fail("getDate didn't throw a ConversionException");
2248         }
2249         catch (ConversionException e)
2250         {
2251             // expected
2252         }
2253 
2254         try
2255         {
2256             conf.getDateArray("key2");
2257             fail("getDateArray didn't throw a ConversionException");
2258         }
2259         catch (ConversionException e)
2260         {
2261             // expected
2262         }
2263 
2264         try
2265         {
2266             conf.getDateList("key1");
2267             fail("getDateList didn't throw a ConversionException");
2268         }
2269         catch (ConversionException e)
2270         {
2271             // expected
2272         }
2273 
2274         try
2275         {
2276             conf.getDateList("key2");
2277             fail("getDateList didn't throw a ConversionException");
2278         }
2279         catch (ConversionException e)
2280         {
2281             // expected
2282         }
2283 
2284         try
2285         {
2286             conf.getCalendar("key1", "yyyy-MM-dd");
2287             fail("getCalendar didn't throw a ConversionException");
2288         }
2289         catch (ConversionException e)
2290         {
2291             // expected
2292         }
2293 
2294         try
2295         {
2296             conf.getCalendar("key2","yyyy-MM-dd");
2297             fail("getCalendar didn't throw a ConversionException");
2298         }
2299         catch (ConversionException e)
2300         {
2301             // expected
2302         }
2303 
2304         try
2305         {
2306             conf.getCalendarArray("key1");
2307             fail("getCalendarArray didn't throw a ConversionException");
2308         }
2309         catch (ConversionException e)
2310         {
2311             // expected
2312         }
2313 
2314         try
2315         {
2316             conf.getCalendarArray("key2");
2317             fail("getCalendarArray didn't throw a ConversionException");
2318         }
2319         catch (ConversionException e)
2320         {
2321             // expected
2322         }
2323 
2324         try
2325         {
2326             conf.getCalendarList("key1");
2327             fail("getCalendarList didn't throw a ConversionException");
2328         }
2329         catch (ConversionException e)
2330         {
2331             // expected
2332         }
2333 
2334         try
2335         {
2336             conf.getCalendarList("key2");
2337             fail("getCalendarList didn't throw a ConversionException");
2338         }
2339         catch (ConversionException e)
2340         {
2341             // expected
2342         }
2343 
2344         try
2345         {
2346             conf.get(InetAddress.class, "key1");
2347             fail("getInetAddress didn't throw a ConversionException");
2348         }
2349         catch (ConversionException e)
2350         {
2351             // expected
2352         }
2353 
2354         if (SystemUtils.isJavaVersionAtLeast(1.4f))
2355         {
2356             // skip the test on Java 1.3
2357             try
2358             {
2359                 conf.get(Class.forName("javax.mail.internet.InternetAddress"), "key1");
2360                 fail("getInternetAddress didn't throw a ConversionException");
2361             }
2362             catch (ConversionException e)
2363             {
2364                 // expected
2365             }
2366         }
2367     }
2368 }