1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
54 conf.addProperty("empty", "");
55
56
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
405 }
406 }
407
408 public void testGetBooleanArray()
409 {
410
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
417 ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list1"));
418
419
420 ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list2"));
421
422
423 ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list3"));
424
425
426 ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list4"));
427
428
429 ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list5"));
430
431
432 ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list6"));
433
434
435 ArrayAssert.assertEquals(expected, conf.getBooleanArray("boolean.list.interpolated"));
436
437
438 ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.string"));
439 ArrayAssert.assertEquals(new boolean[] { true }, conf.getBooleanArray("boolean.object"));
440
441
442 ArrayAssert.assertEquals(new boolean[] { }, conf.getBooleanArray("empty"));
443 }
444
445 public void testGetBooleanList()
446 {
447
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
455 ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list1"));
456
457
458 ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list2"));
459
460
461 ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list3"));
462
463
464 ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list4"));
465
466
467 ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list5"));
468
469
470 ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list6"));
471
472
473 ListAssert.assertEquals(expected, conf.getBooleanList("boolean.list.interpolated"));
474
475
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
482 ListAssert.assertEquals(new ArrayList(), conf.getBooleanList("empty"));
483 }
484
485 public void testGetByteArray()
486 {
487
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
494 ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list1"));
495
496
497 ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list2"));
498
499
500 ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list3"));
501
502
503 ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list4"));
504
505
506 ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list5"));
507
508
509 ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list6"));
510
511
512 ArrayAssert.assertEquals(expected, conf.getByteArray("byte.list.interpolated"));
513
514
515 ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.string"));
516 ArrayAssert.assertEquals(new byte[] { 1 }, conf.getByteArray("byte.object"));
517
518
519 ArrayAssert.assertEquals(new byte[] { }, conf.getByteArray("empty"));
520 }
521
522 public void testGetByteList()
523 {
524
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
532 ListAssert.assertEquals(expected, conf.getByteList("byte.list1"));
533
534
535 ListAssert.assertEquals(expected, conf.getByteList("byte.list2"));
536
537
538 ListAssert.assertEquals(expected, conf.getByteList("byte.list3"));
539
540
541 ListAssert.assertEquals(expected, conf.getByteList("byte.list4"));
542
543
544 ListAssert.assertEquals(expected, conf.getByteList("byte.list5"));
545
546
547 ListAssert.assertEquals(expected, conf.getByteList("byte.list6"));
548
549
550 ListAssert.assertEquals(expected, conf.getByteList("byte.list.interpolated"));
551
552
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
559 ListAssert.assertEquals(new ArrayList(), conf.getByteList("empty"));
560 }
561
562 public void testGetShortArray()
563 {
564
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
571 ArrayAssert.assertEquals(expected, conf.getShortArray("short.list1"));
572
573
574 ArrayAssert.assertEquals(expected, conf.getShortArray("short.list2"));
575
576
577 ArrayAssert.assertEquals(expected, conf.getShortArray("short.list3"));
578
579
580 ArrayAssert.assertEquals(expected, conf.getShortArray("short.list4"));
581
582
583 ArrayAssert.assertEquals(expected, conf.getShortArray("short.list5"));
584
585
586 ArrayAssert.assertEquals(expected, conf.getShortArray("short.list6"));
587
588
589 ArrayAssert.assertEquals(expected, conf.getShortArray("short.list.interpolated"));
590
591
592 ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.string"));
593 ArrayAssert.assertEquals(new short[] { 1 }, conf.getShortArray("short.object"));
594
595
596 ArrayAssert.assertEquals(new short[] { }, conf.getShortArray("empty"));
597 }
598
599 public void testGetShortList()
600 {
601
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
609 ListAssert.assertEquals(expected, conf.getShortList("short.list1"));
610
611
612 ListAssert.assertEquals(expected, conf.getShortList("short.list2"));
613
614
615 ListAssert.assertEquals(expected, conf.getShortList("short.list3"));
616
617
618 ListAssert.assertEquals(expected, conf.getShortList("short.list4"));
619
620
621 ListAssert.assertEquals(expected, conf.getShortList("short.list5"));
622
623
624 ListAssert.assertEquals(expected, conf.getShortList("short.list6"));
625
626
627 ListAssert.assertEquals(expected, conf.getShortList("short.list.interpolated"));
628
629
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
636 ListAssert.assertEquals(new ArrayList(), conf.getShortList("empty"));
637 }
638
639 public void testGetIntegerArray()
640 {
641
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
648 ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list1"));
649
650
651 ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list2"));
652
653
654 ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list3"));
655
656
657 ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list4"));
658
659
660 ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list5"));
661
662
663 ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list6"));
664
665
666 ArrayAssert.assertEquals(expected, conf.getIntArray("integer.list.interpolated"));
667
668
669 ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.string"));
670 ArrayAssert.assertEquals(new int[] { 1 }, conf.getIntArray("integer.object"));
671
672
673 ArrayAssert.assertEquals(new int[] { }, conf.getIntArray("empty"));
674 }
675
676 public void testGetIntegerList()
677 {
678
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
686 ListAssert.assertEquals(expected, conf.getIntegerList("integer.list1"));
687
688
689 ListAssert.assertEquals(expected, conf.getIntegerList("integer.list2"));
690
691
692 ListAssert.assertEquals(expected, conf.getIntegerList("integer.list3"));
693
694
695 ListAssert.assertEquals(expected, conf.getIntegerList("integer.list4"));
696
697
698 ListAssert.assertEquals(expected, conf.getIntegerList("integer.list5"));
699
700
701 ListAssert.assertEquals(expected, conf.getIntegerList("integer.list6"));
702
703
704 ListAssert.assertEquals(expected, conf.getIntegerList("integer.list.interpolated"));
705
706
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
713 ListAssert.assertEquals(new ArrayList(), conf.getIntegerList("empty"));
714 }
715
716 public void testGetLongArray()
717 {
718
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
725 ArrayAssert.assertEquals(expected, conf.getLongArray("long.list1"));
726
727
728 ArrayAssert.assertEquals(expected, conf.getLongArray("long.list2"));
729
730
731 ArrayAssert.assertEquals(expected, conf.getLongArray("long.list3"));
732
733
734 ArrayAssert.assertEquals(expected, conf.getLongArray("long.list4"));
735
736
737 ArrayAssert.assertEquals(expected, conf.getLongArray("long.list5"));
738
739
740 ArrayAssert.assertEquals(expected, conf.getLongArray("long.list6"));
741
742
743 ArrayAssert.assertEquals(expected, conf.getLongArray("long.list.interpolated"));
744
745
746 ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.string"));
747 ArrayAssert.assertEquals(new long[] { 1 }, conf.getLongArray("long.object"));
748
749
750 ArrayAssert.assertEquals(new long[] { }, conf.getLongArray("empty"));
751 }
752
753 public void testGetLongList()
754 {
755
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
763 ListAssert.assertEquals(expected, conf.getLongList("long.list1"));
764
765
766 ListAssert.assertEquals(expected, conf.getLongList("long.list2"));
767
768
769 ListAssert.assertEquals(expected, conf.getLongList("long.list3"));
770
771
772 ListAssert.assertEquals(expected, conf.getLongList("long.list4"));
773
774
775 ListAssert.assertEquals(expected, conf.getLongList("long.list5"));
776
777
778 ListAssert.assertEquals(expected, conf.getLongList("long.list6"));
779
780
781 ListAssert.assertEquals(expected, conf.getLongList("long.list.interpolated"));
782
783
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
790 ListAssert.assertEquals(new ArrayList(), conf.getLongList("empty"));
791 }
792
793 public void testGetFloatArray()
794 {
795
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
802 ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list1"), 0);
803
804
805 ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list2"), 0);
806
807
808 ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list3"), 0);
809
810
811 ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list4"), 0);
812
813
814 ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list5"), 0);
815
816
817 ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list6"), 0);
818
819
820 ArrayAssert.assertEquals(expected, conf.getFloatArray("float.list.interpolated"), 0);
821
822
823 ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.string"), 0);
824 ArrayAssert.assertEquals(new float[] { 1 }, conf.getFloatArray("float.object"), 0);
825
826
827 ArrayAssert.assertEquals(new float[] { }, conf.getFloatArray("empty"), 0);
828 }
829
830 public void testGetFloatList()
831 {
832
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
840 ListAssert.assertEquals(expected, conf.getFloatList("float.list1"));
841
842
843 ListAssert.assertEquals(expected, conf.getFloatList("float.list2"));
844
845
846 ListAssert.assertEquals(expected, conf.getFloatList("float.list3"));
847
848
849 ListAssert.assertEquals(expected, conf.getFloatList("float.list4"));
850
851
852 ListAssert.assertEquals(expected, conf.getFloatList("float.list5"));
853
854
855 ListAssert.assertEquals(expected, conf.getFloatList("float.list6"));
856
857
858 ListAssert.assertEquals(expected, conf.getFloatList("float.list.interpolated"));
859
860
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
867 ListAssert.assertEquals(new ArrayList(), conf.getFloatList("empty"));
868 }
869
870 public void testGetDoubleArray()
871 {
872
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
879 ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list1"), 0);
880
881
882 ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list2"), 0);
883
884
885 ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list3"), 0);
886
887
888 ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list4"), 0);
889
890
891 ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list5"), 0);
892
893
894 ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list6"), 0);
895
896
897 ArrayAssert.assertEquals(expected, conf.getDoubleArray("double.list.interpolated"), 0);
898
899
900 ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.string"), 0);
901 ArrayAssert.assertEquals(new double[] { 1 }, conf.getDoubleArray("double.object"), 0);
902
903
904 ArrayAssert.assertEquals(new double[] { }, conf.getDoubleArray("empty"), 0);
905 }
906
907 public void testGetDoubleList()
908 {
909
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
917 ListAssert.assertEquals(expected, conf.getDoubleList("double.list1"));
918
919
920 ListAssert.assertEquals(expected, conf.getDoubleList("double.list2"));
921
922
923 ListAssert.assertEquals(expected, conf.getDoubleList("double.list3"));
924
925
926 ListAssert.assertEquals(expected, conf.getDoubleList("double.list4"));
927
928
929 ListAssert.assertEquals(expected, conf.getDoubleList("double.list5"));
930
931
932 ListAssert.assertEquals(expected, conf.getDoubleList("double.list6"));
933
934
935 ListAssert.assertEquals(expected, conf.getDoubleList("double.list.interpolated"));
936
937
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
944 ListAssert.assertEquals(new ArrayList(), conf.getDoubleList("empty"));
945 }
946
947 public void testGetBigIntegerArray()
948 {
949
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
956 ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list1"));
957
958
959 ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list2"));
960
961
962 ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list3"));
963
964
965 ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list4"));
966
967
968 ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list6"));
969
970
971 ArrayAssert.assertEquals(expected, conf.getBigIntegerArray("biginteger.list.interpolated"));
972
973
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
978 ArrayAssert.assertEquals(new BigInteger[] { }, conf.getBigIntegerArray("empty"));
979 }
980
981 public void testGetBigIntegerList()
982 {
983
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
991 ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list1"));
992
993
994 ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list2"));
995
996
997 ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list3"));
998
999
1000 ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list4"));
1001
1002
1003 ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list6"));
1004
1005
1006 ListAssert.assertEquals(expected, conf.getBigIntegerList("biginteger.list.interpolated"));
1007
1008
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
1015 ListAssert.assertEquals(new ArrayList(), conf.getBigIntegerList("empty"));
1016 }
1017
1018 public void testGetBigDecimalArray()
1019 {
1020
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
1027 ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list1"));
1028
1029
1030 ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list2"));
1031
1032
1033 ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list3"));
1034
1035
1036 ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list4"));
1037
1038
1039 ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list6"));
1040
1041
1042 ArrayAssert.assertEquals(expected, conf.getBigDecimalArray("bigdecimal.list.interpolated"));
1043
1044
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
1049 ArrayAssert.assertEquals(new BigDecimal[] { }, conf.getBigDecimalArray("empty"));
1050 }
1051
1052 public void testGetBigDecimalList()
1053 {
1054
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
1062 ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list1"));
1063
1064
1065 ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list2"));
1066
1067
1068 ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list3"));
1069
1070
1071 ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list4"));
1072
1073
1074 ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list6"));
1075
1076
1077 ListAssert.assertEquals(expected, conf.getBigDecimalList("bigdecimal.list.interpolated"));
1078
1079
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
1086 ListAssert.assertEquals(new ArrayList(), conf.getBigDecimalList("empty"));
1087 }
1088
1089 public void testGetURL() throws Exception
1090 {
1091
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
1098 assertEquals(expected, conf.getURL("url.string"));
1099
1100
1101 assertEquals(expected, conf.getURL("url.object"));
1102
1103
1104 assertEquals(expected, conf.getURL("url.string.interpolated"));
1105 }
1106
1107 public void testGetURLArray() throws Exception
1108 {
1109
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
1116 ArrayAssert.assertEquals(expected, conf.getURLArray("url.list1"));
1117
1118
1119 ArrayAssert.assertEquals(expected, conf.getURLArray("url.list2"));
1120
1121
1122 ArrayAssert.assertEquals(expected, conf.getURLArray("url.list3"));
1123
1124
1125 ArrayAssert.assertEquals(expected, conf.getURLArray("url.list4"));
1126
1127
1128 ArrayAssert.assertEquals(expected, conf.getURLArray("url.list6"));
1129
1130
1131 ArrayAssert.assertEquals(expected, conf.getURLArray("url.list.interpolated"));
1132
1133
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
1138 ArrayAssert.assertEquals(new URL[] { }, conf.getURLArray("empty"));
1139 }
1140
1141 public void testGetURLList() throws Exception
1142 {
1143
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
1151 ListAssert.assertEquals(expected, conf.getURLList("url.list1"));
1152
1153
1154 ListAssert.assertEquals(expected, conf.getURLList("url.list2"));
1155
1156
1157 ListAssert.assertEquals(expected, conf.getURLList("url.list3"));
1158
1159
1160 ListAssert.assertEquals(expected, conf.getURLList("url.list4"));
1161
1162
1163 ListAssert.assertEquals(expected, conf.getURLList("url.list6"));
1164
1165
1166 ListAssert.assertEquals(expected, conf.getURLList("url.list.interpolated"));
1167
1168
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
1175 ListAssert.assertEquals(new ArrayList(), conf.getURLList("empty"));
1176 }
1177
1178 public void testGetLocale()
1179 {
1180
1181 conf.setProperty("locale", "fr");
1182 assertEquals("language", new Locale("fr", ""), conf.getLocale("locale"));
1183
1184
1185 conf.setProperty("locale", "fr__POSIX");
1186 assertEquals("language + variant", new Locale("fr", "", "POSIX"), conf.getLocale("locale"));
1187
1188
1189 conf.setProperty("locale", "_FR");
1190 assertEquals("country", new Locale("", "FR"), conf.getLocale("locale"));
1191
1192
1193 conf.setProperty("locale", "_FR_WIN");
1194 assertEquals("country + variant", new Locale("", "FR", "WIN"), conf.getLocale("locale"));
1195
1196
1197 conf.setProperty("locale", "fr_FR");
1198 assertEquals("language + country", new Locale("fr", "FR"), conf.getLocale("locale"));
1199
1200
1201 conf.setProperty("locale", "fr_FR_MAC");
1202 assertEquals("language + country + variant", new Locale("fr", "FR", "MAC"), conf.getLocale("locale"));
1203
1204
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
1210 assertEquals(Locale.FRENCH, conf.getLocale("locale.string.interpolated"));
1211 }
1212
1213 public void testGetLocaleArray() throws Exception
1214 {
1215
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
1222 ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list1"));
1223
1224
1225 ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list2"));
1226
1227
1228 ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list3"));
1229
1230
1231 ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list4"));
1232
1233
1234 ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list6"));
1235
1236
1237 ArrayAssert.assertEquals(expected, conf.getLocaleArray("locale.list.interpolated"));
1238
1239
1240 ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.string"));
1241 ArrayAssert.assertEquals(new Locale[] { Locale.FRENCH }, conf.getLocaleArray("locale.object"));
1242
1243
1244 ArrayAssert.assertEquals(new Locale[] { }, conf.getLocaleArray("empty"));
1245 }
1246
1247 public void testGetLocaleList() throws Exception
1248 {
1249
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
1257 ListAssert.assertEquals(expected, conf.getLocaleList("locale.list1"));
1258
1259
1260 ListAssert.assertEquals(expected, conf.getLocaleList("locale.list2"));
1261
1262
1263 ListAssert.assertEquals(expected, conf.getLocaleList("locale.list3"));
1264
1265
1266 ListAssert.assertEquals(expected, conf.getLocaleList("locale.list4"));
1267
1268
1269 ListAssert.assertEquals(expected, conf.getLocaleList("locale.list6"));
1270
1271
1272 ListAssert.assertEquals(expected, conf.getLocaleList("locale.list.interpolated"));
1273
1274
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
1281 ListAssert.assertEquals(new ArrayList(), conf.getLocaleList("empty"));
1282 }
1283
1284 public void testGetColor()
1285 {
1286
1287 conf.setProperty("color", "FF0000");
1288 assertEquals("color", Color.red, conf.getColor("color"));
1289
1290
1291 conf.setProperty("color", "#00FF00");
1292 assertEquals("color", Color.green, conf.getColor("color"));
1293
1294
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
1304 assertEquals(Color.red, conf.getColor("color.string.interpolated"));
1305
1306
1307 assertEquals(Color.cyan, conf.getColor("unknownkey", Color.cyan));
1308 }
1309
1310 public void testGetColorArray() throws Exception
1311 {
1312
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
1319 ArrayAssert.assertEquals(expected, conf.getColorArray("color.list1"));
1320
1321
1322 ArrayAssert.assertEquals(expected, conf.getColorArray("color.list2"));
1323
1324
1325 ArrayAssert.assertEquals(expected, conf.getColorArray("color.list3"));
1326
1327
1328 ArrayAssert.assertEquals(expected, conf.getColorArray("color.list4"));
1329
1330
1331 ArrayAssert.assertEquals(expected, conf.getColorArray("color.list6"));
1332
1333
1334 ArrayAssert.assertEquals(expected, conf.getColorArray("color.list.interpolated"));
1335
1336
1337 ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.string"));
1338 ArrayAssert.assertEquals(new Color[] { Color.red }, conf.getColorArray("color.object"));
1339
1340
1341 ArrayAssert.assertEquals(new Color[] { }, conf.getColorArray("empty"));
1342 }
1343
1344 public void testGetColorList() throws Exception
1345 {
1346
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
1354 ListAssert.assertEquals(expected, conf.getColorList("color.list1"));
1355
1356
1357 ListAssert.assertEquals(expected, conf.getColorList("color.list2"));
1358
1359
1360 ListAssert.assertEquals(expected, conf.getColorList("color.list3"));
1361
1362
1363 ListAssert.assertEquals(expected, conf.getColorList("color.list4"));
1364
1365
1366 ListAssert.assertEquals(expected, conf.getColorList("color.list6"));
1367
1368
1369 ListAssert.assertEquals(expected, conf.getColorList("color.list.interpolated"));
1370
1371
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
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
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
1400 }
1401
1402 Date expected = format.parse("2004-01-01");
1403
1404
1405 assertEquals(expected, conf.getDate("date.string"));
1406 assertEquals(expected, conf.getDate("date.string", "yyyy-MM-dd"));
1407
1408
1409 assertEquals(expected, conf.getDate("date.object"));
1410
1411
1412 assertEquals(expected, conf.getDate("calendar.object"));
1413
1414
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
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
1431 ArrayAssert.assertEquals(expected, conf.getDateArray("date.list1"));
1432
1433
1434 ArrayAssert.assertEquals(expected, conf.getDateArray("date.list2"));
1435
1436
1437 ArrayAssert.assertEquals(expected, conf.getDateArray("date.list3"));
1438
1439
1440 ArrayAssert.assertEquals(expected, conf.getDateArray("date.list4"));
1441
1442
1443 ArrayAssert.assertEquals(expected, conf.getDateArray("date.list5"));
1444
1445
1446 ArrayAssert.assertEquals(expected, conf.getDateArray("date.list6"));
1447
1448
1449 ArrayAssert.assertEquals(expected, conf.getDateArray("date.list.interpolated"));
1450
1451
1452 ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.string"));
1453 ArrayAssert.assertEquals(new Date[] { date1 }, conf.getDateArray("date.object"));
1454
1455
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
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
1485 ListAssert.assertEquals(expected, conf.getDateList("date.list1"));
1486 ListAssert.assertEquals(expected, conf.getList(Date.class, "date.list1"));
1487
1488
1489 ListAssert.assertEquals(expected, conf.getDateList("date.list2"));
1490
1491
1492 ListAssert.assertEquals(expected, conf.getDateList("date.list3"));
1493
1494
1495 ListAssert.assertEquals(expected, conf.getDateList("date.list4"));
1496
1497
1498 ListAssert.assertEquals(expected, conf.getDateList("date.list5"));
1499
1500
1501 ListAssert.assertEquals(expected, conf.getDateList("date.list6"));
1502
1503
1504 ListAssert.assertEquals(expected, conf.getList(Date.class, "date.list7"));
1505
1506
1507 ListAssert.assertEquals(expected, conf.getDateList("date.list.interpolated"));
1508
1509
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
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
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
1539 }
1540
1541 Calendar expected = Calendar.getInstance();
1542 expected.setTime(format.parse("2004-01-01"));
1543
1544
1545 assertEquals(expected, conf.getCalendar("calendar.string"));
1546 assertEquals(expected, conf.getCalendar("calendar.string", "yyyy-MM-dd"));
1547
1548
1549 assertEquals(expected, conf.getCalendar("calendar.object"));
1550
1551
1552 assertEquals(expected, conf.getCalendar("date.object"));
1553
1554
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
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
1575 ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list1"));
1576
1577
1578 ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list2"));
1579
1580
1581 ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list3"));
1582
1583
1584 ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list4"));
1585
1586
1587 ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list5"));
1588
1589
1590 ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list6"));
1591
1592
1593 ArrayAssert.assertEquals(expected, conf.getCalendarArray("calendar.list.interpolated"));
1594
1595
1596 ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.string"));
1597 ArrayAssert.assertEquals(new Calendar[] { calendar1 }, conf.getCalendarArray("calendar.object"));
1598
1599
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
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
1638 ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list1"));
1639 ListAssert.assertEquals(expected, conf.getList(Calendar.class, "calendar.list1"));
1640
1641
1642 ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list2"));
1643
1644
1645 ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list3"));
1646
1647
1648 ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list4"));
1649
1650
1651 ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list5"));
1652
1653
1654 ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list6"));
1655
1656
1657 ListAssert.assertEquals(expected, conf.getList(Calendar.class, "calendar.list7"));
1658
1659
1660 ListAssert.assertEquals(expected, conf.getCalendarList("calendar.list.interpolated"));
1661
1662
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
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
1677 assertEquals(expected, conf.get(InetAddress.class, "ip.string"));
1678
1679
1680 assertEquals(expected, conf.get(InetAddress.class, "ip.object"));
1681
1682
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
1694 }
1695 }
1696
1697 public void testGetInternetAddress() throws Exception
1698 {
1699 if (!SystemUtils.isJavaVersionAtLeast(1.4f))
1700 {
1701
1702 return;
1703 }
1704
1705 Object expected = createInternetAddress("ebourg@apache.org");
1706
1707
1708 assertEquals(expected, conf.get(expected.getClass(), "email.string"));
1709
1710
1711 assertEquals(expected, conf.get(expected.getClass(), "email.object"));
1712
1713
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
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
1752 }
1753
1754 try
1755 {
1756 conf.getBooleanArray("key2");
1757 fail("getBooleanArray didn't throw a ConversionException");
1758 }
1759 catch (ConversionException e)
1760 {
1761
1762 }
1763
1764 try
1765 {
1766 conf.getBooleanList("key1");
1767 fail("getBooleanList didn't throw a ConversionException");
1768 }
1769 catch (ConversionException e)
1770 {
1771
1772 }
1773
1774 try
1775 {
1776 conf.getBooleanList("key2");
1777 fail("getBooleanList didn't throw a ConversionException");
1778 }
1779 catch (ConversionException e)
1780 {
1781
1782 }
1783
1784 try
1785 {
1786 conf.getByteArray("key1");
1787 fail("getByteArray didn't throw a ConversionException");
1788 }
1789 catch (ConversionException e)
1790 {
1791
1792 }
1793
1794 try
1795 {
1796 conf.getByteArray("key2");
1797 fail("getByteArray didn't throw a ConversionException");
1798 }
1799 catch (ConversionException e)
1800 {
1801
1802 }
1803
1804 try
1805 {
1806 conf.getByteList("key1");
1807 fail("getByteList didn't throw a ConversionException");
1808 }
1809 catch (ConversionException e)
1810 {
1811
1812 }
1813
1814 try
1815 {
1816 conf.getByteList("key2");
1817 fail("getByteList didn't throw a ConversionException");
1818 }
1819 catch (ConversionException e)
1820 {
1821
1822 }
1823
1824 try
1825 {
1826 conf.getShortArray("key1");
1827 fail("getShortArray didn't throw a ConversionException");
1828 }
1829 catch (ConversionException e)
1830 {
1831
1832 }
1833
1834 try
1835 {
1836 conf.getShortArray("key2");
1837 fail("getShortArray didn't throw a ConversionException");
1838 }
1839 catch (ConversionException e)
1840 {
1841
1842 }
1843
1844 try
1845 {
1846 conf.getShortList("key1");
1847 fail("getShortList didn't throw a ConversionException");
1848 }
1849 catch (ConversionException e)
1850 {
1851
1852 }
1853
1854 try
1855 {
1856 conf.getShortList("key2");
1857 fail("getShortList didn't throw a ConversionException");
1858 }
1859 catch (ConversionException e)
1860 {
1861
1862 }
1863
1864 try
1865 {
1866 conf.getIntArray("key1");
1867 fail("getIntArray didn't throw a ConversionException");
1868 }
1869 catch (ConversionException e)
1870 {
1871
1872 }
1873
1874 try
1875 {
1876 conf.getIntArray("key2");
1877 fail("getIntArray didn't throw a ConversionException");
1878 }
1879 catch (ConversionException e)
1880 {
1881
1882 }
1883
1884 try
1885 {
1886 conf.getIntegerList("key1");
1887 fail("getIntegerList didn't throw a ConversionException");
1888 }
1889 catch (ConversionException e)
1890 {
1891
1892 }
1893
1894 try
1895 {
1896 conf.getIntegerList("key2");
1897 fail("getIntegerList didn't throw a ConversionException");
1898 }
1899 catch (ConversionException e)
1900 {
1901
1902 }
1903
1904 try
1905 {
1906 conf.getLongArray("key1");
1907 fail("getLongArray didn't throw a ConversionException");
1908 }
1909 catch (ConversionException e)
1910 {
1911
1912 }
1913
1914 try
1915 {
1916 conf.getLongArray("key2");
1917 fail("getLongArray didn't throw a ConversionException");
1918 }
1919 catch (ConversionException e)
1920 {
1921
1922 }
1923
1924 try
1925 {
1926 conf.getLongList("key1");
1927 fail("getLongList didn't throw a ConversionException");
1928 }
1929 catch (ConversionException e)
1930 {
1931
1932 }
1933
1934 try
1935 {
1936 conf.getLongList("key2");
1937 fail("getLongList didn't throw a ConversionException");
1938 }
1939 catch (ConversionException e)
1940 {
1941
1942 }
1943
1944 try
1945 {
1946 conf.getFloatArray("key1");
1947 fail("getFloatArray didn't throw a ConversionException");
1948 }
1949 catch (ConversionException e)
1950 {
1951
1952 }
1953
1954 try
1955 {
1956 conf.getFloatArray("key2");
1957 fail("getFloatArray didn't throw a ConversionException");
1958 }
1959 catch (ConversionException e)
1960 {
1961
1962 }
1963
1964 try
1965 {
1966 conf.getFloatList("key1");
1967 fail("getFloatList didn't throw a ConversionException");
1968 }
1969 catch (ConversionException e)
1970 {
1971
1972 }
1973
1974 try
1975 {
1976 conf.getFloatList("key2");
1977 fail("getFloatList didn't throw a ConversionException");
1978 }
1979 catch (ConversionException e)
1980 {
1981
1982 }
1983
1984 try
1985 {
1986 conf.getDoubleArray("key1");
1987 fail("getDoubleArray didn't throw a ConversionException");
1988 }
1989 catch (ConversionException e)
1990 {
1991
1992 }
1993
1994 try
1995 {
1996 conf.getDoubleArray("key2");
1997 fail("getDoubleArray didn't throw a ConversionException");
1998 }
1999 catch (ConversionException e)
2000 {
2001
2002 }
2003
2004 try
2005 {
2006 conf.getDoubleList("key1");
2007 fail("getDoubleList didn't throw a ConversionException");
2008 }
2009 catch (ConversionException e)
2010 {
2011
2012 }
2013
2014 try
2015 {
2016 conf.getDoubleList("key2");
2017 fail("getDoubleList didn't throw a ConversionException");
2018 }
2019 catch (ConversionException e)
2020 {
2021
2022 }
2023
2024 try
2025 {
2026 conf.getBigIntegerArray("key1");
2027 fail("getBigIntegerArray didn't throw a ConversionException");
2028 }
2029 catch (ConversionException e)
2030 {
2031
2032 }
2033
2034 try
2035 {
2036 conf.getBigIntegerArray("key2");
2037 fail("getBigIntegerArray didn't throw a ConversionException");
2038 }
2039 catch (ConversionException e)
2040 {
2041
2042 }
2043
2044 try
2045 {
2046 conf.getBigIntegerList("key1");
2047 fail("getBigIntegerList didn't throw a ConversionException");
2048 }
2049 catch (ConversionException e)
2050 {
2051
2052 }
2053
2054 try
2055 {
2056 conf.getBigIntegerList("key2");
2057 fail("getBigIntegerList didn't throw a ConversionException");
2058 }
2059 catch (ConversionException e)
2060 {
2061
2062 }
2063
2064 try
2065 {
2066 conf.getBigDecimalArray("key1");
2067 fail("getBigDecimalArray didn't throw a ConversionException");
2068 }
2069 catch (ConversionException e)
2070 {
2071
2072 }
2073
2074 try
2075 {
2076 conf.getBigDecimalArray("key2");
2077 fail("getBigDecimalArray didn't throw a ConversionException");
2078 }
2079 catch (ConversionException e)
2080 {
2081
2082 }
2083
2084 try
2085 {
2086 conf.getBigDecimalList("key1");
2087 fail("getBigDecimalList didn't throw a ConversionException");
2088 }
2089 catch (ConversionException e)
2090 {
2091
2092 }
2093
2094 try
2095 {
2096 conf.getBigDecimalList("key2");
2097 fail("getBigDecimalList didn't throw a ConversionException");
2098 }
2099 catch (ConversionException e)
2100 {
2101
2102 }
2103
2104 try
2105 {
2106 conf.getURLArray("key1");
2107 fail("getURLArray didn't throw a ConversionException");
2108 }
2109 catch (ConversionException e)
2110 {
2111
2112 }
2113
2114 try
2115 {
2116 conf.getURLArray("key2");
2117 fail("getURLArray didn't throw a ConversionException");
2118 }
2119 catch (ConversionException e)
2120 {
2121
2122 }
2123
2124 try
2125 {
2126 conf.getURLList("key1");
2127 fail("getURLList didn't throw a ConversionException");
2128 }
2129 catch (ConversionException e)
2130 {
2131
2132 }
2133
2134 try
2135 {
2136 conf.getURLList("key2");
2137 fail("getURLList didn't throw a ConversionException");
2138 }
2139 catch (ConversionException e)
2140 {
2141
2142 }
2143
2144 try
2145 {
2146 conf.getLocaleArray("key1");
2147 fail("getLocaleArray didn't throw a ConversionException");
2148 }
2149 catch (ConversionException e)
2150 {
2151
2152 }
2153
2154 try
2155 {
2156 conf.getLocaleArray("key2");
2157 fail("getLocaleArray didn't throw a ConversionException");
2158 }
2159 catch (ConversionException e)
2160 {
2161
2162 }
2163
2164 try
2165 {
2166 conf.getLocaleList("key1");
2167 fail("getLocaleList didn't throw a ConversionException");
2168 }
2169 catch (ConversionException e)
2170 {
2171
2172 }
2173
2174 try
2175 {
2176 conf.getLocaleList("key2");
2177 fail("getLocaleList didn't throw a ConversionException");
2178 }
2179 catch (ConversionException e)
2180 {
2181
2182 }
2183
2184 try
2185 {
2186 conf.getColorArray("key1");
2187 fail("getColorArray didn't throw a ConversionException");
2188 }
2189 catch (ConversionException e)
2190 {
2191
2192 }
2193
2194 try
2195 {
2196 conf.getColorArray("key2");
2197 fail("getColorArray didn't throw a ConversionException");
2198 }
2199 catch (ConversionException e)
2200 {
2201
2202 }
2203
2204 try
2205 {
2206 conf.getColorList("key1");
2207 fail("getColorList didn't throw a ConversionException");
2208 }
2209 catch (ConversionException e)
2210 {
2211
2212 }
2213
2214 try
2215 {
2216 conf.getColorList("key2");
2217 fail("getColorList didn't throw a ConversionException");
2218 }
2219 catch (ConversionException e)
2220 {
2221
2222 }
2223
2224 try
2225 {
2226 conf.getDateArray("key1");
2227 fail("getDateArray didn't throw a ConversionException");
2228 }
2229 catch (ConversionException e)
2230 {
2231
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
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
2252 }
2253
2254 try
2255 {
2256 conf.getDateArray("key2");
2257 fail("getDateArray didn't throw a ConversionException");
2258 }
2259 catch (ConversionException e)
2260 {
2261
2262 }
2263
2264 try
2265 {
2266 conf.getDateList("key1");
2267 fail("getDateList didn't throw a ConversionException");
2268 }
2269 catch (ConversionException e)
2270 {
2271
2272 }
2273
2274 try
2275 {
2276 conf.getDateList("key2");
2277 fail("getDateList didn't throw a ConversionException");
2278 }
2279 catch (ConversionException e)
2280 {
2281
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
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
2302 }
2303
2304 try
2305 {
2306 conf.getCalendarArray("key1");
2307 fail("getCalendarArray didn't throw a ConversionException");
2308 }
2309 catch (ConversionException e)
2310 {
2311
2312 }
2313
2314 try
2315 {
2316 conf.getCalendarArray("key2");
2317 fail("getCalendarArray didn't throw a ConversionException");
2318 }
2319 catch (ConversionException e)
2320 {
2321
2322 }
2323
2324 try
2325 {
2326 conf.getCalendarList("key1");
2327 fail("getCalendarList didn't throw a ConversionException");
2328 }
2329 catch (ConversionException e)
2330 {
2331
2332 }
2333
2334 try
2335 {
2336 conf.getCalendarList("key2");
2337 fail("getCalendarList didn't throw a ConversionException");
2338 }
2339 catch (ConversionException e)
2340 {
2341
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
2352 }
2353
2354 if (SystemUtils.isJavaVersionAtLeast(1.4f))
2355 {
2356
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
2365 }
2366 }
2367 }
2368 }