FileDocCategorySizeDatePackage
AliasMgrTest.javaAPI DocGlassfish v2 API4647Fri May 04 22:24:52 BST 2007com.sun.cli.jmx.support

AliasMgrTest

public final class AliasMgrTest extends TestCase

Fields Summary
public static final String
LEGAL_CHARS
public static final String
ILLEGAL_CHARS
final String
TEST
final String
TEST_VALUE
Constructors Summary
public AliasMgrTest()

	
Methods Summary
public voidattemptInvalidName(java.lang.String name)

		try
		{
			create().createAlias( name, "bad name" );
			fail( "expected alias to fail: \"" + name + "\"");
		}
		catch( Exception e )
		{
			// good, we expected to get here
		}
	
AliasMgrMBeancreate()


		
	 
	
		return( new AliasMgr( new AliasMgrHashMapImpl() ) );
	
public voidtestEmptyName()

		attemptInvalidName( "" );
	
public voidtestIllegalChars()

		for( int i = 0; i < ILLEGAL_CHARS.length(); ++i )
		{
			final char	theChar	= ILLEGAL_CHARS.charAt( i );
			
			attemptInvalidName( "" + theChar );
			attemptInvalidName( "x" + theChar + "y" );
		}
	
public voidtestLegalChars()

		final AliasMgrMBean	aliasMgr	= create();
				
		aliasMgr.createAlias( LEGAL_CHARS, "test" );
			
		for( int i = 0; i < LEGAL_CHARS.length(); ++i )
		{
			final char	theChar	= LEGAL_CHARS.charAt( i );
			
			aliasMgr.createAlias( "" + theChar, "test" );
		}
	
public voidtestLifecycle()

	
		 
	
		 
	
		final AliasMgrMBean	aliasMgr	= create();
		
		aliasMgr.createAlias( TEST, TEST_VALUE );
		assertEquals( TEST_VALUE, aliasMgr.resolveAlias( TEST ) );
		
		aliasMgr.deleteAlias( TEST );
		assertEquals( null, aliasMgr.resolveAlias( TEST ) );
	
public voidtestList()

		final AliasMgrMBean	aliasMgr	= create();
		assertEquals( 0, aliasMgr.listAliases( true ).length );
		assertEquals( 0, aliasMgr.getAliases( ).length );
		
		aliasMgr.createAlias( TEST, TEST_VALUE );
		assertEquals( 1, aliasMgr.listAliases( true ).length );
		assertEquals( 1, aliasMgr.listAliases( false ).length );
		assertEquals( 1, aliasMgr.getAliases( ).length );
		
		String	[]	listedAliases	= aliasMgr.listAliases( false );
		assertEquals( TEST, listedAliases[ 0 ] );
		
		listedAliases	= aliasMgr.listAliases( true );
		assertEquals( TEST + "=" + TEST_VALUE , listedAliases[ 0 ] );