OfflineDottedNamesRegistryTestpublic final class OfflineDottedNamesRegistryTest extends TestCase
Constructors Summary |
---|
public OfflineDottedNamesRegistryTest()
|
Methods Summary |
---|
private com.sun.enterprise.management.offline.OfflineDottedNamesRegistry | create()
return new OfflineDottedNamesRegistry();
| private javax.management.ObjectName | createObjectName(java.lang.String j2eeType, java.lang.String name)
return Util.newObjectName( "amx", Util.makeRequiredProps( j2eeType, name ) );
| private java.util.Set | dummySet()
return GSetUtil.newStringSet( "hello", "there" );
| public void | testAddRemove()
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 void | testCreate()
create();
| public void | testIllegalAdd()
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 )
{
}
|
|