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