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

This page was automatically generated by Maven