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