FileDocCategorySizeDatePackage
NotificationListenerBaseTest.javaAPI DocGlassfish v2 API9667Fri May 04 22:24:06 BST 2007com.sun.enterprise.management.util.jmx

NotificationListenerBaseTest

public class NotificationListenerBaseTest extends JMXTestBase

Fields Summary
private MBeanServer
mServer
private static final String
TEST
private static final String
DUMMY_OBJECT_NAME_PREFIX
private static final String
REG_DOMAIN
private static final int
REG_COUNT
Constructors Summary
public NotificationListenerBaseTest()

    
         
    
    
        mServer = null;
    
Methods Summary
private com.sun.enterprise.management.util.jmx.NotificationListenerBaseTest$MyListenercreate(java.lang.String pattern)

	    final MyListener  listener   = 
	        new MyListener( mServer, JMXUtil.newObjectName( pattern ), null );
	    
        listener.startListening();
	    return listener;
	
private javax.management.ObjectNamecreateObjectName(java.lang.String domain, int id, java.lang.String name)

	
    
         
    
             
                
              
    
       String s   = domain + ":" +
            "name=" + name +
            ",id=" + id +
            (",category=" + ((id % 2) == 0 ? "even":"odd"));
	        
	   return JMXUtil.newObjectName( s );
    
java.util.SetregisterDummies(int count, java.lang.String name)

	    return registerDummies( TEST, count, name );
	
java.util.SetregisterDummies(java.lang.String domain, int count, java.lang.String name)

	    final Set<ObjectName>   s   = new HashSet<ObjectName>();
	    
	    for( int i = 0; i < count; ++i )
	    {
	        final Dummy d   = new Dummy();
	        d.setDummy( i );
	        
	        final ObjectName    on  = createObjectName( domain, i, name );
	        final ObjectName    objectName  = registerMBean( d, on );
	        
	        s.add( objectName );
	    }
	    
	    return s;
	
protected javax.management.ObjectNameregisterMBean(java.lang.Object mbean, javax.management.ObjectName objectName)

		return mServer.registerMBean( mbean, objectName ).getObjectName();
	
public voidsetUp()

	    mServer  = MBeanServerFactory.newMBeanServer( "test" );
	
public voidtearDown()

	    mServer = null;
	
public voidtestCreate()

	    final MyListener  b   = create( "*:*" );
	    assert( b.getListenees().size() != 0 );
	    b.getMBeanServerConnection();
	    b.cleanup();
	    assert( b.getListenees().size() == 0 );
	
public voidtestGetListenees()

	    final int    NUM = 10;
	    final String NAME   = "bbb";
	    
	    registerDummies( NUM, NAME );
	    
	    final MyListener  odd   = create( TEST + ":category=odd,*" );
	    assert( odd.getListenees().size() == NUM / 2 );
	    for( final ObjectName item : odd.getListenees() )
	    {
	        assert( item.getKeyProperty( "category" ).equals( "odd" ) );
	    }
	    assert( odd.isAlive() );
	    
	    final MyListener  even   = create( TEST + ":category=even,*" );
	    assert( even.getListenees().size() == NUM / 2 );
	    for( final ObjectName item : even.getListenees() )
	    {
	        assert( item.getKeyProperty( "category" ).equals( "even" ) );
	    }
	    assert( even.isAlive() );
	    
	    final MyListener  all   = create( TEST + ":name=bbb,*" );
	    assert( all.getListenees().size() == NUM );
	    for( final ObjectName item : all.getListenees() )
	    {
	        assert( item.getKeyProperty( "name" ).equals( NAME ) );
	    }
	    assert( all.isAlive() );
	
private voidtestListenForRegistration(java.lang.String domain, java.lang.String name, int count, java.lang.String constrainStr)

	    final ObjectName    constrain = (constrainStr == null) ? null :
	        JMXUtil.newObjectName( constrainStr );
	    
	    final MyRegListener listener = new MyRegListener( constrain );
        listener.startListening();
	    assert( listener.getListenees().size() == 1 );
	    
	    final Set<ObjectName>   s   = registerDummies( domain, count, name );
	    assert( listener.mRegCount == count );
	    
	    for( final ObjectName objectName : s )
	    {
	        mServer.unregisterMBean( objectName );
	    }
	    assert( listener.mUnregCount == count );
	    listener.cleanup();
	    assert( listener.getListenees().size() == 0 );
	    
	
public voidtestListenForRegistration1()

    
	     
	
	     
	
	    final String NAME   = "zzz";
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, null );
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, "*:*");
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, REG_DOMAIN +":*");
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, "*:" + "name=" + NAME);
	
public voidtestListenForRegistration2()

	    final String NAME   = "zzzz";
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, null );
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, "*:*");
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, REG_DOMAIN +":*");
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, "*:" + "name=" + NAME);
	
public voidtestListenForRegistration3()

	    final String NAME   = "zzzzz";
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, null );
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, "*:*");
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, REG_DOMAIN +":*");
	    testListenForRegistration( REG_DOMAIN, NAME, REG_COUNT, "*:" + "name=" + NAME);