FileDocCategorySizeDatePackage
ComSunAppservConfigTest.javaAPI DocGlassfish v2 API6844Fri May 04 22:23:54 BST 2007com.sun.enterprise.management.config

ComSunAppservConfigTest

public final class ComSunAppservConfigTest extends com.sun.enterprise.management.support.ComSunAppservTest
Unit test for the com.sun.appserv monitoring MBeans relied upon by AMX.

Fields Summary
private static final Set
COM_SUN_APPSERV_EXCLUDED_TYPES
Constructors Summary
public ComSunAppservConfigTest()

    
Methods Summary
private booleancheckConfig(javax.management.ObjectName objectName)

        boolean worksOK = true;
        
        final MBeanServerConnection conn    = getMBeanServerConnection();
        
        final MBeanInfo mbeanInfo    = conn.getMBeanInfo( objectName );
        assert( mbeanInfo != null );
        final MBeanAttributeInfo[]  attrInfos   = mbeanInfo.getAttributes();
        for( final MBeanAttributeInfo attrInfo : attrInfos )
        {
            try
            {
                final Object    value   = conn.getAttribute( objectName, attrInfo.getName() );
            }
            catch( Exception e )
            {
			    final Throwable rootCause	= ExceptionUtil.getRootCause( e );
			
                warning( "MBean " + StringUtil.quote( objectName ) +
                    " threw an exception trying to get Attribute " +
                    StringUtil.quote( attrInfo.getName() ) + ": " + rootCause );
                worksOK = false;
            }
        }
        
        final String[]  attrNames   = JMXUtil.getAttributeNames( attrInfos );
        try
        {
           // System.out.println( objectName + " {" + ArrayStringifier.stringify( attrNames, ", " ) + "}");
            final AttributeList attrs   = conn.getAttributes( objectName, attrNames );
            assert( attrs.size() == attrInfos.length );
            
            // verify that Attribute names match what was returned
            final Set<String> attrNamesSet  = GSetUtil.newSet( attrNames );
            assert( attrNamesSet.size() == attrNames.length );  // should all be unique
            final List<Attribute> typed = TypeCast.asList( attrs );
            for( final Attribute attr : typed )
            {
                assert( attrNamesSet.contains( attr.getName() ) );
            }
        }
        catch( Exception e )
        {
			final Throwable rootCause	= ExceptionUtil.getRootCause( e );
			    
            warning( "MBean " + StringUtil.quote( objectName ) +
                " threw an exception trying to get getAttributes(" +
                ArrayStringifier.stringify( attrNames, ", " ) + "): " + rootCause );
            worksOK = false;
        }
        
        return( worksOK );
    
public voidtestAllConfig()

        
    
    
         
    
         
    
        final Map<String,ObjectName>    m   = getAllComSunAppservConfig();
        
        final Collection<ObjectName>   objectNames = m.values();
        final Set<ObjectName>   defective   = new HashSet<ObjectName>();
        int testedCount = 0;
        for( final ObjectName objectName : objectNames )
        {
            final String type   = objectName.getKeyProperty( "type" );
            if ( COM_SUN_APPSERV_EXCLUDED_TYPES.contains( type ) )
            {
                continue;
            }
            
            ++testedCount;
            if ( ! checkConfig( objectName ) )
            {
                defective.add( objectName );
            }
        }
        
        printVerbose( "ComSunAppservConfigTest.testAllConfig: checked " +
            testedCount + " com.sun.appserv:category=config MBeans for basic functionality, " +
            defective.size() + " failures." );
        
        if ( defective.size() != 0 )
        {
            failure( "The following MBeans are defective:\n" +
                CollectionUtil.toString( defective, "\n") );
        }