FileDocCategorySizeDatePackage
ContainerTest.javaAPI DocGlassfish v2 API14639Fri May 04 22:23:54 BST 2007com.sun.enterprise.management.base

ContainerTest

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

Fields Summary
Constructors Summary
public ContainerTest()

	
Methods Summary
public voidcheckContaineeMap(com.sun.appserv.management.base.AMX container)

	    checkContaineeMap( (Container)container );
	
private voidcheckContaineeMap(com.sun.appserv.management.base.Container container)

		final Set<String>	containedJ2EETypes	= container.getContaineeJ2EETypes();
		assert( containedJ2EETypes != null );
		assert( ! containedJ2EETypes.contains( null ) );
		
		assert( container.getMultiContaineeMap( (Set<String>)null ) != null );
		assert( container.getMultiContaineeMap( containedJ2EETypes ) != null );
		
		for ( final String j2eeType : containedJ2EETypes )
		{
			final Map<String,AMX> containeeMap	=
			    container.getContaineeMap( j2eeType );
			assert( containeeMap != null ) :
				"getContaineeObjectNameMap failed for " + j2eeType ;
			final Set<String>	nullValueKeys	= MapUtil.getNullValueKeys( containeeMap );
			assert( nullValueKeys.size() == 0 ) :
				"getContaineeObjectNameMap contains nulls for " + toString( nullValueKeys );
		}
	
private voidcheckContaineeSet(com.sun.appserv.management.base.Container container)

		final Set<String>	containedJ2EETypes	= container.getContaineeJ2EETypes();
		assert( containedJ2EETypes != null );
		assert( ! containedJ2EETypes.contains( null ) );
		assert( container.getContaineeSet() != null );
		
		for ( final String j2eeType : containedJ2EETypes )
		{
			final Set<AMX> containeeSet	=
			    container.getContaineeSet( j2eeType );
			assert( containeeSet != null ) :
				"getContaineeSet for " + j2eeType ;
			assert( ! containeeSet.contains( null ) ) :
				"getContaineeSet contains null for " + j2eeType ;
				
		    final Set<AMX>    fromSet =
			    container.getContaineeSet( GSetUtil.newStringSet( j2eeType ) );
			assert( fromSet.equals( containeeSet ) );
		        
			if ( containeeSet.size() == 1 )
			{
			    assert( container.getContainee( j2eeType ) != null );
			}
		}
	
public voidcheckContaineeSet(com.sun.appserv.management.base.AMX container)

	    checkContaineeSet( (Container)container );
	
public voidcheckContainerContainsChild(javax.management.ObjectName containeeObjectName)

	    final MBeanServerConnection conn    = getMBeanServerConnection();
	    
	    assert( containeeObjectName != null );
	    assert( conn.isRegistered( containeeObjectName ) );
		final AMX	containedProxy	= getProxyFactory().getProxy( containeeObjectName, AMX.class);
		if ( containedProxy instanceof DomainRoot )
		{
		    // DomainRoot has no Container
		    return;
		}
		
		final ObjectName    containerObjectName = (ObjectName)
		    conn.getAttribute( containeeObjectName, "ContainerObjectName" );
		if ( ! conn.isRegistered( containerObjectName ) )
		{
		    warning( "Container " + StringUtil.quote( containerObjectName ) +
		        " for " + StringUtil.quote( containeeObjectName ) +
		        " is not registered." );
		    return;
		}
	    
		final AMX	parentProxy		= containedProxy.getContainer( );
		
		if ( parentProxy instanceof Container )
		{
			if ( ! ( parentProxy instanceof Container ) )
			{ 
				trace( "WARNING: proxy is instance of Container, but not Container: " +
					Util.getExtra( parentProxy ).getObjectName() );
			}
			else
			{
				final Container	container	= (Container)parentProxy;
					
				if ( container != null )
				{
					final Set<AMX>	containees	= container.getContaineeSet();
					final Set<ObjectName>	containeeObjectNames	= Util.toObjectNames( containees );
					
					if ( ! containeeObjectNames.contains( Util.getExtra( containedProxy ).getObjectName() ) )
					{
						trace( "ERROR: Container " + Util.getExtra( parentProxy ).getObjectName() + 
							" does not contain its child: " + containeeObjectName );
						assertTrue( false );
					}
				}
			}
		}
	
private voidcheckGetByName(com.sun.appserv.management.base.Container container)

		final Set<String>	containedJ2EETypes	= container.getContaineeJ2EETypes();
		
		for ( final String j2eeType : containedJ2EETypes )
		{
			final Map<String,AMX> containeeMap	=
			    container.getContaineeMap( j2eeType );
			
			for( final String name : containeeMap.keySet() )
			{
				final AMX containee	= container.getContainee( j2eeType, name );
					
				assert( containee != null ) :
					"can't get containee of type " + j2eeType + ", name = " + name +
					" in " + Util.getObjectName( container );
					
				assert( containee.getJ2EEType().equals( j2eeType ) );
				assert( containee.getName( ).equals( name ) );
				
				final Set<AMX>   byName  =
				    container.getByNameContaineeSet( GSetUtil.newStringSet( j2eeType ), name );
				assert( byName.size() == 1 );
				assert( byName.iterator().next() == containee );
			}
		}
	
public voidcheckGetByName(com.sun.appserv.management.base.AMX container)

	    checkGetByName( (Container)container );
	
public voidcheckIsContainer(javax.management.ObjectName objectName)

		final AMX	proxy	= getProxyFactory().getProxy( objectName, AMX.class);

		try
		{
			final Set<String>	containedJ2EETypes	=  TypeCast.asSet( 
				Util.getExtra( proxy ).getAttribute( Container.ATTR_CONTAINEE_J2EE_TYPES ) );
			
			if ( containedJ2EETypes != null && containedJ2EETypes.size() != 0 )
			{
				assert( proxy instanceof Container ) :
					"proxy has ContaineeJ2EETypes but is not a Container: " + objectName;
			}
		}
		catch( AttributeNotFoundException e )
		{
		}
		
	
private voidcheckMapAgreesWithSet(com.sun.appserv.management.base.Container container)

		final Set<String>	containedJ2EETypes	= container.getContaineeJ2EETypes();
		
		for ( final String j2eeType : containedJ2EETypes )
		{
			final Map<String,AMX> containeeMap	=
			    container.getContaineeMap( j2eeType );
			    
			final Set<AMX> containeeSet	=
			    container.getContaineeSet( j2eeType );
				
			assert( containeeMap.keySet().size() == containeeSet.size() ) :
				"containeeMap has " + containeeMap.keySet().size() +
					" = " + toString( containeeMap ) +
				" but containeeSet has " + containeeSet.size() + " = " + toString( containeeSet );
		
		    final Set<String>   namesSet = Util.getNames( containeeSet );
		    assert( containeeMap.keySet().equals( namesSet ) );
		}
	
public voidcheckMapAgreesWithSet(com.sun.appserv.management.base.AMX container)

	    checkMapAgreesWithSet( (Container)container );
	
private java.util.SetgetAllContainers()

	    return getTestUtil().getAllAMX( Container.class );
	
public static com.sun.enterprise.management.CapabilitiesgetCapabilities()

	    return getOfflineCapableCapabilities( true );
	
private booleanmapsEqual(java.util.Map m1, java.util.Map m2)

	    final Map<String,ObjectName>    t1  = Util.toObjectNames( m1 );
	    final Map<String,ObjectName>    t2  = Util.toObjectNames( m2 );
	    
	    return t1.equals( t2 );
	
private booleanmapsOfMapsEqual(java.util.Map m1, java.util.Map m2)

	    boolean equals  = false;
	    
	    if ( m1.keySet().equals( m2.keySet() ) )
	    {
	        equals  = true;
	        for( final String key : m1.keySet() )
	        {
	            final Map<String,T>   x1  = m1.get( key );
	            final Map<String,T>   x2  = m2.get( key );
	            if ( ! mapsEqual( x1, x2 ) )
	            {
	                trace( "x1: " + MapUtil.toString( x1 ) );
	                trace( "x2: " + MapUtil.toString( x2 ) );
	                equals  = false;
	                break;
	            }
	        }
	    }
	    
	    return equals;
	
private booleansetsEqual(java.util.Set s1, java.util.Set s2)

	    final Set<ObjectName>    t1  = Util.toObjectNames( s1 );
	    final Set<ObjectName>    t2  = Util.toObjectNames( s2 );
	    
	    return t1.equals( t2 );
	
private voidtestContainee(com.sun.appserv.management.base.Container c)

        final Map<String,Map<String,AMX>>  all  = c.getMultiContaineeMap( null );
        
        for( final String j2eeType : all.keySet() )
        {
            testContaineesOfType( c, j2eeType );
        }
	
public voidtestContaineeMap()

		testAllProxies( getAllContainers(), "checkContaineeMap" );
	
public voidtestContaineeSet()

		testAllProxies( getAllContainers(), "checkContaineeSet" );
	
public voidtestContainees()

	    final Set<Container>    containers = getAllContainers();
	    
	    for( final Container c : containers )
	    {
	        testContainee( c );
	    }
	    
	
private voidtestContaineesOfType(com.sun.appserv.management.base.Container c, java.lang.String j2eeType)

	    final Set<String>   j2eeTypes   = c.getContaineeJ2EETypes();
	    
        final Map<String,Map<String,AMX>>  all  = c.getMultiContaineeMap( j2eeTypes );
        final Map<String,Map<String,AMX>>  allFromNull  = c.getMultiContaineeMap( null );
        assert( mapsOfMapsEqual( all, allFromNull) );
        
        final Map<String,AMX>   byType  = c.getContaineeMap( j2eeType );
        assert mapsEqual( byType, all.get( j2eeType ) );
        
        if ( byType.keySet().size() == 1 )
        {
            final AMX  cc   = c.getContainee( j2eeType );
            assert cc == byType.values().iterator().next();
        }
        
        final Set<AMX>  s = c.getContaineeSet( j2eeType );
        final Set<AMX>  sByType = new HashSet<AMX>( byType.values() );
        assert setsEqual( sByType, s ) ;
        
        final Set<String>   nullSet = null;
        
        assert( setsEqual( c.getContaineeSet( nullSet ), c.getContaineeSet( j2eeTypes ) ) );
        assert( setsEqual( c.getContaineeSet(), c.getContaineeSet( nullSet ) ) );
        
        for( final AMX amx : byType.values() )
        {
            final String        itsName = amx.getName();
            final String        itsType = amx.getJ2EEType();
            
            final Set<String>   types   = GSetUtil.newStringSet( itsType );
            final Set<AMX>  x   = c.getByNameContaineeSet( types, itsName );
            
            assert( x.size() == 1 );
            assert( amx == x.iterator().next() );
            assert( c.getContainee( itsType, itsName ) == amx );
        }
	
public voidtestContainersContainChildren()

		testAll( "checkContainerContainsChild" );
	
public voidtestGetByName()

		testAllProxies( getAllContainers(), "checkGetByName" );
	
public voidtestIsContainer()

		testAll( "checkIsContainer" );
	
public voidtestMapAgreesWithSet()

		testAllProxies( getAllContainers(), "checkMapAgreesWithSet" );