1
2
3
4
5
6
7
8 package org.codehaus.dna.impl;
9
10 import java.util.Map;
11 import junit.framework.TestCase;
12
13 import org.codehaus.dna.Configuration;
14 import org.codehaus.dna.ConfigurationException;
15 import org.codehaus.dna.impl.DefaultConfiguration;
16
17 public class DefaultConfigurationTestCase
18 extends TestCase
19 {
20 public void testBasicConfigurationElement()
21 throws Exception
22 {
23 final String name = "myElement";
24 final String location = "file.xml:20";
25 final String path = "";
26 final DefaultConfiguration configuration =
27 new DefaultConfiguration( name, location, path );
28 assertEquals( "name", name, configuration.getName() );
29 assertEquals( "location", location, configuration.getLocation() );
30 assertEquals( "path", path, configuration.getPath() );
31 }
32
33 public void testNullNameInCtor()
34 throws Exception
35 {
36 final String name = null;
37 final String location = "file.xml:20";
38 final String path = "";
39 try
40 {
41 new DefaultConfiguration( name, location, path );
42 }
43 catch( final NullPointerException npe )
44 {
45 assertEquals( "name", npe.getMessage() );
46 return;
47 }
48 fail( "Expected null pointer exception as passed in null to ctor." );
49 }
50
51 public void testNullLocationInCtor()
52 throws Exception
53 {
54 final String name = "name";
55 final String location = null;
56 final String path = "";
57 try
58 {
59 new DefaultConfiguration( name, location, path );
60 }
61 catch( final NullPointerException npe )
62 {
63 assertEquals( "location", npe.getMessage() );
64 return;
65 }
66 fail( "Expected null pointer exception as passed in null to ctor." );
67 }
68
69 public void testNullPathInCtor()
70 throws Exception
71 {
72 final String name = "name";
73 final String location = "";
74 final String path = null;
75 try
76 {
77 new DefaultConfiguration( name, location, path );
78 }
79 catch( final NullPointerException npe )
80 {
81 assertEquals( "path", npe.getMessage() );
82 return;
83 }
84 fail( "Expected null pointer exception as passed in null to ctor." );
85 }
86
87 public void testNullNameInSetAttribute()
88 throws Exception
89 {
90 final DefaultConfiguration configuration =
91 new DefaultConfiguration( "name", "", "" );
92 try
93 {
94 configuration.setAttribute( null, "" );
95 }
96 catch( final NullPointerException npe )
97 {
98 assertEquals( "key", npe.getMessage() );
99 return;
100 }
101 fail( "Expected null pointer exception as passed in null to setAttribute." );
102 }
103
104 public void testNullValueInSetAttribute()
105 throws Exception
106 {
107 final DefaultConfiguration configuration =
108 new DefaultConfiguration( "name", "", "" );
109 try
110 {
111 configuration.setAttribute( "", null );
112 }
113 catch( final NullPointerException npe )
114 {
115 assertEquals( "value", npe.getMessage() );
116 return;
117 }
118 fail( "Expected null pointer exception as passed in null to setAttribute." );
119 }
120
121 public void testNullValueInSetValue()
122 throws Exception
123 {
124 final DefaultConfiguration configuration =
125 new DefaultConfiguration( "name", "", "" );
126 try
127 {
128 configuration.setValue( null );
129 }
130 catch( final NullPointerException npe )
131 {
132 assertEquals( "value", npe.getMessage() );
133 return;
134 }
135 fail( "Expected null pointer exception as passed in null to setValue." );
136 }
137
138 public void testNullChildinAddChild()
139 throws Exception
140 {
141 final DefaultConfiguration configuration =
142 new DefaultConfiguration( "name", "", "" );
143 try
144 {
145 configuration.addChild( null );
146 }
147 catch( final NullPointerException npe )
148 {
149 assertEquals( "configuration", npe.getMessage() );
150 return;
151 }
152 fail( "Expected null pointer exception as passed in null to addChild." );
153 }
154
155 public void testNullNameInGetAttribute()
156 throws Exception
157 {
158 final DefaultConfiguration configuration =
159 new DefaultConfiguration( "name", "", "" );
160 try
161 {
162 configuration.getAttribute( null );
163 }
164 catch( final NullPointerException npe )
165 {
166 assertEquals( "name", npe.getMessage() );
167 return;
168 }
169 fail( "Expected null pointer exception as passed in null to getAttribute." );
170 }
171
172 public void testNullNameInGetChild()
173 throws Exception
174 {
175 final DefaultConfiguration configuration =
176 new DefaultConfiguration( "name", "", "" );
177 try
178 {
179 configuration.getChild( null, false );
180 }
181 catch( final NullPointerException npe )
182 {
183 assertEquals( "name", npe.getMessage() );
184 return;
185 }
186 fail( "Expected null pointer exception as passed in null to getChild." );
187 }
188
189 public void testNullNameInGetChildren()
190 throws Exception
191 {
192 final DefaultConfiguration configuration =
193 new DefaultConfiguration( "name", "", "" );
194 try
195 {
196 configuration.getChildren( null );
197 }
198 catch( final NullPointerException npe )
199 {
200 assertEquals( "name", npe.getMessage() );
201 return;
202 }
203 fail( "Expected null pointer exception as passed in null to getChildren." );
204 }
205
206 public void testGetValueAsText()
207 throws Exception
208 {
209 final DefaultConfiguration configuration =
210 new DefaultConfiguration( "myElement", "file.xml:20", "" );
211 final String value = "blah";
212 configuration.setValue( value );
213 assertEquals( "getValue()", value, configuration.getValue() );
214 assertEquals( "getValue('test')", value, configuration.getValue( "test" ) );
215 }
216
217 public void testGetNullValueAsText()
218 throws Exception
219 {
220 final DefaultConfiguration configuration =
221 new DefaultConfiguration( "myElement", "file.xml:20", "" );
222 assertEquals( "getValue('test')", "test", configuration.getValue( "test" ) );
223 try
224 {
225 configuration.getValue();
226 }
227 catch( ConfigurationException e )
228 {
229 return;
230 }
231 fail( "Expected getValue() to throw an exception" );
232 }
233
234 public void testGetValueAsBoolean()
235 throws Exception
236 {
237 final DefaultConfiguration configuration =
238 new DefaultConfiguration( "myElement", "file.xml:20", "" );
239 configuration.setValue( "true" );
240 assertEquals( "getValue()", true, configuration.getValueAsBoolean() );
241 assertEquals( "getValue('false')", true, configuration.getValueAsBoolean( false ) );
242 }
243
244 public void testGetNullValueAsBoolean()
245 throws Exception
246 {
247 final DefaultConfiguration configuration =
248 new DefaultConfiguration( "myElement", "file.xml:20", "" );
249 assertEquals( "getValue('false')", false, configuration.getValueAsBoolean( false ) );
250 try
251 {
252 configuration.getValueAsBoolean();
253 }
254 catch( ConfigurationException e )
255 {
256 return;
257 }
258 fail( "Expected getValue() to throw an exception" );
259 }
260
261 public void testGetValueAsInteger()
262 throws Exception
263 {
264 final DefaultConfiguration configuration =
265 new DefaultConfiguration( "myElement", "file.xml:20", "" );
266 configuration.setValue( "3" );
267 assertEquals( "getValue()", 3, configuration.getValueAsInteger() );
268 assertEquals( "getValue('1')", 3, configuration.getValueAsInteger( 1 ) );
269 }
270
271 public void testGetNullValueAsInteger()
272 throws Exception
273 {
274 final DefaultConfiguration configuration =
275 new DefaultConfiguration( "myElement", "file.xml:20", "" );
276 assertEquals( "getValue('1')", 1, configuration.getValueAsInteger( 1 ) );
277 try
278 {
279 configuration.getValueAsInteger();
280 }
281 catch( ConfigurationException e )
282 {
283 return;
284 }
285 fail( "Expected getValue() to throw an exception" );
286 }
287
288 public void testGetMalformedValueAsInteger()
289 throws Exception
290 {
291 final DefaultConfiguration configuration =
292 new DefaultConfiguration( "myElement", "file.xml:20", "" );
293 configuration.setValue( "malformed" );
294 assertEquals( "getValue('1')", 1, configuration.getValueAsInteger( 1 ) );
295 try
296 {
297 configuration.getValueAsInteger();
298 }
299 catch( ConfigurationException e )
300 {
301 return;
302 }
303 fail( "Expected getValue() to throw an exception" );
304 }
305
306 public void testGetValueAsLong()
307 throws Exception
308 {
309 final DefaultConfiguration configuration =
310 new DefaultConfiguration( "myElement", "file.xml:20", "" );
311 configuration.setValue( "3" );
312 assertEquals( "getValue()", 3, configuration.getValueAsLong() );
313 assertEquals( "getValue('1')", 3, configuration.getValueAsLong( 1 ) );
314 }
315
316 public void testGetNullValueAsLong()
317 throws Exception
318 {
319 final DefaultConfiguration configuration =
320 new DefaultConfiguration( "myElement", "file.xml:20", "" );
321 assertEquals( "getValue('1')", 1, configuration.getValueAsLong( 1 ) );
322 try
323 {
324 configuration.getValueAsLong();
325 }
326 catch( ConfigurationException e )
327 {
328 return;
329 }
330 fail( "Expected getValue() to throw an exception" );
331 }
332
333 public void testGetMalformedValueAsLong()
334 throws Exception
335 {
336 final DefaultConfiguration configuration =
337 new DefaultConfiguration( "myElement", "file.xml:20", "" );
338 configuration.setValue( "malformed" );
339 assertEquals( "getValue('1')", 1, configuration.getValueAsLong( 1 ) );
340 try
341 {
342 configuration.getValueAsLong();
343 }
344 catch( ConfigurationException e )
345 {
346 return;
347 }
348 fail( "Expected getValue() to throw an exception" );
349 }
350
351 public void testGetValueAsFloat()
352 throws Exception
353 {
354 final DefaultConfiguration configuration =
355 new DefaultConfiguration( "myElement", "file.xml:20", "" );
356 configuration.setValue( "3.0" );
357 assertTrue( "getValue()", 3.0 == configuration.getValueAsFloat() );
358 assertTrue( "getValue('1')", 3.0 == configuration.getValueAsFloat( 1 ) );
359 }
360
361 public void testGetNullValueAsFloat()
362 throws Exception
363 {
364 final DefaultConfiguration configuration =
365 new DefaultConfiguration( "myElement", "file.xml:20", "" );
366 assertTrue( "getValue('1')", 1.0 == configuration.getValueAsFloat( 1 ) );
367 try
368 {
369 configuration.getValueAsFloat();
370 }
371 catch( ConfigurationException e )
372 {
373 return;
374 }
375 fail( "Expected getValue() to throw an exception" );
376 }
377
378 public void testGetMalformedValueAsFloat()
379 throws Exception
380 {
381 final DefaultConfiguration configuration =
382 new DefaultConfiguration( "myElement", "file.xml:20", "" );
383 configuration.setValue( "malformed" );
384 assertTrue( "getValue('1')", 1.0 == configuration.getValueAsFloat( 1 ) );
385 try
386 {
387 configuration.getValueAsFloat();
388 }
389 catch( ConfigurationException e )
390 {
391 return;
392 }
393 fail( "Expected getValue() to throw an exception" );
394 }
395
396 public void testGetAttributeAsText()
397 throws Exception
398 {
399 final DefaultConfiguration configuration =
400 new DefaultConfiguration( "myElement", "file.xml:20", "" );
401 final String key = "key";
402 final String value = "value";
403 configuration.setAttribute( key, value );
404 assertEquals( "getAttribute('key')",
405 value,
406 configuration.getAttribute( key ) );
407 assertEquals( "getAttribute('key','defaultValue')",
408 value,
409 configuration.getAttribute( key, "defaultValue" ) );
410 }
411
412 public void testGetMissingAttributeAsText()
413 throws Exception
414 {
415 final DefaultConfiguration configuration =
416 new DefaultConfiguration( "myElement", "file.xml:20", "" );
417 final String key = "key";
418 configuration.setAttribute( "AnotherKey", "someValue" );
419 assertEquals( "getAttribute('key','defaultValue')",
420 "defaultValue",
421 configuration.getAttribute( key, "defaultValue" ) );
422
423 try
424 {
425 configuration.getAttribute( key );
426 }
427 catch( ConfigurationException e )
428 {
429 return;
430 }
431 fail( "Expected to fail with getAttribute for non existent key" );
432 }
433
434 public void testGetAttributeAsBoolean()
435 throws Exception
436 {
437 final DefaultConfiguration configuration =
438 new DefaultConfiguration( "myElement", "file.xml:20", "" );
439 final String key = "key";
440 final String value = "true";
441 configuration.setAttribute( key, value );
442 assertEquals( "getAttribute('key')",
443 true,
444 configuration.getAttributeAsBoolean( key ) );
445 assertEquals( "getAttribute('key','false')",
446 true,
447 configuration.getAttributeAsBoolean( key, false ) );
448 }
449
450 public void testGetMissingAttributeAsBoolean()
451 throws Exception
452 {
453 final DefaultConfiguration configuration =
454 new DefaultConfiguration( "myElement", "file.xml:20", "" );
455 final String key = "key";
456 assertEquals( "getAttribute('key','false')",
457 false,
458 configuration.getAttributeAsBoolean( key, false ) );
459 try
460 {
461 configuration.getAttribute( key );
462 }
463 catch( ConfigurationException e )
464 {
465 return;
466 }
467 fail( "Expected to fail with getAttribute for non existent key" );
468 }
469
470 public void testGetAttributeAsInteger()
471 throws Exception
472 {
473 final DefaultConfiguration configuration =
474 new DefaultConfiguration( "myElement", "file.xml:20", "" );
475 final String key = "key";
476 final String value = "3";
477 configuration.setAttribute( key, value );
478 assertEquals( "getAttribute('key')",
479 3,
480 configuration.getAttributeAsInteger( key ) );
481 assertEquals( "getAttribute('key','1')",
482 3,
483 configuration.getAttributeAsInteger( key, 1 ) );
484 }
485
486 public void testGetMissingAttributeAsInteger()
487 throws Exception
488 {
489 final DefaultConfiguration configuration =
490 new DefaultConfiguration( "myElement", "file.xml:20", "" );
491 final String key = "key";
492 assertEquals( "getAttribute('key','defaultValue')",
493 1,
494 configuration.getAttributeAsInteger( key, 1 ) );
495
496 try
497 {
498 configuration.getAttributeAsInteger( key );
499 }
500 catch( ConfigurationException e )
501 {
502 return;
503 }
504 fail( "Expected to fail with getAttribute for non existent key" );
505 }
506
507 public void testGetMalformedAttributeAsInteger()
508 throws Exception
509 {
510 final DefaultConfiguration configuration =
511 new DefaultConfiguration( "myElement", "file.xml:20", "" );
512 final String key = "key";
513 final String value = "malformed";
514 configuration.setAttribute( key, value );
515 assertEquals( "getAttribute('key','defaultValue')",
516 1,
517 configuration.getAttributeAsInteger( key, 1 ) );
518
519 try
520 {
521 configuration.getAttributeAsInteger( key );
522 }
523 catch( ConfigurationException e )
524 {
525 return;
526 }
527 fail( "Expected to fail with getAttribute for malformed attribute" );
528 }
529
530 public void testGetAttributeAsLong()
531 throws Exception
532 {
533 final DefaultConfiguration configuration =
534 new DefaultConfiguration( "myElement", "file.xml:20", "" );
535 final String key = "key";
536 final String value = "3";
537 configuration.setAttribute( key, value );
538 assertEquals( "getAttribute('key')",
539 3,
540 configuration.getAttributeAsLong( key ) );
541 assertEquals( "getAttribute('key','1')",
542 3,
543 configuration.getAttributeAsLong( key, 1 ) );
544 }
545
546 public void testGetMissingAttributeAsLong()
547 throws Exception
548 {
549 final DefaultConfiguration configuration =
550 new DefaultConfiguration( "myElement", "file.xml:20", "" );
551 final String key = "key";
552 assertEquals( "getAttribute('key','1')",
553 1,
554 configuration.getAttributeAsLong( key, 1 ) );
555
556 try
557 {
558 configuration.getAttributeAsLong( key );
559 }
560 catch( ConfigurationException e )
561 {
562 return;
563 }
564 fail( "Expected to fail with getAttribute for non existent key" );
565 }
566
567 public void testGetMalformedAttributeAsLong()
568 throws Exception
569 {
570 final DefaultConfiguration configuration =
571 new DefaultConfiguration( "myElement", "file.xml:20", "" );
572 final String key = "key";
573 final String value = "malformed";
574 configuration.setAttribute( key, value );
575 assertEquals( "getAttribute('key','1')",
576 1,
577 configuration.getAttributeAsLong( key, 1 ) );
578
579 try
580 {
581 configuration.getAttributeAsLong( key );
582 }
583 catch( ConfigurationException e )
584 {
585 return;
586 }
587 fail( "Expected to fail with getAttribute for malformed attribute" );
588 }
589
590 public void testGetAttributeAsFloat()
591 throws Exception
592 {
593 final DefaultConfiguration configuration =
594 new DefaultConfiguration( "myElement", "file.xml:20", "" );
595 final String key = "key";
596 final String value = "3";
597 configuration.setAttribute( key, value );
598 assertTrue( "getAttribute('key')",
599 3.0 == configuration.getAttributeAsFloat( key ) );
600 assertTrue( "getAttribute('key','1')",
601 3.0 == configuration.getAttributeAsFloat( key, 1 ) );
602 }
603
604 public void testGetMissingAttributeAsFloat()
605 throws Exception
606 {
607 final DefaultConfiguration configuration =
608 new DefaultConfiguration( "myElement", "file.xml:20", "" );
609 final String key = "key";
610 assertTrue( "getAttribute('key','defaultValue')",
611 1.0 == configuration.getAttributeAsFloat( key, 1 ) );
612
613 try
614 {
615 configuration.getAttributeAsFloat( key );
616 }
617 catch( ConfigurationException e )
618 {
619 return;
620 }
621 fail( "Expected to fail with getAttribute for non existent key" );
622 }
623
624 public void testGetMalformedAttributeAsFloat()
625 throws Exception
626 {
627 final DefaultConfiguration configuration =
628 new DefaultConfiguration( "myElement", "file.xml:20", "" );
629 final String key = "key";
630 final String value = "malformed";
631 configuration.setAttribute( key, value );
632 assertTrue( "getAttribute('key','defaultValue')",
633 1.0 == configuration.getAttributeAsFloat( key, 1 ) );
634
635 try
636 {
637 configuration.getAttributeAsFloat( key );
638 }
639 catch( ConfigurationException e )
640 {
641 return;
642 }
643 fail( "Expected to fail with getAttribute for malformed attribute" );
644 }
645
646 public void testGetAttributes()
647 throws Exception
648 {
649 final DefaultConfiguration configuration =
650 new DefaultConfiguration( "myElement", "file.xml:20", "" );
651 configuration.setAttribute( "key1", "value1" );
652 configuration.setAttribute( "key2", "value2" );
653
654 final String[] names = configuration.getAttributeNames();
655 assertEquals( "names.length", 2, names.length );
656 }
657
658 public void testGetAttributesWithNoAttributesSet()
659 throws Exception
660 {
661 final DefaultConfiguration configuration =
662 new DefaultConfiguration( "myElement", "file.xml:20", "" );
663
664 final String[] names = configuration.getAttributeNames();
665 assertEquals( "names.length", 0, names.length );
666 }
667
668 public void testGetChildren()
669 throws Exception
670 {
671 final DefaultConfiguration configuration =
672 new DefaultConfiguration( "myElement", "file.xml:20", "" );
673 final DefaultConfiguration child =
674 new DefaultConfiguration( "mychild", "file.xml:20", "/myElement" );
675
676 configuration.addChild( child );
677
678 final Configuration[] children = configuration.getChildren();
679 assertEquals( "children.length", 1, children.length );
680 assertEquals( "children[0]", child, children[ 0 ] );
681 }
682
683 public void testGetChildrenWithNoChildren()
684 throws Exception
685 {
686 final DefaultConfiguration configuration =
687 new DefaultConfiguration( "myElement", "file.xml:20", "" );
688
689 final Configuration[] children = configuration.getChildren();
690 assertEquals( "children.length", 0, children.length );
691 }
692
693 public void testGetChild()
694 throws Exception
695 {
696 final DefaultConfiguration configuration =
697 new DefaultConfiguration( "myElement", "file.xml:20", "" );
698 final DefaultConfiguration child =
699 new DefaultConfiguration( "mychild", "file.xml:20", "/myElement" );
700 configuration.addChild( child );
701
702 final Configuration test = configuration.getChild( "mychild" );
703 assertEquals( child, test );
704 }
705
706 public void testGetNotExistentChildWithNoAutoCreateButOtherChildren()
707 throws Exception
708 {
709 final DefaultConfiguration configuration =
710 new DefaultConfiguration( "myElement", "file.xml:20", "" );
711
712 final DefaultConfiguration child =
713 new DefaultConfiguration( "meep", "file.xml:20", "/myElement" );
714 configuration.addChild( child );
715
716 final Configuration test = configuration.getChild( "mychild", false );
717 assertEquals( null, test );
718 }
719
720 public void testGetNotExistentChildWithNoAutoCreate()
721 throws Exception
722 {
723 final DefaultConfiguration configuration =
724 new DefaultConfiguration( "myElement", "file.xml:20", "" );
725
726 final Configuration test = configuration.getChild( "mychild", false );
727 assertEquals( null, test );
728 }
729
730 public void testGetNotExistentChildWithAutoCreate()
731 throws Exception
732 {
733 final DefaultConfiguration configuration =
734 new DefaultConfiguration( "myElement", "file.xml:20", "" );
735
736 final Configuration test = configuration.getChild( "mychild", true );
737 assertNotNull( test );
738 assertEquals( "mychild", test.getName() );
739 }
740
741 public void testGuardAgainstMixedContentWhenAddingValue()
742 throws Exception
743 {
744 final DefaultConfiguration configuration =
745 new DefaultConfiguration( "myElement", "file.xml:20", "" );
746 final DefaultConfiguration child =
747 new DefaultConfiguration( "mychild", "file.xml:20", "/myElement" );
748 configuration.addChild( child );
749
750 try
751 {
752 configuration.setValue( "blah" );
753 }
754 catch( IllegalStateException e )
755 {
756 return;
757 }
758 fail( "Expected to fail setting mixed content for configuration" );
759 }
760
761 public void testGuardAgainstMixedContentWhenAddingChild()
762 throws Exception
763 {
764 final DefaultConfiguration configuration =
765 new DefaultConfiguration( "myElement", "file.xml:20", "" );
766 final DefaultConfiguration child =
767 new DefaultConfiguration( "mychild", "file.xml:20", "/myElement" );
768 configuration.setValue( "blah" );
769
770 try
771 {
772 configuration.addChild( child );
773 }
774 catch( IllegalStateException e )
775 {
776 return;
777 }
778 fail( "Expected to fail setting mixed content for configuration" );
779 }
780
781 public void testGetChildrenWithName()
782 throws Exception
783 {
784 final DefaultConfiguration configuration =
785 new DefaultConfiguration( "myElement", "file.xml:20", "" );
786 final DefaultConfiguration child1 =
787 new DefaultConfiguration( "mychild", "file.xml:20", "/myElement" );
788 final DefaultConfiguration child2 =
789 new DefaultConfiguration( "blah", "file.xml:20", "/myElement" );
790 final DefaultConfiguration child3 =
791 new DefaultConfiguration( "myOtherChild", "file.xml:20", "/myElement" );
792
793 configuration.addChild( child1 );
794 configuration.addChild( child2 );
795 configuration.addChild( child3 );
796
797 final Configuration[] children = configuration.getChildren( "mychild" );
798 assertEquals( "children.length", 1, children.length );
799 }
800
801 public void testGetChildrenWithNameAndNoExistingChildren()
802 throws Exception
803 {
804 final DefaultConfiguration configuration =
805 new DefaultConfiguration( "myElement", "file.xml:20", "" );
806
807 final Configuration[] children =
808 configuration.getChildren( "mychild" );
809 assertEquals( "children.length", 0, children.length );
810 }
811
812 public void testAutogeneratePath()
813 throws Exception
814 {
815 final DefaultConfiguration configuration =
816 new DefaultConfiguration( "myElement", "file.xml:20", "" );
817
818 final Configuration child = configuration.getChild( "test" ).getChild( "blah" );
819 assertEquals( "child.path", "/myElement/test", child.getPath() );
820 assertTrue( "child.location", child.getLocation().endsWith( "<autogen>" ) );
821 }
822
823 public void testMakeReadOnlyWithNoChildren()
824 throws Exception
825 {
826 final DefaultConfiguration configuration =
827 new DefaultConfiguration( "myElement", "file.xml:20", "" );
828 configuration.makeReadOnly();
829 assertTrue( "configuration.isReadOnly()", configuration.isReadOnly() );
830 }
831
832 public void testMakeReadOnlyWithChildren()
833 throws Exception
834 {
835 final DefaultConfiguration configuration =
836 new DefaultConfiguration( "myElement", "file.xml:20", "" );
837
838 final DefaultConfiguration child =
839 new DefaultConfiguration( "child", "file.xml:20", "/myElement" );
840 configuration.addChild( child );
841
842 configuration.makeReadOnly();
843 assertTrue( "configuration.isReadOnly()", configuration.isReadOnly() );
844 assertTrue( "child.isReadOnly()", child.isReadOnly() );
845 }
846
847 public void testMakeReadOnlyWithNonFreezableChildren()
848 throws Exception
849 {
850 final DefaultConfiguration configuration =
851 new DefaultConfiguration( "myElement", "file.xml:20", "" );
852
853 configuration.addChild( new MockConfiguration() );
854
855 configuration.makeReadOnly();
856 assertTrue( "configuration.isReadOnly()", configuration.isReadOnly() );
857 }
858
859 public void testToString()
860 throws Exception
861 {
862 final DefaultConfiguration configuration =
863 new DefaultConfiguration( "myElement", "file.xml:20", "" );
864
865 final String expected = "[Configuration name='myElement']";
866 final String string = configuration.toString();
867 assertEquals( expected, string );
868 }
869
870 public void testToStringWithAttributes()
871 throws Exception
872 {
873 final DefaultConfiguration configuration =
874 new DefaultConfiguration( "myElement", "file.xml:20", "" );
875 configuration.setAttribute( "key", "value" );
876 final Map attributeMap = configuration.getAttributeMap();
877
878 final String expected =
879 "[Configuration name='myElement' attributes=" + attributeMap + "]";
880 final String string = configuration.toString();
881 assertEquals( expected, string );
882 }
883 }