FileDocCategorySizeDatePackage
ManagementRulesConfigTest.javaAPI DocGlassfish v2 API8724Fri May 04 22:23:56 BST 2007com.sun.enterprise.management.config

ManagementRulesConfigTest

public final class ManagementRulesConfigTest extends com.sun.enterprise.management.AMXTestBase

Fields Summary
private static final String
ACTION_MBEAN_NAME
Constructors Summary
public ManagementRulesConfigTest()

	    if ( checkNotOffline( "ensureDefaultInstance" ) )
	    {
	        ensureDefaultInstance( getConfigConfig() );
	    }
	
Methods Summary
public ManagementRuleConfigcreateAndTestRule(int id)

	    final ManagementRulesConfig rules   = getManagementRulesConfig();
	    
        final String    name    = createName( id );
        
        if ( rules.getManagementRuleConfigMap().get( name ) != null )
        {
            removeRule( name );
            warning( "Removed left over ManagementRuleConfig: " + StringUtil.quote( name ) );
        }
        
        String actionMBeanName = ((id%2) ==0) ? ACTION_MBEAN_NAME : null;
        
        ManagementRuleConfig    ruleConfig =
            createRule( rules, name, EventTypeValues.TRACE, actionMBeanName, getDummyProperties(), getOptional() );
        
        testRuleConfig( ruleConfig );
        ActionConfig actionConfig   = ruleConfig.getActionConfig();
        if ( actionConfig  == null )
        {
            actionConfig = ruleConfig.createActionConfig( ACTION_MBEAN_NAME );
            testRuleConfig( ruleConfig );
        }
        
        try
        {
            ruleConfig.createActionConfig( ACTION_MBEAN_NAME );
        }
        catch( Exception e )
        {
            // good, we expect to be here
        }
        
        try
        {
            ruleConfig.createActionConfig( null );
        }
        catch( Exception e )
        {
            // good, we expect to be here
        }
        
        return ruleConfig;
	
private java.lang.StringcreateName(int i)

        return "rule" + i;
    
private static ManagementRuleConfigcreateRule(ManagementRulesConfig rules, java.lang.String name, java.lang.String eventType, java.lang.String actionMBeanName, java.util.Properties props, java.util.Map optional)

	    final ManagementRuleConfig rule =
	        rules.createManagementRuleConfig(
	            name, eventType, actionMBeanName, props, optional );
	    
	    return rule;
    
public static ManagementRuleConfigensureDefaultInstance(ConfigConfig config)

	    final ManagementRulesConfig rules   = getManagementRulesConfig(config);
	    
	    ManagementRuleConfig   result  =
	        rules.getManagementRuleConfigMap().get( getDefaultInstanceName() );
	    
	    if ( result == null )
	    {
	        result  = createRule( rules, getDefaultInstanceName(), EventTypeValues.TRACE, ACTION_MBEAN_NAME, null, null );
	    }
	    
	    return result;
	
public static java.lang.StringgetDefaultInstanceName()

        return getDefaultInstanceName( "ManagementRulesConfigTest" );
    
private java.util.PropertiesgetDummyProperties()

    
    
         
    
    
        final Properties props = new Properties();
        
        props.put( "Dummy1", "Dummy1-value" );
        props.put( "Dummy2", "Dummy2-value" );
        
        return props;
    
private static ManagementRulesConfiggetManagementRulesConfig(ConfigConfig config)

	    return config.getManagementRulesConfig();
	
private ManagementRulesConfiggetManagementRulesConfig()

	    return getManagementRulesConfig( getConfigConfig() );
	
private java.util.MapgetOptional()

        final Map<String,String> optional = new HashMap<String,String>();
        
        optional.put( EVENT_LOG_ENABLED_KEY, "true" );
        optional.put( EVENT_LEVEL_KEY, "INFO" );
        
        return optional;
    
private voidremoveRule(java.lang.String name)

	    getManagementRulesConfig().removeManagementRuleConfig( name );
    
public voidtestCreateRule()

	    final ManagementRulesConfig rulesConfig = getManagementRulesConfig();
	    if ( rulesConfig == null )
	    {
	        warning( "testCreateRule: ManagementRulesConfig is null...skipping test" );
	        return;
	    }
	    
	    final int   NUM = 6;
	    final ManagementRuleConfig[] ruleConfigs = new ManagementRuleConfig[ NUM ];
	    
	    try
	    {
    	    for( int i = 0; i < NUM; ++i )
    	    {
    	        ruleConfigs[ i ]    = createAndTestRule( i );
    	    }
	    }
	    finally
	    {
    	    for( int i = 0; i < NUM; ++i )
    	    {
    	        if ( ruleConfigs[ i ] != null )
    	        {
    	            removeRule( ruleConfigs[ i ].getName() );
    	        }
    	    }
	    }
	
private voidtestEventConfig(EventConfig eventConfig)

        assert( eventConfig != null );
        
        final String eventType  = eventConfig.getType();
        eventConfig.setType( eventType );
        eventConfig.setDescription( "test description" );
    
public voidtestGet()

	    final ManagementRulesConfig rulesConfig = getManagementRulesConfig();
	    
	    if ( rulesConfig != null )
	    {
    	    final Map<String,ManagementRuleConfig>  ruleConfigs =
    	        rulesConfig.getManagementRuleConfigMap();
	        assert( ruleConfigs != null );
	    }
	    else
	    {
	        warning( "testGet: ManagementRulesConfig is null...skipping test" );
	    }
	
private voidtestRuleConfig(ManagementRuleConfig ruleConfig)

        final EventConfig   eventConfig = ruleConfig.getEventConfig();
        assert( eventConfig != null );
        testEventConfig( eventConfig );
        
        final ActionConfig  actionConfig = ruleConfig.getActionConfig();
        if ( actionConfig != null )
        {
            final String mbeanName  = actionConfig.getActionMBeanName();
            actionConfig.setActionMBeanName( mbeanName );
        }