1 23 24 29 30 31 package com.sun.enterprise.admin.dottedname; 32 33 import java.util.Collections ; 34 import java.util.HashSet ; 35 import java.util.Set ; 36 import java.util.Iterator ; 37 38 import javax.management.MBeanServer ; 39 import javax.management.ObjectName ; 40 import javax.management.MBeanInfo ; 41 import javax.management.MBeanServerConnection ; 42 import javax.management.AttributeNotFoundException ; 43 import javax.management.MBeanServerFactory ; 44 import javax.management.JMException ; 45 import javax.management.Attribute ; 46 import javax.management.AttributeList ; 47 48 import com.sun.enterprise.admin.mbeans.DottedNameGetSetMBeanImpl; 49 import com.sun.enterprise.admin.dottedname.DottedNamePropertySupport; 50 import com.sun.enterprise.admin.util.ArrayConversion; 51 52 53 54 public final class DottedNameGetSetMBeanImplTest extends junit.framework.TestCase 55 { 56 MBeanServer mServer; 57 58 DottedNameRegistry mRegistry; 59 DottedNameRegistry mMonitoringRegistry; 60 DottedNameGetSetMBean mGetSetMBean; 61 62 public 63 DottedNameGetSetMBeanImplTest( ) 64 { 65 } 66 67 68 70 private static final String DOMAIN = DottedNameAliasSupport.DOMAIN_SCOPE; 71 private static final String SERVER_NAME_BASE = "server"; 72 private static final String CONFIG_SUFFIX = "-config"; 73 private static final String TESTEE_OBJECTNAME_BASE = "Test:name=testee"; 74 private static final int NUM_SERVERS = 2; 75 76 static private String [] DOMAIN_SUBPARTS = (String [])ArrayConversion.setToArray( 77 DottedNameAliasSupport.DOMAIN_PARTS, new String [ DottedNameAliasSupport.DOMAIN_PARTS.size() ] ); 78 79 private static final int NUM_DOMAIN_SUBPARTS = DOMAIN_SUBPARTS.length; 80 81 private static final String SIMPLE = "simple"; 82 private static final String SIMPLE_NAME = SIMPLE; 83 84 85 private static final char BACKSLASH = '\\'; 86 87 private static final String FUNKY_DOTTED_NAME = "test" + BACKSLASH + BACKSLASH + 90 BACKSLASH + "."; 91 private static final String FUNKY_ID = "funky"; 92 93 96 static private class StubbedServerInfo implements DottedNameServerInfo 97 { 98 public 99 StubbedServerInfo() 100 { 101 } 102 103 private static final Set SERVER_NAME_SET = initServerNames( NUM_SERVERS ); 104 private static final Set CONFIG_NAME_SET = initConfigNames( NUM_SERVERS ); 105 106 private static Set 107 initServerNames( int numNames ) 108 { 109 final HashSet s = new HashSet (); 110 111 for( int i = 0; i < numNames; ++i ) 113 { 114 s.add( getServerDottedName( "" + i ) ); 115 } 116 117 return( Collections.unmodifiableSet( s ) ); 118 } 119 120 private static Set 121 initConfigNames( int numNames ) 122 { 123 final HashSet s = new HashSet (); 124 125 for( int i = 0; i < numNames; ++i ) 127 { 128 s.add( getConfigDottedName( "" + i ) ); 129 } 130 131 return( Collections.unmodifiableSet( s ) ); 132 } 133 134 public Set 135 getServerNames() 136 { 137 return( SERVER_NAME_SET ); 138 } 139 140 public Set 141 getConfigNames() 142 { 143 return( CONFIG_NAME_SET ); 144 } 145 146 public String 147 getConfigNameForServer( String serverName ) 148 throws DottedNameServerInfo.UnavailableException 149 { 150 if ( SERVER_NAME_SET.contains( serverName ) ) 151 { 152 return( serverName + CONFIG_SUFFIX ); 153 } 154 155 throw new DottedNameServerInfo.UnavailableException( "" ); 156 } 157 158 public String [] 159 getServerNamesForConfig( String configName ) 160 throws DottedNameServerInfo.UnavailableException 161 { 162 final java.util.Iterator iter = getServerNames().iterator(); 163 final java.util.ArrayList namesOut = new java.util.ArrayList (); 164 165 while ( iter.hasNext() ) 166 { 167 final String serverName = (String )iter.next(); 168 169 if ( configName.equals( getConfigNameForServer( serverName ) ) ) 170 { 171 namesOut.add( serverName ); 172 } 173 } 174 175 final String [] namesOutArray = new String [ namesOut.size() ]; 176 namesOut.toArray( namesOutArray ); 177 178 return( namesOutArray ); 179 } 180 } 181 182 184 188 static private class HookedDottedNameGetSetMBeanImpl 189 extends DottedNameGetSetMBeanImpl 190 implements DottedNameGetSetMBean 191 { 192 public 193 HookedDottedNameGetSetMBeanImpl( 194 final MBeanServerConnection conn, 195 final DottedNameRegistry registry, 196 final DottedNameRegistry monitoringRegistry ) 197 throws Exception 198 { 199 super( conn, registry, monitoringRegistry ); 200 201 DottedNameLogger.getInstance().setLevel( java.util.logging.Level.SEVERE ); 203 } 204 205 206 protected DottedNameServerInfo 207 createServerInfo( MBeanServerConnection conn ) 208 { 209 return( new StubbedServerInfo( ) ); 210 } 211 212 } 213 214 216 217 219 static private TesteeMBean 220 createTestee() 221 { 222 final TesteeMBean testee = new Testee(); 223 224 return( testee ); 225 } 226 227 private static String 228 getServerDottedName( String id ) 229 { 230 return( SERVER_NAME_BASE + id ); 231 } 232 233 private static String 234 getMonitoringDottedName( String id ) 235 { 236 return( getServerDottedName( id ) ); 237 } 238 239 private static String 240 getConfigDottedName( String id ) 241 { 242 return( getServerDottedName( id ) + CONFIG_SUFFIX ); 243 } 244 245 246 ObjectName 247 registerAndAddTestee( 248 final Object mbean, 249 final String dottedName, 250 final String id, 251 final String category, 252 DottedNameRegistry registry ) 253 throws JMException 254 { 255 final ObjectName objectName = new ObjectName ( TESTEE_OBJECTNAME_BASE + 256 ",id=" + id + 257 ",category=" + category ); 258 259 mServer.registerMBean( mbean, objectName ); 260 261 registry.add( dottedName, objectName ); 262 assert( registry.dottedNameToObjectName( dottedName ) == objectName ); 263 264 return( objectName ); 265 } 266 267 ObjectName 268 registerAndAddTestee( 269 final String dottedName, 270 final String id, 271 final String category, 272 DottedNameRegistry registry ) 273 throws JMException 274 { 275 final ObjectName objectName = 276 registerAndAddTestee( createTestee(), dottedName, id, category, registry ); 277 278 return( objectName ); 279 } 280 281 final String CATEGORY_CONFIG = "config"; 282 final String CATEGORY_MONITORING = "monitoring"; 283 final String CATEGORY_SPECIAL = "special"; 284 285 public void 286 setUp() 287 throws Exception 288 { 289 290 mServer = MBeanServerFactory.newMBeanServer( "" + System.currentTimeMillis() ); 291 292 mRegistry = new DottedNameRegistry1To1Impl(); 293 mMonitoringRegistry = new DottedNameRegistry1To1Impl(); 294 295 mGetSetMBean = new HookedDottedNameGetSetMBeanImpl( mServer, mRegistry, mMonitoringRegistry ); 296 mServer.registerMBean( mGetSetMBean, new ObjectName ( ":name=get-set-testee" ) ); 297 298 299 302 for( int i = 0; i < NUM_SERVERS; ++i ) 303 { 304 final String id = "" + i; 305 final String dottedName = getConfigDottedName( id ); 306 307 registerAndAddTestee( dottedName, id, CATEGORY_CONFIG, mRegistry ); 308 } 309 final ObjectName on = registerAndAddTestee( DOMAIN, DOMAIN, CATEGORY_CONFIG, mRegistry ); 311 for( int i = 0; i < DOMAIN_SUBPARTS.length; ++i ) 312 { 313 final String part = DOMAIN_SUBPARTS[ i ]; 314 315 registerAndAddTestee( DOMAIN + "." + part, part, CATEGORY_CONFIG, mRegistry ); 316 } 317 318 319 321 324 for( int i = 0; i < NUM_SERVERS; ++i ) 325 { 326 final String id = "" + i; 327 final String dottedName = getMonitoringDottedName( id ); 328 329 registerAndAddTestee( dottedName, id, CATEGORY_MONITORING, mMonitoringRegistry); 330 } 331 registerAndAddTestee( DOMAIN, 333 DOMAIN, CATEGORY_MONITORING, mMonitoringRegistry); 334 335 SIMPLE_OBJECT_NAME = registerAndAddTestee( new MonitoringTestee(), SIMPLE_NAME, 337 SIMPLE, CATEGORY_MONITORING, mMonitoringRegistry); 338 } 339 340 ObjectName SIMPLE_OBJECT_NAME = null; 341 342 static void 343 dm( Object o ) 344 { 345 System.out.println( o.toString() ); 346 } 347 348 public void 349 tearDown() 350 { 351 mServer = null; 352 } 353 354 private static String 355 valueName( String prefix, String valueName ) 356 { 357 return( prefix + "." + valueName ); 358 } 359 360 Attribute 361 getAttribute( String name ) 362 { 363 final Object result = mGetSetMBean.dottedNameGet( name ); 364 365 if ( result instanceof Exception ) 366 { 367 ((Exception )result).printStackTrace(); 368 } 369 370 assert( result instanceof Attribute ): "expecting Attribute, got " + result.getClass().getName(); 371 return( (Attribute )result ); 372 } 373 374 private static final String PRIMARY_TESTEE = getServerDottedName( "0" ); 375 static String 376 testeeValueName( String name ) 377 { 378 return( PRIMARY_TESTEE + "." + name ); 379 } 380 381 382 383 Attribute 384 getMonitoringAttribute( String name ) 385 { 386 final Object result = mGetSetMBean.dottedNameMonitoringGet( name ); 387 388 assert( result instanceof Attribute ) : 389 "expecting single Attribute, got " + result.getClass().getName(); 390 return( (Attribute )result ); 391 } 392 393 public void 394 testGetchar() 395 { 396 final String dn = testeeValueName( "char" ); 397 assertEquals( getAttribute( dn ), new Attribute ( dn, new Character ( 'c' ) ) ); 398 } 399 400 401 public void 402 testGetbyte() 403 { 404 final String dn = testeeValueName( "byte" ); 405 assertEquals( getAttribute( dn ), new Attribute ( dn, new Byte ( (byte)0 ) ) ); 406 } 407 408 public void 409 testGetshort() 410 { 411 final String dn = testeeValueName( "short" ); 412 assertEquals( getAttribute( dn ), new Attribute ( dn, new Short ( (short)0 ) ) ); 413 } 414 415 public void 416 testGetint() throws Exception 417 { 418 final String dn = testeeValueName( "int" ); 419 assertEquals( getAttribute( dn ), new Attribute ( dn, new Integer ( 0 ) ) ); 420 } 421 422 public void 423 testGetlong() throws Exception 424 { 425 final String dn = testeeValueName( "long" ); 426 assertEquals( getAttribute( dn ), new Attribute ( dn, new Long ( 0 ) ) ); 427 } 428 429 public void 430 testGetfloat() throws Exception 431 { 432 final String dn = testeeValueName( "float" ); 433 assertEquals( getAttribute( dn ), new Attribute ( dn, new Float ( 0.0 ) ) ); 434 } 435 436 public void 437 testGetdouble() throws Exception 438 { 439 final String dn = testeeValueName( "double" ); 440 assertEquals( getAttribute( dn ), new Attribute ( dn, new Double ( 0.0 ) ) ); 441 } 442 443 444 public void 445 testGetString()throws Exception 446 { 447 final String dn = testeeValueName( "String" ); 448 assertEquals( getAttribute( dn ), new Attribute ( dn, "" ) ); 449 } 450 451 public void 452 testGetStringArray()throws Exception 453 { 454 final String dn = testeeValueName( "StringArray" ); 455 456 final Attribute attr = getAttribute( dn ); 457 assertEquals( 0, ((String [])attr.getValue()).length ); 458 } 459 460 public void 461 testGetWild()throws Exception 462 { 463 final Attribute [] attrs = (Attribute [])mGetSetMBean.dottedNameGet( "*.StringArray" ); 464 465 assertEquals( NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS, attrs.length ); 467 } 468 469 public void 470 testGetWildProperty()throws Exception 471 { 472 final Attribute [] attrs = (Attribute [])mGetSetMBean.dottedNameGet( PRIMARY_TESTEE + ".property.*" ); 473 assertEquals( 1, attrs.length ); 474 } 475 static String 476 attributeToString( final Attribute attr )throws Exception 477 { 478 return( attr.getName() + " = " + attr.getValue().toString() ); 479 } 480 static String 481 attributeListToString( final AttributeList attrs )throws Exception 482 { 483 final StringBuffer buf = new StringBuffer (); 484 485 for( int i = 0; i < attrs.size(); ++i ) 486 { 487 buf.append( attributeToString( (Attribute )attrs.get( i ) ) ); 488 buf.append( "\n" ); 489 } 490 return( buf.toString() ); 491 } 492 493 String 494 arrayToString( Object [] a )throws Exception 495 { 496 final StringBuffer buf = new StringBuffer (); 497 498 buf.append( "{" ); 499 for( int i = 0; i < a.length; ++i ) 500 { 501 buf.append( a[ i ].toString() ); 502 buf.append( ", " ); 503 } 504 buf.append( "}" ); 505 506 return( buf.toString() ); 507 } 508 509 public void 510 testServerAliasIntoDomain()throws Exception 511 { 512 final String target = getServerDottedName( "0" ) + "." + DOMAIN_SUBPARTS[ 0 ]; 514 515 getAttribute( target + ".int" ); 516 } 517 518 public synchronized void 519 testWildcardGetAll() 520 { 521 final Attribute [] list1 = (Attribute [])mGetSetMBean.dottedNameGet( "*" ); 522 final Attribute [] list2 = (Attribute [])mGetSetMBean.dottedNameGet( "*.*" ); 523 final Attribute [] list3 = (Attribute [])mGetSetMBean.dottedNameGet( "***.***" ); 524 final Attribute [] list4 = (Attribute [])mGetSetMBean.dottedNameGet( "**********.*" ); 525 526 final int expectedSize = list1.length; 527 assert( expectedSize != 0 ); 528 assertEquals( expectedSize, list2.length ); 529 assertEquals( expectedSize, list3.length ); 530 assertEquals( expectedSize, list4.length ); 531 } 532 533 534 public synchronized void 535 testWildcardMonitoringGetAll() 536 { 537 final Attribute [] list1 = (Attribute [])mGetSetMBean.dottedNameMonitoringGet( "*" ); 538 final Attribute [] list2 = (Attribute [])mGetSetMBean.dottedNameMonitoringGet( "*.*" ); 539 final Attribute [] list3 = (Attribute [])mGetSetMBean.dottedNameMonitoringGet( "***.***" ); 540 final Attribute [] list4 = (Attribute [])mGetSetMBean.dottedNameMonitoringGet( "**********.*" ); 541 542 final int expectedSize = list1.length; 543 assert( expectedSize != 0 ); 544 assertEquals( expectedSize, list2.length ); 545 assertEquals( expectedSize, list3.length ); 546 assertEquals( expectedSize, list4.length ); 547 } 548 549 550 public synchronized void 551 testWildcardGetAllMonitor() 552 { 553 final Attribute [] list = (Attribute [])mGetSetMBean.dottedNameMonitoringGet( "*" ); 554 assert( list.length != 0 ); 555 } 556 557 public synchronized void 558 testNoProperties() throws Exception 559 { 560 mServer.getMBeanInfo(SIMPLE_OBJECT_NAME ); 561 final Object result = mGetSetMBean.dottedNameMonitoringGet( SIMPLE + ".property.foo" ); 563 564 assert( result instanceof AttributeNotFoundException ) : 565 "expected AttributeNotFoundException, got " + result.getClass().getName() + 566 " at "; 567 } 568 569 public void 570 testWildcardListEmpty() 571 { 572 assert( mGetSetMBean.dottedNameList( new String [ 0 ] ).length != 0 ); 573 } 574 575 public synchronized void 576 testWildcardListAll() 577 { 578 final int length1 = dottedNameList( "*" ).length; 579 580 assert( length1 != 0 ); 581 } 582 583 public synchronized void 584 testWildcardMonitoringListAll() 585 { 586 assert( dottedNameMonitoringList( "*" ).length != 0 ); 587 } 588 589 public void 590 testWildcardAllGetsOnlyServers() 591 { 592 final String [] names = dottedNameList( "*" ); 594 595 final Set serverNames = new StubbedServerInfo().getServerNames(); 596 for( int i = 0; i < names.length; ++i ) 597 { 598 final DottedName dn = DottedNameFactory.getInstance().get( names[ i ] ); 599 600 assert( serverNames.contains( dn.getScope() ) ); 601 } 602 } 603 604 public void 605 testDomainGetsOnlyDomain() 606 { 607 final String [] names = dottedNameList( "domain*" ); 609 610 for( int i = 0; i < names.length; ++i ) 611 { 612 final DottedName dn = DottedNameFactory.getInstance().get( names[ i ] ); 613 614 assertEquals( dn.getScope(), DottedNameAliasSupport.DOMAIN_SCOPE ); 615 } 616 } 617 618 public void 619 testConfigGetsOnlyConfig() 620 { 621 final String [] names = dottedNameList( getConfigDottedName( "0" ) + "*" ); 623 624 for( int i = 0; i < names.length; ++i ) 625 { 626 final DottedName dn = DottedNameFactory.getInstance().get( names[ i ] ); 627 628 assertEquals( dn.getScope(), getConfigDottedName( "0" ) ); 629 } 630 } 631 632 633 public void 634 testGetWildAttr() 635 { 636 Attribute [] attrs = (Attribute [])mGetSetMBean.dottedNameGet( "*.StringArray*" ); 637 640 assertEquals( NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS, attrs.length ); 641 642 attrs = (Attribute [])mGetSetMBean.dottedNameGet("*.*int*" ); 643 assertEquals( NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS, attrs.length ); 644 } 645 646 public void 647 testGetWildAttrSingleMBean() 648 { 649 final Attribute [] attrs = 651 (Attribute [])mGetSetMBean.dottedNameGet( PRIMARY_TESTEE + ".*" ); 652 653 assertEquals( 17 + 1 + 1, attrs.length ); 654 } 655 656 public void 657 testMultiGet() 658 { 659 final String [] params = new String [] 660 { 661 testeeValueName( "char" ), 662 testeeValueName( "int" ), 663 testeeValueName( "float" ), 664 testeeValueName( "Double" ), 665 }; 666 667 final Attribute [] attrs = (Attribute [])mGetSetMBean.dottedNameGet( params ); 668 669 assertEquals( params.length, attrs.length ); 670 for( int i = 0; i < attrs.length; ++i ) 671 { 672 assert( attrs[ i ] instanceof Attribute ); 673 } 674 } 675 676 Attribute 677 find( Object [] attrs, String name ) 678 { 679 Attribute attr = null; 680 681 final int size = attrs.length; 682 for( int i = 0; i < size; ++i ) 683 { 684 final Attribute candidate = (Attribute )attrs[ i ]; 685 686 if ( candidate.getName().equals( name ) ) 687 { 688 attr = candidate; 689 break; 690 } 691 } 692 return( attr ); 693 } 694 695 public synchronized void 696 testMultiSet() 697 { 698 final String [] params = new String [] 699 { 700 testeeValueName( "int" ) + "=99", 701 testeeValueName( "char" ) + "=x", 702 testeeValueName( "String" ) + "=9.999", 703 testeeValueName( "Double" ) + "=9.999", 704 }; 705 706 final Object [] attrs = mGetSetMBean.dottedNameSet( params ); 707 assertEquals( params.length, attrs.length ); 708 709 assertEquals( new Attribute ( testeeValueName( "int" ), new Integer ( 99 ) ), 710 find( attrs, testeeValueName( "int" ))); 711 712 713 assertEquals( new Attribute ( testeeValueName( "String" ), "9.999" ), 714 find( attrs, testeeValueName( "String" ))); 715 716 717 assertEquals( new Attribute ( testeeValueName( "char" ), new Character ( 'x' ) ), 718 find( attrs, testeeValueName( "char" ))); 719 720 721 assertEquals( new Attribute ( testeeValueName( "Double" ), new Double ( 9.999 ) ), 722 find( attrs, testeeValueName( "Double" ))); 723 } 724 725 public void 726 testSetWild() 727 { 728 final Object result = mGetSetMBean.dottedNameSet( "*.int=1" ); 729 730 assert( result instanceof Exception ); 731 } 732 733 public void 734 testSetchar() 735 { 736 final String dn = testeeValueName( "char" ); 737 mGetSetMBean.dottedNameSet( new String [] { dn + "=x" } ); 738 assertEquals( getAttribute( dn ), new Attribute ( dn, new Character ( 'x' ) ) ); 739 } 740 741 public void 742 testSetbyte() 743 { 744 final String dn = testeeValueName( "byte" ); 745 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 746 assertEquals( getAttribute( dn ), new Attribute ( dn, new Byte ( (byte)100 ) ) ); 747 } 748 749 public void 750 testSetshort() 751 { 752 final String dn = testeeValueName( "short" ); 753 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 754 assertEquals( getAttribute( dn ), new Attribute ( dn, new Short ( (short)100 ) ) ); 755 } 756 757 public void 758 testSetint() 759 { 760 final String dn = testeeValueName( "int" ); 761 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 762 assertEquals( getAttribute( dn ), new Attribute ( dn, new Integer ( 100 ) ) ); 763 } 764 765 public void 766 testSetlong() 767 { 768 final String dn = testeeValueName( "long" ); 769 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 770 assertEquals( getAttribute( dn ), new Attribute ( dn, new Long ( 100 ) ) ); 771 } 772 773 public void 774 testSetfloat() 775 { 776 final String dn = testeeValueName( "float" ); 777 mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } ); 778 assertEquals( getAttribute( dn ), new Attribute ( dn, new Float ( 99.99 ) ) ); 779 } 780 781 public void 782 testSetdouble() 783 { 784 final String dn = testeeValueName( "double" ); 785 mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } ); 786 assertEquals( getAttribute( dn ), new Attribute ( dn, new Double ( 99.99 ) ) ); 787 } 788 789 790 791 public void 792 testSetCharacter() 793 { 794 final String dn = testeeValueName( "Character" ); 795 mGetSetMBean.dottedNameSet( new String [] { dn + "=x" } ); 796 assertEquals( getAttribute( dn ), new Attribute ( dn, new Character ( 'x' ) ) ); 797 } 798 799 public void 800 testSetByte() 801 { 802 final String dn = testeeValueName( "byte" ); 803 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 804 assertEquals( getAttribute( dn ), new Attribute ( dn, new Byte ( (byte)100 ) ) ); 805 } 806 807 public void 808 testSetShort() 809 { 810 final String dn = testeeValueName( "Short" ); 811 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 812 assertEquals( getAttribute( dn ), new Attribute ( dn, new Short ( (short)100 ) ) ); 813 } 814 815 public void 816 testSetInteger() 817 { 818 final String dn = testeeValueName( "Integer" ); 819 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 820 assertEquals( getAttribute( dn ), new Attribute ( dn, new Integer ( 100 ) ) ); 821 } 822 823 public void 824 testSetLong() 825 { 826 final String dn = testeeValueName( "Long" ); 827 mGetSetMBean.dottedNameSet( new String [] { dn + "=100" } ); 828 assertEquals( getAttribute( dn ), new Attribute ( dn, new Long ( 100 ) ) ); 829 } 830 831 public void 832 testSetFloat() 833 { 834 final String dn = testeeValueName( "Float" ); 835 mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } ); 836 assertEquals( getAttribute( dn ), new Attribute ( dn, new Float ( 99.99 ) ) ); 837 } 838 839 public void 840 testSetDouble() 841 { 842 final String dn = testeeValueName( "Double" ); 843 mGetSetMBean.dottedNameSet( new String [] { dn + "=99.99" } ); 844 assertEquals( getAttribute( dn ), new Attribute ( dn, new Double ( 99.99 ) ) ); 845 } 846 847 848 public void 849 testSetString() 850 { 851 final String dn = testeeValueName( "String" ); 852 mGetSetMBean.dottedNameSet( new String [] { dn + "=hello world" } ); 853 assertEquals( getAttribute( dn ), new Attribute ( dn, "hello world" ) ); 854 } 855 856 public void 857 testSetStringArray() 858 { 859 final String dn = testeeValueName( "StringArray" ); 860 final Attribute result = (Attribute )mGetSetMBean.dottedNameSet( dn + "=hello,there,world" ); 861 862 final Attribute attr = getAttribute( dn ); 863 assertEquals( result, attr ); 864 final String [] values = (String [])attr.getValue(); 865 assertEquals( 3, values.length ); 866 assertEquals( "hello", values[ 0 ] ); 867 assertEquals( "there", values[ 1 ] ); 868 assertEquals( "world", values[ 2 ] ); 869 } 870 871 public void 872 testSetIntegerArray() 873 { 874 final String dn = testeeValueName( "IntegerArray" ); 875 mGetSetMBean.dottedNameSet( dn + "=1,2,3" ); 876 877 final Attribute attr = getAttribute( dn ); 878 final Integer [] values = (Integer [])attr.getValue(); 879 assertEquals( 3, values.length ); 880 assertEquals( new Integer ( 1 ), values[ 0 ] ); 881 assertEquals( new Integer ( 2 ), values[ 1 ] ); 882 assertEquals( new Integer ( 3 ), values[ 2 ] ); 883 } 884 885 public void 886 testGetProperty() 887 { 888 final String dottedName = PRIMARY_TESTEE + "." + 889 DottedNamePropertySupport.getPropertySuffix( Testee.PROPERTY_NAME ); 890 891 final Attribute attr = getAttribute( dottedName ); 892 assertEquals( Testee.PROPERTY_VALUE, attr.getValue() ); 893 } 894 895 public synchronized void 896 testSetProperty() 897 { 898 final String dottedName = PRIMARY_TESTEE + "." + 899 DottedNamePropertySupport.getPropertySuffix( "testProperty" ); 900 901 final String TEST_VALUE = "hello"; 902 903 final Object value = mGetSetMBean.dottedNameSet( dottedName + "=" + TEST_VALUE ); 905 if ( value instanceof Exception ) 906 { 907 ((Exception )value).printStackTrace(); 908 } 909 910 final Attribute attr = (Attribute )value; 911 assertEquals( TEST_VALUE, attr.getValue( ) ); 912 assertEquals( TEST_VALUE, getAttribute( dottedName ).getValue() ); 913 } 914 915 private String [] 916 dottedNameList( String name ) 917 { 918 return( mGetSetMBean.dottedNameList( new String [] { name } ) ); 919 } 920 921 private String [] 922 dottedNameMonitoringList( String name ) 923 { 924 return( mGetSetMBean.dottedNameMonitoringList( new String [] { name } ) ); 925 } 926 927 public void 928 testListAll() 929 { 930 final int required = 932 NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS + 0; 935 936 final String [] names = dottedNameList( "*" ); 937 assertEquals( required, names.length ); 938 } 939 940 public void 941 testListEmpty() 942 { 943 final String [] names = dottedNameList( "" ); 944 assertEquals( 0, names.length ); 945 } 946 947 String 948 setToString( final Set s ) 949 { 950 final Iterator iter = s.iterator(); 951 final StringBuffer buf = new StringBuffer (); 952 953 while ( iter.hasNext() ) 954 { 955 buf.append( (String )iter.next() + "\n" ); 956 } 957 958 return( buf.toString() ); 959 } 960 961 public void 962 testListNoMatch() 963 { 964 assertEquals( 0, dottedNameList( "*foo*" ).length ); 965 } 966 public void 967 testListDomain() 968 { 969 assertEquals( 0, dottedNameList( "*" + DOMAIN + "*" ).length ); 971 assertEquals( 0, dottedNameList( "*" + DOMAIN ).length ); 972 973 assertEquals( 1 + NUM_DOMAIN_SUBPARTS, dottedNameList( DOMAIN + "*" ).length ); 974 } 975 976 public void 977 testListServer() 978 { 979 final int required = NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS; 980 assertEquals( required, dottedNameList( SERVER_NAME_BASE + "*" ).length ); 981 assertEquals( required, dottedNameList( "*" + SERVER_NAME_BASE + "*" ).length ); 982 } 983 984 985 public void 986 testListRecursive() 987 { 988 final int required = 989 NUM_SERVERS + NUM_SERVERS * NUM_DOMAIN_SUBPARTS + 0; 992 993 assertEquals( required, dottedNameList( SERVER_NAME_BASE + "*").length ); 994 } 995 996 public void 997 testListNonRecursive() 998 { 999 assertEquals( NUM_DOMAIN_SUBPARTS, dottedNameList( getServerDottedName( "0" ) ).length ); 1000 assertEquals( NUM_DOMAIN_SUBPARTS, dottedNameList( DOMAIN ).length ); 1001 } 1002 1003 public void 1004 testListNoChildren() 1005 { 1006 assertEquals( 0, dottedNameList( getServerDottedName( "0." + DOMAIN_SUBPARTS[ 0 ] ) ).length ); 1007 assertEquals( 0, dottedNameList( getConfigDottedName( "0" ) ).length ); 1008 } 1009 1010 public void 1011 testListWithChildren() 1012 { 1013 assertEquals( NUM_DOMAIN_SUBPARTS, dottedNameList( DOMAIN + ".*" ).length ); 1014 } 1015 1016 public void 1017 testListWildcardMonitoring() 1018 { 1019 assertEquals( NUM_SERVERS, dottedNameMonitoringList( "server*" ).length ); 1020 } 1021 1022 public void 1023 testAliasingOffForMonitoring() 1024 { 1025 final Object result = mGetSetMBean.dottedNameMonitoringGet( getConfigDottedName( "0" ) + ".*" ); 1026 1027 assert( result instanceof Attribute [] ); 1028 1029 assertEquals( 0, dottedNameMonitoringList( "*config*" ).length ); 1030 } 1031 1032 public void 1033 testListNonExistent() 1034 { 1035 assertEquals( 0, dottedNameList( "foo" ).length ); 1036 assertEquals( 0, dottedNameList( "/" ).length ); 1037 } 1038 1039 public void 1040 testMonitoringGet() 1041 { 1042 final String dn = DOMAIN + ".int"; 1043 assertEquals( getMonitoringAttribute( dn ), new Attribute ( dn, new Integer ( 0 ) ) ); 1044 } 1045 1046 public void 1047 testFunkyName() throws JMException 1048 { 1049 registerAndAddTestee( FUNKY_DOTTED_NAME, FUNKY_ID, CATEGORY_SPECIAL, mRegistry); 1052 } 1053 1054} 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | Popular Tags |