Methods Summary |
---|
private void | checkEqualArray(java.lang.Object[] expected, java.lang.Object[] actual)
assertEquals( expected.getClass(), actual.getClass() );
assertEquals( expected.length, actual.length );
for( int i = 0; i < expected.length; ++i )
{
if ( expected[ i ] == null )
{
assertEquals( null, actual[ i ] );
}
else
{
assertEquals( expected[ i ].getClass(), actual[ i ].getClass() );
if ( ClassUtil.objectIsArray( expected[ i ] ) )
{
if ( ClassUtil.objectIsPrimitiveArray( expected[ i ] ) )
{
final Object [] e = ArrayConversion.toAppropriateType( expected[ i ] );
final Object [] a = ArrayConversion.toAppropriateType( actual[ i ] );
checkEqualArray( e, a );
}
else
{
checkEqualArray( (Object [])expected[ i ], (Object [])actual[ i ] );
}
}
else
{
assertEquals( expected[ i ], actual[ i ] );
}
}
}
|
private javax.management.MBeanServer | createAgent()
return( MBeanServerFactory.createMBeanServer( "Test" ) );
|
private void | deleteTestAliases()
assert( mProxy != null );
final String [] aliases = mProxy.listAliases( false );
assert( aliases != null );
for( int i = 0; i < aliases.length; ++i )
{
final String name = aliases[ i ];
if ( name.startsWith( ALIAS_BASE ) )
{
mProxy.deleteAlias( name );
}
}
|
private void | doIntegerTest(java.lang.String arg, java.lang.Object expected)
final Integer result = (Integer)doTest( "testInteger", arg );
assertEquals( expected, result );
|
private void | doObjectArrayTest(java.lang.String arg, java.lang.Object[] expected)
final Object [] result = (Object [])doTest( "testObjectArray", arg );
checkEqualArray( expected, result );
|
private void | doObjectTest(java.lang.String arg, java.lang.Object expected)
final Object result = doTest( "testObject", arg );
assertEquals( expected, result );
|
private void | doStringTest(java.lang.String arg, java.lang.String expected)
final String result = (String)doTest( "testString", arg );
assertEquals( expected, result );
|
private java.lang.Object | doTest(java.lang.String operationName, java.lang.String arg)
final InvokeResult invokeResult = invokeSimpleTestee( operationName, arg );
if ( invokeResult.getResultType() != InvokeResult.SUCCESS )
{
fail( "invocation failed for " + operationName + "(" + arg + ")" );
}
return( invokeResult.mResult );
|
private java.lang.String | getCastType(java.lang.String type)
String result = type;
if ( ClassUtil.classnameIsArray( result ) )
{
final Class theClass = ClassUtil.getClassFromName(result);
final Class elementClass = ClassUtil.getInnerArrayElementClass( theClass );
result = elementClass.getName();
}
return( result );
|
private com.sun.cli.jmx.support.InvokeResult[] | invoke(java.lang.String operationName, java.lang.String args, java.lang.String[] targets)
final InvokeResult [] results = mProxy.mbeanInvoke( operationName, args, targets );
return( results );
|
private com.sun.cli.jmx.support.InvokeResult | invokeSimpleTestee(java.lang.String operationName, java.lang.String args)
final InvokeResult [] results = invoke( operationName, args, SIMPLE_TESTEE_TARGET );
assert( results.length == 1 );
return( results[ 0 ] );
|
private com.sun.cli.jmx.support.InvokeResult | invokeSupportTestee(java.lang.String operationName, java.lang.String args)
final InvokeResult [] results = invoke( operationName, args, SUPPORT_TESTEE_TARGET );
assert( results.length == 1 );
return( results[ 0 ] );
|
private boolean | isGenericallyTestable(javax.management.MBeanOperationInfo operationInfo)
boolean isTestable = true;
final MBeanParameterInfo [] paramInfos = operationInfo.getSignature();
final int numParams = paramInfos.length;
for( int i = 0; i < numParams; ++i )
{
final Class theClass = ClassUtil.getClassFromName( paramInfos[i].getType() );
if ( ! isGenericallyTestableClass( theClass ) )
{
isTestable = false;
break;
}
}
return( isTestable );
|
private boolean | isGenericallyTestableClass(java.lang.Class theClass)
boolean isTestable = false;
Class testClass = theClass;
if ( ClassUtil.classIsArray( theClass ) )
{
// we can test all arrays of supported types
testClass = ClassUtil.getInnerArrayElementClass( theClass );
}
final Class [] classes = GENERICALLY_TESTABLE_CLASSES;
final int numClasses = classes.length;
for( int i = 0; i < numClasses; ++i )
{
if ( testClass == classes[ i ] )
{
isTestable = true;
break;
}
}
if ( ! isTestable )
{
assert( testClass == java.util.Properties.class );
}
return( isTestable );
|
private java.lang.String | makeArgList(java.lang.String[] args)
final int numArgs = args.length;
String result = null;
if ( numArgs != 0 )
{
final StringBuffer buf = new StringBuffer();
for( int i = 0; i < numArgs; ++i )
{
buf.append( args[ i ] );
buf.append( "," );
}
// strip trailing ","
buf.setLength( buf.length() - 1 );
result = new String( buf ) ;
}
return( result );
|
private void | registerMBean(javax.management.MBeanServer conn, java.lang.Object mbean, java.lang.String name)
conn.registerMBean( mbean, new ObjectName( name ) );
|
public void | setUp()
mServer = createAgent( );
// CLI_SUPPORT_TESTEE is very expensive to create, so we'll always reuse the same one
registerMBean( mServer, CLI_SUPPORT_TESTEE, CLISupportStrings.CLI_SUPPORT_TESTEE_TARGET );
registerMBean( mServer, new CLISupportSimpleTestee( ),
CLISupportStrings.CLI_SIMPLE_TESTEE_TARGET );
final AliasMgr aliasMgr = new AliasMgr( new AliasMgrHashMapImpl() );
aliasMgr.createAlias( ALL_ALIAS, "*" );
aliasMgr.createAlias( SIMPLE_TESTEE_ALIAS, CLISupportStrings.CLI_SIMPLE_TESTEE_TARGET );
aliasMgr.createAlias( SUPPORT_TESTEE_ALIAS, CLISupportStrings.CLI_SUPPORT_TESTEE_TARGET );
final CLISupportMBeanImpl cliSupport = new CLISupportMBeanImpl( mServer, aliasMgr );
mProxy = new CLISupportMBeanProxy( aliasMgr, cliSupport );
verifySetup( mProxy );
|
public void | tearDown()
mProxy.mbeanUnregister( mProxy.resolveAlias( SUPPORT_TESTEE_ALIAS ) );
mProxy.mbeanUnregister( mProxy.resolveAlias( SIMPLE_TESTEE_ALIAS ) );
mProxy = null;
mServer = null;
|
public void | test11MixedArgs()
invokeSimpleTestee( "test11MixedArgs", ARGS_11 );
|
public void | test11ObjectArgs()
invokeSimpleTestee( "test11ObjectArgs", ARGS_11 );
|
public void | testAliases()
deleteTestAliases();
// create an alias for each MBean
final ObjectName [] names = mProxy.mbeanFind( new String [] { StandardAliases.ALL_ALIAS } );
final int numNames = names.length;
// create test alias for each existing MBean
for( int i = 0; i < numNames; ++i )
{
final String aliasName = ALIAS_BASE + (i+1);
mProxy.createAlias( aliasName, names[ i ].toString() );
}
// now verify that each of them resolves correctly
for( int i = 0; i < numNames; ++i )
{
final String aliasName = ALIAS_BASE + (i+1);
final String aliasValue = mProxy.resolveAlias( aliasName );
if ( aliasValue == null )
{
fail( "can't resolve alias after creating it: " + aliasName );
}
if ( ! names[ i ].toString().equals( aliasValue ))
{
fail( "alias does not resolve to value it was created with: " + aliasName );
}
}
// create an alias consisting of all aliases
final String ALL_ALIASES_NAME = ALIAS_BASE + "all";
final String [] aliases = mProxy.listAliases( false );
final String allAliases = ArrayStringifier.stringify( aliases, " " );
mProxy.createAlias( ALL_ALIASES_NAME, allAliases );
// create a recursive alias
String allAliasesName = ALL_ALIASES_NAME;
for( int i = 0; i < 5; ++i )
{
mProxy.createAlias( allAliasesName + i, allAliasesName );
allAliasesName = allAliasesName + i;
}
// verify that the alias to all of them produces the same set of names as we started with
final ObjectName [] resolvedNames = mProxy.resolveTargets( new String [] { allAliasesName } );
//p( "all aliases = " + ArrayStringifier.stringify( resolvedNames, "\n" ) );
if ( resolvedNames.length != numNames )
{
fail( "alias resolution produce wrong number of results" );
}
deleteTestAliases();
|
public void | testArrayWithCastAndElementsWithCast()
doObjectArrayTest( "(Number){(BigInteger)0,(BigDecimal)10.0}",
new Number [] { new BigInteger( "0" ), new BigDecimal( "10.0" ) } );
// now see that incompatible casts are rejected
final String input = "(Number){(String)hello}";
final InvokeResult invokeResult = invokeSimpleTestee( "testObjectArray", input );
if ( invokeResult.getResultType() == InvokeResult.SUCCESS )
{
fail( "expected this construct to fail: " + input );
}
|
public void | testArrayWithEmptyElements()
final String s = new String( "" );
doObjectArrayTest( "(String){,,,}", new String [] { s,s,s,s } );
doObjectArrayTest( "{,,,}", new Object [] { s,s,s,s } );
|
public void | testArrayWithNullElements()
doObjectArrayTest( "{null,null}", new Object [] { null, null } );
doObjectArrayTest( "{(String)null,(Object)null}", new Object [] { null, null } );
|
public void | testCaseInsensitivity()
final InvokeResult result = invokeSimpleTestee( "testcasesensitivity2", null );
assertEquals( "testCaseSensitivity2", result.mResult );
|
public void | testCaseSensitivity()
InvokeResult result;
result = invokeSimpleTestee( "testcasesensitivity1", null );
assertEquals( "testcasesensitivity1", result.mResult );
result = invokeSimpleTestee( "testCASESENSITIVITY1", null );
assertEquals( "testCASESENSITIVITY1", result.mResult );
result = invokeSimpleTestee( "testCaseSensitivity1", null );
assertEquals( "testCaseSensitivity1", result.mResult );
try
{
result = invokeSimpleTestee( "testcaseSensitivity1", null );
if ( result.getResultType() == InvokeResult.SUCCESS )
{
fail( "expected ambiguous match to prevent execution of method: " + result.mResult );
}
}
catch( Exception e )
{
// good, expected this
}
|
public void | testEmptyArray()
doObjectArrayTest( "{}", new Object [ 0 ]);
|
public void | testEmptyObjectArrayWithCast()
doObjectArrayTest( "(Object){}", new Object [ 0 ]);
doObjectArrayTest( "(String){}", new String [ 0 ]);
doObjectArrayTest( "(Character){}", new Character [ 0 ]);
doObjectArrayTest( "(Boolean){}", new Boolean [ 0 ]);
doObjectArrayTest( "(Byte){}", new Byte [ 0 ]);
doObjectArrayTest( "(Short){}", new Short [ 0 ]);
doObjectArrayTest( "(Integer){}", new Integer [ 0 ]);
doObjectArrayTest( "(Long){}", new Long [ 0 ]);
doObjectArrayTest( "(Float){}", new Float [ 0 ]);
doObjectArrayTest( "(Double){}", new Double [ 0 ]);
doObjectArrayTest( "(BigInteger){}", new BigInteger [ 0 ]);
doObjectArrayTest( "(BigDecimal){}", new BigDecimal [ 0 ]);
doObjectArrayTest( "(Number){}", new Number [ 0 ]);
|
public void | testEmptyQuotedString()
doStringTest( "\"\"", "");
|
public void | testEmptyQuotedStringWithCast()
doStringTest( "(String)\"\"", "");
|
public void | testEmptyStringWithCast()
doStringTest( "(String)", "");
|
public void | testEscapedString()
final String result = "\"\n\r\t\"";
doStringTest( "\\\"\\n\\r\\t\\\"", result);
|
private void | testGeneric(boolean namedTest, javax.management.ObjectName objectName)
final MBeanInfo info = mServer.getMBeanInfo( objectName );
final MBeanOperationInfo [] opInfos = info.getOperations();
int notTestedCount = 0;
for( int i = 0; i < opInfos.length; ++i )
{
try
{
if ( isGenericallyTestable( opInfos[ i ] ) )
{
final InvokeResult.ResultType resultType =
testOperationGenerically( namedTest, objectName, opInfos[ i ] );
if ( resultType != InvokeResult.SUCCESS )
{
fail( "invocation failure on: " + SmartStringifier.toString( opInfos[ i ] ) );
}
}
else
{
++notTestedCount;
}
}
catch( Exception e )
{
fail( "FAILURE: " + SmartStringifier.toString( opInfos[ i ] ) );
}
}
|
public void | testGenericNamed()
final ObjectName [] allObjects = mProxy.mbeanFind( SUPPORT_TESTEE_ALIAS );
assert( allObjects.length == 1 );
testGeneric( false, allObjects[ 0 ] );
|
public void | testGenericOrdered()
final ObjectName [] allObjects = mProxy.mbeanFind( SUPPORT_TESTEE_ALIAS );
assert( allObjects.length == 1 );
testGeneric( false, allObjects[ 0 ] );
|
public void | testInteger()
doIntegerTest("(Integer)10", Integer.valueOf(10));
doIntegerTest("-10", Integer.valueOf(-10));
|
public void | testMBeanCreateDelete()
final String name = "test:name=testtemp";
final String className = "com.sun.cli.jmx.test.CLISupportSimpleTestee";
mProxy.mbeanCreate( name, className, null );
ObjectName [] results = mProxy.mbeanFind( new String [] { name } );
assertEquals( 1, results.length );
mProxy.mbeanUnregister( name );
results = mProxy.mbeanFind( new String [] { name } );
assertEquals( 0, results.length );
|
public void | testMBeanFind()
final ObjectName [] results = mProxy.mbeanFind( ALL_TARGETS );
assertEquals( 3, results.length );
|
public void | testMBeanGet()
final ResultsForGetSet [] results = mProxy.mbeanGet( "*", SIMPLE_TESTEE_TARGET );
assertEquals( 1, results.length );
assertEquals( 2, results[ 0 ].getAttributes().size() );
|
public void | testMBeanInspect()
final InspectRequest request = new InspectRequest();
final InspectResult [] results = mProxy.mbeanInspect( request, ALL_TARGETS );
assertEquals( 3, results.length );
|
public void | testMBeanSet()
final ResultsForGetSet [] results = mProxy.mbeanSet( "NotifMillis=1000", SIMPLE_TESTEE_TARGET );
assertEquals( 1, results.length );
assertEquals( 1, results[ 0 ].getAttributes().size() );
final AttributeList attrs = mProxy.mbeanGet( "NotifMillis", SIMPLE_TESTEE_TARGET )[ 0 ].getAttributes();
final Attribute expected = new Attribute( "NotifMillis", Long.valueOf(1000));
assertEquals( expected, attrs.get( 0 ) );
|
public void | testMixedArrayWithCasts()
doObjectArrayTest("{(Character)c,(Boolean)true,(Byte)99,(Short)-999,(Integer)0,(Long)99999,(BigInteger)99999999999999999999999999,(BigDecimal)123456789123456789.123456789123456789,\"hello\",(String)hello,hello,}",
new Object[]{Character.valueOf('c"),
Boolean.valueOf("true"),
Byte.valueOf((byte) 99),
Short.valueOf((short) -999),
Integer.valueOf(0),
Long.valueOf(99999),
new BigInteger("99999999999999999999999999"),
new BigDecimal("123456789123456789.123456789123456789"),
"hello", "hello", "hello", ""});
|
public void | testNamedInvoke()
invokeSupportTestee( "testNamed", "p1=hello" );
invokeSupportTestee( "testNamed", "p1=hello,p2=there" );
invokeSupportTestee( "testNamed", "p1=hello,p2=there,p3=!!!" );
invokeSupportTestee( "testNamed", "p1=hello,p2=there,p3=!!!,p4=foobar" );
|
public void | testNullIllegalForSimpleType()
try
{
final InvokeResult result = invokeSimpleTestee( "test_int", "null" );
if ( result.getResultType() == InvokeResult.SUCCESS )
{
fail( "expected failure trying to pass 'null' for an int" );
}
}
catch( Exception e )
{
}
|
public void | testNullIntegerWithCast()
doIntegerTest( "(Integer)null", null);
|
public void | testNullIntegerWithoutCast()
doIntegerTest( "null", null);
|
public void | testNullObjectWithCast()
doObjectTest( "(Object)null", null);
|
public void | testNullObjectWithoutCast()
doObjectTest( "null", null);
|
public void | testNullStringWithCast()
doStringTest( "(String)null", null);
|
public void | testNullStringWithoutCast()
doStringTest( "null", null);
|
public void | testNumericStringNoCast()
doStringTest( "10", "10");
|
private InvokeResult.ResultType | testOperationGenerically(boolean namedArgs, javax.management.ObjectName targetName, javax.management.MBeanOperationInfo operationInfo)
final MBeanParameterInfo [] paramInfos = operationInfo.getSignature();
final int numParams = paramInfos.length;
final String [] strings = new String [ numParams ];
final String operationName = operationInfo.getName();
// create an object of the correct type for each parameter.
// The actual value is not important.
for( int i = 0; i < numParams; ++i )
{
final MBeanParameterInfo paramInfo = paramInfos[ i ];
final String paramType = paramInfos[ i ].getType();
final Class theClass = ClassUtil.getClassFromName( paramType );
final Object paramObject = ClassUtil.InstantiateDefault( theClass );
final String paramString = SmartStringifier.toString( paramObject );
final String castString = "(" + getCastType( paramType ) + ")";
final String paramName = namedArgs ? (paramInfo.getName() + '=") : "";
strings[ i ] = paramName + castString + paramString;
}
// convert the arguments to strings
final String argString = makeArgList( strings );
final String [] args = new String [] { targetName.toString() };
final InvokeResult [] results = (InvokeResult [])mProxy.mbeanInvoke( operationName, argString, args );
final InvokeResult result = results[ 0 ];
if ( result.getResultType() == InvokeResult.SUCCESS )
{
// p( "SUCCESS: " + operationName + "(" + SmartStringifier.toString( paramInfos ) + ")");
}
else
{
final String paramInfosString = SmartStringifier.toString( paramInfos );
result.mThrowable.printStackTrace();
}
return( result.getResultType() );
|
public void | testPropertiesOnly()
final String operationName = "testPropertiesOnly";
final String argString = "foo=bar";
final InvokeResult [] results = (InvokeResult [])
mProxy.mbeanInvoke( operationName, argString, SUPPORT_TESTEE_TARGET );
final InvokeResult result = results[ 0 ];
if ( result.getResultType() != InvokeResult.SUCCESS )
{
throw new TestFailedException( "invocation failed: " + operationName + "(" + argString + ")" );
}
|
public void | testStringAsObject()
doObjectTest( "(Object)hello", "hello");
|
public void | testStringContaining_word_null()
doStringTest( "\"null\"", "null");
|
public void | testURI()
final URI input = new URI( "service:jmx:jmxmp://localhost:" );
final InvokeResult result = invokeSimpleTestee( "testURI", input.toString() );
assertEquals( input, result.mResult );
|
public void | testURL()
final URL input = new URL( "http://www.sun.com?foo=bar&bar=foo" );
final InvokeResult result = invokeSimpleTestee( "testURL", input.toString() );
assertEquals( input, result.mResult );
|
private void | verifySetup(com.sun.cli.jmx.support.CLISupportMBeanProxy proxy)
// must be at least one MBean
final ObjectName [] all = proxy.resolveTargets( ALL_TARGETS );
assert( all.length != 0 );
// verify that the AliasMgr and CLI are available.
final String [] aliases = proxy.listAliases( false );
assert( aliases.length != 0 );
// verify that required aliases are in place
assert( proxy.resolveAlias( ALL_ALIAS ) != null );
assert( proxy.resolveAlias( SIMPLE_TESTEE_ALIAS ) != null );
assert( proxy.resolveAlias( SUPPORT_TESTEE_ALIAS ) != null );
|