1 23 24 29 30 package com.sun.cli.jmx.support; 31 32 import java.lang.reflect.Array ; 33 import java.lang.reflect.Method ; 34 35 import java.math.BigDecimal ; 36 import java.math.BigInteger ; 37 import java.lang.Number ; 38 39 import java.net.URL ; 40 import java.net.URI ; 41 42 import javax.management.*; 43 44 import com.sun.cli.util.ClassUtil; 45 import com.sun.cli.util.stringifier.ArrayStringifier; 46 import com.sun.cli.util.stringifier.SmartStringifier; 47 48 import com.sun.cli.jmx.support.CLISupportMBeanProxy; 49 import com.sun.cli.jmx.support.InspectRequest; 50 import com.sun.cli.jmx.support.InspectResult; 51 import com.sun.cli.jmx.support.InvokeResult; 52 import com.sun.cli.jmx.support.ResultsForGetSet; 53 import com.sun.cli.util.ClassUtil; 54 import com.sun.cli.util.ArrayConversion; 55 56 import com.sun.cli.jmx.test.CLISupportTestee; 57 import com.sun.cli.jmx.test.CLISupportSimpleTestee; 58 59 60 public final class CLISupportMBeanImplTest extends junit.framework.TestCase 61 { 62 MBeanServer mServer; 63 CLISupportMBeanProxy mProxy; 64 65 private final static String ALIAS_BASE = "test-alias-"; 66 private final static String CLI_TEST_ALIAS_NAME = ALIAS_BASE + "generic-test"; 67 68 69 private final static String ALL_ALIAS = "all"; 70 private final static String SIMPLE_TESTEE_ALIAS = "StdTestee"; 71 private final static String SUPPORT_TESTEE_ALIAS = "SupportTestee"; 72 73 private final static String [] ALL_TARGETS = new String [] { ALL_ALIAS }; 74 private final static String [] SIMPLE_TESTEE_TARGET = new String [] { SIMPLE_TESTEE_ALIAS }; 75 private final static String [] SUPPORT_TESTEE_TARGET = new String [] { SUPPORT_TESTEE_ALIAS }; 76 77 78 public 79 CLISupportMBeanImplTest( ) 80 { 81 } 82 83 private class TestFailedException extends Exception 84 { 85 TestFailedException( String msg ) 86 { 87 super( msg ); 88 } 89 } 90 91 92 public void 93 testPropertiesOnly( ) throws Exception 94 { 95 final String operationName = "testPropertiesOnly"; 96 final String argString = "foo=bar"; 97 final InvokeResult [] results = (InvokeResult []) 98 mProxy.mbeanInvoke( operationName, argString, SUPPORT_TESTEE_TARGET ); 99 100 final InvokeResult result = results[ 0 ]; 101 102 if ( result.getResultType() != InvokeResult.SUCCESS ) 103 { 104 throw new TestFailedException( "invocation failed: " + operationName + "(" + argString + ")" ); 105 } 106 107 } 108 109 110 private final static String ARGS_11 = 111 "hello,true,x,99,999,9999,999999,99.9999,999.999999,12345678910,12345678910.12345678910"; 112 113 public void 114 test11ObjectArgs( ) throws Exception 115 { 116 invokeSimpleTestee( "test11ObjectArgs", ARGS_11 ); 117 } 118 119 public void 120 test11MixedArgs( ) throws Exception 121 { 122 invokeSimpleTestee( "test11MixedArgs", ARGS_11 ); 123 } 124 125 private Object 126 doTest( final String operationName, final String arg ) 127 throws Exception 128 { 129 final InvokeResult invokeResult = invokeSimpleTestee( operationName, arg ); 130 131 if ( invokeResult.getResultType() != InvokeResult.SUCCESS ) 132 { 133 fail( "invocation failed for " + operationName + "(" + arg + ")" ); 134 } 135 136 return( invokeResult.mResult ); 137 } 138 139 private void 140 doStringTest( final String arg, final String expected) 141 throws Exception 142 { 143 final String result = (String )doTest( "testString", arg ); 144 assertEquals( expected, result ); 145 } 146 147 private void 148 doObjectTest( final String arg, final Object expected) 149 throws Exception 150 { 151 final Object result = doTest( "testObject", arg ); 152 assertEquals( expected, result ); 153 } 154 155 private void 156 doIntegerTest( final String arg, final Object expected) 157 throws Exception 158 { 159 final Integer result = (Integer )doTest( "testInteger", arg ); 160 assertEquals( expected, result ); 161 } 162 163 private void 164 checkEqualArray( final Object [] expected, final Object [] actual ) 165 { 166 assertEquals( expected.getClass(), actual.getClass() ); 167 assertEquals( expected.length, actual.length ); 168 169 for( int i = 0; i < expected.length; ++i ) 170 { 171 if ( expected[ i ] == null ) 172 { 173 assertEquals( null, actual[ i ] ); 174 } 175 else 176 { 177 assertEquals( expected[ i ].getClass(), actual[ i ].getClass() ); 178 179 if ( ClassUtil.objectIsArray( expected[ i ] ) ) 180 { 181 if ( ClassUtil.objectIsPrimitiveArray( expected[ i ] ) ) 182 { 183 final Object [] e = ArrayConversion.toAppropriateType( expected[ i ] ); 184 final Object [] a = ArrayConversion.toAppropriateType( actual[ i ] ); 185 186 checkEqualArray( e, a ); 187 } 188 else 189 { 190 checkEqualArray( (Object [])expected[ i ], (Object [])actual[ i ] ); 191 } 192 } 193 else 194 { 195 assertEquals( expected[ i ], actual[ i ] ); 196 } 197 } 198 } 199 } 200 201 private void 202 doObjectArrayTest( final String arg, final Object [] expected) 203 throws Exception 204 { 205 final Object [] result = (Object [])doTest( "testObjectArray", arg ); 206 checkEqualArray( expected, result ); 207 } 208 209 210 211 public void 212 testEmptyQuotedString( ) throws Exception 213 { 214 doStringTest( "\"\"", ""); 215 } 216 217 public void 218 testEmptyQuotedStringWithCast( ) throws Exception 219 { 220 doStringTest( "(String)\"\"", ""); 221 } 222 223 public void 224 testEmptyStringWithCast( ) throws Exception 225 { 226 doStringTest( "(String)", ""); 227 } 228 229 public void 230 testEscapedString( ) throws Exception 231 { 232 final String result = "\"\n\r\t\""; 233 234 doStringTest( "\\\"\\n\\r\\t\\\"", result); 235 } 236 237 238 public void 239 testNumericStringNoCast( ) throws Exception 240 { 241 doStringTest( "10", "10"); 242 } 243 244 public void 245 testStringContaining_word_null( ) throws Exception 246 { 247 doStringTest( "\"null\"", "null"); 248 } 249 250 public void 251 testNullStringWithoutCast( ) throws Exception 252 { 253 doStringTest( "null", null); 254 } 255 256 public void 257 testNullStringWithCast( ) throws Exception 258 { 259 doStringTest( "(String)null", null); 260 } 261 262 public void 263 testNullObjectWithCast( ) throws Exception 264 { 265 doObjectTest( "(Object)null", null); 266 } 267 268 public void 269 testNullObjectWithoutCast( ) throws Exception 270 { 271 doObjectTest( "null", null); 272 } 273 274 public void 275 testStringAsObject( ) throws Exception 276 { 277 doObjectTest( "(Object)hello", "hello"); 278 } 279 280 public void 281 testNullIntegerWithCast( ) throws Exception 282 { 283 doIntegerTest( "(Integer)null", null); 284 } 285 286 public void 287 testInteger( ) throws Exception 288 { 289 doIntegerTest( "(Integer)10", new Integer ( 10 )); 290 doIntegerTest( "-10", new Integer ( -10 )); 291 } 292 293 public void 294 testNullIntegerWithoutCast( ) throws Exception 295 { 296 doIntegerTest( "null", null); 297 } 298 299 300 public void 301 testEmptyArray( ) throws Exception 302 { 303 doObjectArrayTest( "{}", new Object [ 0 ]); 304 } 305 306 public void 307 testEmptyObjectArrayWithCast( ) throws Exception 308 { 309 doObjectArrayTest( "(Object){}", new Object [ 0 ]); 310 doObjectArrayTest( "(String){}", new String [ 0 ]); 311 doObjectArrayTest( "(Character){}", new Character [ 0 ]); 312 doObjectArrayTest( "(Boolean){}", new Boolean [ 0 ]); 313 doObjectArrayTest( "(Byte){}", new Byte [ 0 ]); 314 doObjectArrayTest( "(Short){}", new Short [ 0 ]); 315 doObjectArrayTest( "(Integer){}", new Integer [ 0 ]); 316 doObjectArrayTest( "(Long){}", new Long [ 0 ]); 317 doObjectArrayTest( "(Float){}", new Float [ 0 ]); 318 doObjectArrayTest( "(Double){}", new Double [ 0 ]); 319 doObjectArrayTest( "(BigInteger){}", new BigInteger [ 0 ]); 320 doObjectArrayTest( "(BigDecimal){}", new BigDecimal [ 0 ]); 321 doObjectArrayTest( "(Number){}", new Number [ 0 ]); 322 } 323 324 public void 325 testArrayWithEmptyElements() 326 throws Exception 327 { 328 final String s = new String ( "" ); 329 330 doObjectArrayTest( "(String){,,,}", new String [] { s,s,s,s } ); 331 doObjectArrayTest( "{,,,}", new Object [] { s,s,s,s } ); 332 } 333 334 public void 335 testArrayWithNullElements() 336 throws Exception 337 { 338 doObjectArrayTest( "{null,null}", new Object [] { null, null } ); 339 340 doObjectArrayTest( "{(String)null,(Object)null}", new Object [] { null, null } ); 341 } 342 343 344 public void 345 testArrayWithCastAndElementsWithCast() 346 throws Exception 347 { 348 doObjectArrayTest( "(Number){(BigInteger)0,(BigDecimal)10.0}", 349 new Number [] { new BigInteger ( "0" ), new BigDecimal ( "10.0" ) } ); 350 351 final String input = "(Number){(String)hello}"; 353 354 final InvokeResult invokeResult = invokeSimpleTestee( "testObjectArray", input ); 355 if ( invokeResult.getResultType() == InvokeResult.SUCCESS ) 356 { 357 fail( "expected this construct to fail: " + input ); 358 } 359 } 360 361 public void 362 testMixedArrayWithCasts() 363 throws Exception 364 { 365 doObjectArrayTest( 366 "{(Character)c,(Boolean)true,(Byte)99," + 367 "(Short)-999,(Integer)0,(Long)99999," + 368 "(BigInteger)99999999999999999999999999," + 369 "(BigDecimal)123456789123456789.123456789123456789," + 370 "\"hello\",(String)hello,hello,}", 371 new Object [] 372 { 373 new Character ( 'c' ), 374 new Boolean ( "true" ), 375 new Byte ( (byte)99 ), 376 new Short ( (short)-999 ), 377 new Integer ( 0 ), 378 new Long ( 99999 ), 379 new BigInteger ( "99999999999999999999999999" ), 380 new BigDecimal ( "123456789123456789.123456789123456789" ), 381 "hello", 382 "hello", 383 "hello", 384 "", 385 } 386 ); 387 } 388 389 public void 390 testNullIllegalForSimpleType( ) throws Exception 391 { 392 try 393 { 394 final InvokeResult result = invokeSimpleTestee( "test_int", "null" ); 395 if ( result.getResultType() == InvokeResult.SUCCESS ) 396 { 397 fail( "expected failure trying to pass 'null' for an int" ); 398 } 399 } 400 catch( Exception e ) 401 { 402 } 403 } 404 405 public void 406 testCaseSensitivity() 407 throws Exception 408 { 409 InvokeResult result; 410 411 result = invokeSimpleTestee( "testcasesensitivity1", null ); 412 assertEquals( "testcasesensitivity1", result.mResult ); 413 414 result = invokeSimpleTestee( "testCASESENSITIVITY1", null ); 415 assertEquals( "testCASESENSITIVITY1", result.mResult ); 416 417 result = invokeSimpleTestee( "testCaseSensitivity1", null ); 418 assertEquals( "testCaseSensitivity1", result.mResult ); 419 420 try 421 { 422 result = invokeSimpleTestee( "testcaseSensitivity1", null ); 423 if ( result.getResultType() == InvokeResult.SUCCESS ) 424 { 425 fail( "expected ambiguous match to prevent execution of method: " + result.mResult ); 426 } 427 } 428 catch( Exception e ) 429 { 430 } 432 } 433 434 public void 435 testCaseInsensitivity() 436 throws Exception 437 { 438 final InvokeResult result = invokeSimpleTestee( "testcasesensitivity2", null ); 439 assertEquals( "testCaseSensitivity2", result.mResult ); 440 } 441 442 443 public void 444 testURL() 445 throws Exception 446 { 447 final URL input = new URL ( "http://www.sun.com?foo=bar&bar=foo" ); 448 final InvokeResult result = invokeSimpleTestee( "testURL", input.toString() ); 449 assertEquals( input, result.mResult ); 450 } 451 452 public void 453 testURI() 454 throws Exception 455 { 456 final URI input = new URI ( "service:jmx:jmxmp://localhost:" ); 457 final InvokeResult result = invokeSimpleTestee( "testURI", input.toString() ); 458 assertEquals( input, result.mResult ); 459 } 460 461 462 463 500 501 502 private InvokeResult [] 503 invoke( String operationName, String args, String [] targets ) 504 throws Exception 505 { 506 final InvokeResult [] results = mProxy.mbeanInvoke( operationName, args, targets ); 507 508 return( results ); 509 } 510 511 private InvokeResult 512 invokeSupportTestee( String operationName, String args) 513 throws Exception 514 { 515 final InvokeResult [] results = invoke( operationName, args, SUPPORT_TESTEE_TARGET ); 516 assert( results.length == 1 ); 517 518 return( results[ 0 ] ); 519 } 520 521 private InvokeResult 522 invokeSimpleTestee( String operationName, String args) 523 throws Exception 524 { 525 final InvokeResult [] results = invoke( operationName, args, SIMPLE_TESTEE_TARGET ); 526 assert( results.length == 1 ); 527 528 return( results[ 0 ] ); 529 } 530 531 public void 532 testNamedInvoke( ) throws Exception 533 { 534 invokeSupportTestee( "testNamed", "p1=hello" ); 535 536 invokeSupportTestee( "testNamed", "p1=hello,p2=there" ); 537 538 invokeSupportTestee( "testNamed", "p1=hello,p2=there,p3=!!!" ); 539 540 invokeSupportTestee( "testNamed", "p1=hello,p2=there,p3=!!!,p4=foobar" ); 541 } 542 543 545 private String 546 makeArgList( final String [] args ) 547 { 548 final int numArgs = args.length; 549 String result = null; 550 551 if ( numArgs != 0 ) 552 { 553 final StringBuffer buf = new StringBuffer (); 554 555 for( int i = 0; i < numArgs; ++i ) 556 { 557 buf.append( args[ i ] ); 558 buf.append( "," ); 559 } 560 buf.setLength( buf.length() - 1 ); 562 563 result = new String ( buf ) ; 564 } 565 566 return( result ); 567 } 568 569 570 private String 571 getCastType( String type ) 572 throws ClassNotFoundException 573 { 574 String result = type; 575 576 if ( ClassUtil.classnameIsArray( result ) ) 577 { 578 final Class theClass = ClassUtil.getClassFromName(result); 579 580 final Class elementClass = ClassUtil.getInnerArrayElementClass( theClass ); 581 582 result = elementClass.getName(); 583 } 584 585 return( result ); 586 } 587 588 589 590 private InvokeResult.ResultType 591 testOperationGenerically( 592 final boolean namedArgs, 593 final ObjectName targetName, 594 final MBeanOperationInfo operationInfo ) 595 throws Exception 596 { 597 final MBeanParameterInfo [] paramInfos = operationInfo.getSignature(); 598 final int numParams = paramInfos.length; 599 600 final String [] strings = new String [ numParams ]; 601 final String operationName = operationInfo.getName(); 602 603 for( int i = 0; i < numParams; ++i ) 606 { 607 final MBeanParameterInfo paramInfo = paramInfos[ i ]; 608 final String paramType = paramInfos[ i ].getType(); 609 final Class theClass = ClassUtil.getClassFromName( paramType ); 610 611 final Object paramObject = ClassUtil.InstantiateDefault( theClass ); 612 final String paramString = SmartStringifier.toString( paramObject ); 613 final String castString = "(" + getCastType( paramType ) + ")"; 614 615 final String paramName = namedArgs ? (paramInfo.getName() + '=') : ""; 616 617 strings[ i ] = paramName + castString + paramString; 618 } 619 620 final String argString = makeArgList( strings ); 622 623 final String [] args = new String [] { targetName.toString() }; 624 625 final InvokeResult [] results = (InvokeResult [])mProxy.mbeanInvoke( operationName, argString, args ); 626 final InvokeResult result = results[ 0 ]; 627 628 if ( result.getResultType() == InvokeResult.SUCCESS ) 629 { 630 } 632 else 633 { 634 final String paramInfosString = SmartStringifier.toString( paramInfos ); 635 636 result.mThrowable.printStackTrace(); 637 } 638 639 return( result.getResultType() ); 640 } 641 642 static private final Class [] GENERICALLY_TESTABLE_CLASSES = 643 { 644 boolean.class, 645 char.class, 646 byte.class, short.class, int.class, long.class, 647 float.class, double.class, 648 Boolean .class, 649 Character .class, 650 Byte .class, Short .class, Integer .class, Long .class, 651 Float .class, 652 Double .class, 653 Number .class, 654 String .class, 655 Object .class, 656 java.math.BigDecimal .class, 657 java.math.BigInteger .class, 658 java.net.URL .class, 659 java.net.URI .class 660 661 }; 662 private boolean 663 isGenericallyTestableClass( final Class theClass ) 664 throws ClassNotFoundException 665 { 666 boolean isTestable = false; 667 668 Class testClass = theClass; 669 if ( ClassUtil.classIsArray( theClass ) ) 670 { 671 testClass = ClassUtil.getInnerArrayElementClass( theClass ); 673 } 674 675 final Class [] classes = GENERICALLY_TESTABLE_CLASSES; 676 final int numClasses = classes.length; 677 for( int i = 0; i < numClasses; ++i ) 678 { 679 if ( testClass == classes[ i ] ) 680 { 681 isTestable = true; 682 break; 683 } 684 } 685 686 if ( ! isTestable ) 687 { 688 assert( testClass == java.util.Properties .class ); 689 } 690 691 return( isTestable ); 692 } 693 694 private boolean 695 isGenericallyTestable( final MBeanOperationInfo operationInfo ) 696 throws ClassNotFoundException 697 { 698 boolean isTestable = true; 699 700 final MBeanParameterInfo [] paramInfos = operationInfo.getSignature(); 701 final int numParams = paramInfos.length; 702 for( int i = 0; i < numParams; ++i ) 703 { 704 final Class theClass = ClassUtil.getClassFromName( paramInfos[i].getType() ); 705 706 if ( ! isGenericallyTestableClass( theClass ) ) 707 { 708 isTestable = false; 709 break; 710 } 711 } 712 713 return( isTestable ); 714 } 715 716 717 private void 718 testGeneric( boolean namedTest, ObjectName objectName ) throws Exception 719 { 720 final MBeanInfo info = mServer.getMBeanInfo( objectName ); 721 final MBeanOperationInfo [] opInfos = info.getOperations(); 722 723 int notTestedCount = 0; 724 for( int i = 0; i < opInfos.length; ++i ) 725 { 726 try 727 { 728 if ( isGenericallyTestable( opInfos[ i ] ) ) 729 { 730 final InvokeResult.ResultType resultType = 731 testOperationGenerically( namedTest, objectName, opInfos[ i ] ); 732 733 if ( resultType != InvokeResult.SUCCESS ) 734 { 735 fail( "invocation failure on: " + SmartStringifier.toString( opInfos[ i ] ) ); 736 } 737 } 738 else 739 { 740 ++notTestedCount; 741 } 742 } 743 catch( Exception e ) 744 { 745 fail( "FAILURE: " + SmartStringifier.toString( opInfos[ i ] ) ); 746 } 747 } 748 } 749 750 public void 751 testGenericOrdered() 752 throws Exception 753 { 754 final ObjectName [] allObjects = mProxy.mbeanFind( SUPPORT_TESTEE_ALIAS ); 755 assert( allObjects.length == 1 ); 756 757 testGeneric( false, allObjects[ 0 ] ); 758 } 759 760 public void 761 testGenericNamed() 762 throws Exception 763 { 764 final ObjectName [] allObjects = mProxy.mbeanFind( SUPPORT_TESTEE_ALIAS ); 765 assert( allObjects.length == 1 ); 766 767 testGeneric( false, allObjects[ 0 ] ); 768 } 769 770 771 public void 772 testMBeanFind( ) throws Exception 773 { 774 final ObjectName [] results = mProxy.mbeanFind( ALL_TARGETS ); 775 776 assertEquals( 3, results.length ); 777 } 778 779 780 public void 781 testMBeanInspect( ) throws Exception 782 { 783 final InspectRequest request = new InspectRequest(); 784 785 final InspectResult [] results = mProxy.mbeanInspect( request, ALL_TARGETS ); 786 787 assertEquals( 3, results.length ); 788 } 789 790 public void 791 testMBeanGet( ) throws Exception 792 { 793 final ResultsForGetSet [] results = mProxy.mbeanGet( "*", SIMPLE_TESTEE_TARGET ); 794 795 assertEquals( 1, results.length ); 796 assertEquals( 2, results[ 0 ].getAttributes().size() ); 797 } 798 799 public void 800 testMBeanSet( ) throws Exception 801 { 802 final ResultsForGetSet [] results = mProxy.mbeanSet( "NotifMillis=1000", SIMPLE_TESTEE_TARGET ); 803 804 assertEquals( 1, results.length ); 805 assertEquals( 1, results[ 0 ].getAttributes().size() ); 806 807 final AttributeList attrs = mProxy.mbeanGet( "NotifMillis", SIMPLE_TESTEE_TARGET )[ 0 ].getAttributes(); 808 final Attribute expected = new Attribute( "NotifMillis", new Long ( 1000 )); 809 assertEquals( expected, attrs.get( 0 ) ); 810 } 811 812 public void 813 testMBeanCreateDelete( ) throws Exception 814 { 815 final String name = "test:name=testtemp"; 816 final String className = "com.sun.cli.jmx.test.CLISupportSimpleTestee"; 817 818 mProxy.mbeanCreate( name, className, null ); 819 820 ObjectName [] results = mProxy.mbeanFind( new String [] { name } ); 821 assertEquals( 1, results.length ); 822 823 mProxy.mbeanUnregister( name ); 824 results = mProxy.mbeanFind( new String [] { name } ); 825 assertEquals( 0, results.length ); 826 827 828 } 829 830 831 832 private void 833 deleteTestAliases() throws Exception 834 { 835 assert( mProxy != null ); 836 837 final String [] aliases = mProxy.listAliases( false ); 838 assert( aliases != null ); 839 840 for( int i = 0; i < aliases.length; ++i ) 841 { 842 final String name = aliases[ i ]; 843 844 if ( name.startsWith( ALIAS_BASE ) ) 845 { 846 mProxy.deleteAlias( name ); 847 } 848 } 849 } 850 851 852 856 public void 857 testAliases( ) throws Exception 858 { 859 deleteTestAliases(); 860 861 final ObjectName [] names = mProxy.mbeanFind( new String [] { StandardAliases.ALL_ALIAS } ); 863 final int numNames = names.length; 864 865 for( int i = 0; i < numNames; ++i ) 867 { 868 final String aliasName = ALIAS_BASE + (i+1); 869 mProxy.createAlias( aliasName, names[ i ].toString() ); 870 } 871 872 for( int i = 0; i < numNames; ++i ) 874 { 875 final String aliasName = ALIAS_BASE + (i+1); 876 877 final String aliasValue = mProxy.resolveAlias( aliasName ); 878 if ( aliasValue == null ) 879 { 880 fail( "can't resolve alias after creating it: " + aliasName ); 881 } 882 883 if ( ! names[ i ].toString().equals( aliasValue )) 884 { 885 fail( "alias does not resolve to value it was created with: " + aliasName ); 886 } 887 } 888 889 final String ALL_ALIASES_NAME = ALIAS_BASE + "all"; 891 final String [] aliases = mProxy.listAliases( false ); 892 final String allAliases = ArrayStringifier.stringify( aliases, " " ); 893 mProxy.createAlias( ALL_ALIASES_NAME, allAliases ); 894 895 String allAliasesName = ALL_ALIASES_NAME; 897 for( int i = 0; i < 5; ++i ) 898 { 899 mProxy.createAlias( allAliasesName + i, allAliasesName ); 900 allAliasesName = allAliasesName + i; 901 } 902 903 final ObjectName [] resolvedNames = mProxy.resolveTargets( new String [] { allAliasesName } ); 905 if ( resolvedNames.length != numNames ) 907 { 908 fail( "alias resolution produce wrong number of results" ); 909 } 910 911 deleteTestAliases(); 912 } 913 914 915 private void 916 verifySetup( CLISupportMBeanProxy proxy ) throws Exception 917 { 918 final ObjectName [] all = proxy.resolveTargets( ALL_TARGETS ); 920 assert( all.length != 0 ); 921 922 final String [] aliases = proxy.listAliases( false ); 924 assert( aliases.length != 0 ); 925 926 assert( proxy.resolveAlias( ALL_ALIAS ) != null ); 928 assert( proxy.resolveAlias( SIMPLE_TESTEE_ALIAS ) != null ); 929 assert( proxy.resolveAlias( SUPPORT_TESTEE_ALIAS ) != null ); 930 931 932 } 933 934 935 private MBeanServer 936 createAgent( ) 937 { 938 return( MBeanServerFactory.createMBeanServer( "Test" ) ); 939 } 940 941 private void 942 registerMBean( MBeanServer conn, Object mbean, String name ) 943 throws Exception 944 { 945 conn.registerMBean( mbean, new ObjectName( name ) ); 946 } 947 948 private final static CLISupportTestee CLI_SUPPORT_TESTEE = new CLISupportTestee( ); 949 public void 950 setUp() throws Exception 951 { 952 mServer = createAgent( ); 953 954 registerMBean( mServer, CLI_SUPPORT_TESTEE, CLISupportStrings.CLI_SUPPORT_TESTEE_TARGET ); 956 957 registerMBean( mServer, new CLISupportSimpleTestee( ), 958 CLISupportStrings.CLI_SIMPLE_TESTEE_TARGET ); 959 960 final AliasMgr aliasMgr = new AliasMgr( new AliasMgrHashMapImpl() ); 961 aliasMgr.createAlias( ALL_ALIAS, "*" ); 962 aliasMgr.createAlias( SIMPLE_TESTEE_ALIAS, CLISupportStrings.CLI_SIMPLE_TESTEE_TARGET ); 963 aliasMgr.createAlias( SUPPORT_TESTEE_ALIAS, CLISupportStrings.CLI_SUPPORT_TESTEE_TARGET ); 964 965 final CLISupportMBeanImpl cliSupport = new CLISupportMBeanImpl( mServer, aliasMgr ); 966 967 mProxy = new CLISupportMBeanProxy( aliasMgr, cliSupport ); 968 969 verifySetup( mProxy ); 970 } 971 972 public void 973 tearDown() 974 throws Exception 975 { 976 mProxy.mbeanUnregister( mProxy.resolveAlias( SUPPORT_TESTEE_ALIAS ) ); 977 mProxy.mbeanUnregister( mProxy.resolveAlias( SIMPLE_TESTEE_ALIAS ) ); 978 mProxy = null; 979 mServer = null; 980 } 981 982 }; 983 984 | Popular Tags |