FileDocCategorySizeDatePackage
OfflineDottedNamesRegistryTest.javaAPI DocGlassfish v2 API5446Fri May 04 22:24:04 BST 2007com.sun.enterprise.management.ext.offline

OfflineDottedNamesRegistryTest

public final class OfflineDottedNamesRegistryTest extends TestCase

Fields Summary
Constructors Summary
public OfflineDottedNamesRegistryTest()

    
Methods Summary
private com.sun.enterprise.management.offline.OfflineDottedNamesRegistrycreate()

        return new OfflineDottedNamesRegistry();
    
private javax.management.ObjectNamecreateObjectName(java.lang.String j2eeType, java.lang.String name)

        return Util.newObjectName( "amx", Util.makeRequiredProps( j2eeType, name ) );
    
private java.util.SetdummySet()

	    return GSetUtil.newStringSet( "hello", "there" );
	
public voidtestAddRemove()

	    final OfflineDottedNamesRegistry    reg = create();
	    
	    final int ITER  = 1000;
	    
	    final Set<String>   attrs   = dummySet();
	    final ObjectName[]  objectNames = new ObjectName[ ITER ];
	    final String[]      prefixes = new String[ ITER ];
	    
	    for( int i = 0; i < ITER; ++i )
	    {
	        final String prefix = "foo" + i;
	        final ObjectName objectName = createObjectName( "test" + i, "" + i );

	        objectNames[ i ]    = objectName;
	        prefixes[ i ]       = prefix;
	        
	        reg.addMapping( objectName, prefix, attrs );
    	    assert( reg.getPrefix( objectName ) ==  prefix );
    	    assert( reg.getObjectName( prefix ) == objectName );
    	    assert( reg.getLegalAttributes( objectName ).equals( attrs ) );
	    }
	    
	    for( int i = 0; i < ITER; ++i )
	    {
	        final ObjectName    objectName  = objectNames[ i ];
	        final String        prefix  = prefixes[ i ];
	        
    	    assert( reg.getPrefix( objectName ) ==  prefix );
    	    assert( reg.getObjectName( prefix ) == objectName );
    	    assert( reg.getLegalAttributes( objectName ).equals( attrs ) );
	        
    	    reg.removeMapping( objectName );
    	    
    	    assert( reg.getPrefix( objectName) == null );
    	    assert( reg.getObjectName( prefixes[ i ] ) == null );
    	    assert( reg.getLegalAttributes( objectName ) == null );
	    }
	
public voidtestCreate()

	    create();
	
public voidtestIllegalAdd()

	    final OfflineDottedNamesRegistry    reg = create();
	    
	    try
	    {
	        reg.addMapping( null, "foo", dummySet() );
	        assert false : "Expected exception adding null ObjectName";
	    }
	    catch ( Exception e )
	    {
	    }
	    
	    try
	    {
	        reg.addMapping( createObjectName( "XXX", "ZZZ" ), null, dummySet() );
	        assert false : "Expected exception adding null prefix";
	    }
	    catch ( Exception e )
	    {
	    }
	    
	    try
	    {
	        reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", null );
	        assert false : "Expected exception adding null attributes";
	    }
	    catch ( Exception e )
	    {
	    }
	    
	    try
	    {
	        reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", dummySet() );
	        // try to add again
	        reg.addMapping( createObjectName( "XXX", "ZZZ" ), "foo", dummySet() );
	        assert false : "Expected exception adding same ObjectName";
	    }
	    catch ( Exception e )
	    {
	    }