FileDocCategorySizeDatePackage
TestUtil.javaAPI DocGlassfish v2 API7814Fri May 04 22:23:50 BST 2007com.sun.enterprise.management

TestUtil

public final class TestUtil extends Object
Observes various things as tests are run.

Fields Summary
private final com.sun.appserv.management.DomainRoot
mDomainRoot
private final String
NEWLINE
Constructors Summary
public TestUtil(com.sun.appserv.management.DomainRoot domainRoot)

        mDomainRoot = domainRoot;
	    NEWLINE = System.getProperty( "line.separator" );
    
Methods Summary
public com.sun.enterprise.management.support.AMXDebugStuffasAMXDebugStuff(com.sun.appserv.management.base.AMX amx)

	    final String[] attrNames   = Util.getExtra( amx ).getAttributeNames();
	    
	    AMXDebugStuff   result  = null;
	    if ( GSetUtil.newUnmodifiableStringSet( attrNames ).contains( "AMXDebug" ) )
	    {
    	    final ProxyFactory  factory = Util.getExtra( amx ).getProxyFactory();
    	        
            try
            {
        	    final Class     amxClass    =
        	        ClassUtil.getClassFromName( Util.getExtra( amx ).getInterfaceName() );
        	    final Class[]   interfaces  = new Class[] { amxClass, AMXDebugStuff.class };
        	    
                final ObjectName    objectName  = Util.getObjectName( amx );
                
                return (AMXDebugStuff)
                    factory.newProxyInstance( objectName, interfaces );
            }
            catch( Exception e )
            {
                trace( ExceptionUtil.toString( e ) );
                throw new RuntimeException( e );
            }
        }
        
        return result;
	
public java.util.SetfindRegisteredJ2EETypes()

return
Set of j2eeTypes for which no MBeans exist

	    return getJ2EETypes( mDomainRoot.getQueryMgr().queryAllSet() );
	
public java.util.SortedSetgetAllAMX()

return
all AMX, sorted by ObjectName

	    final SortedSet<ObjectName>   all = getAllObjectNames();
	    
	    final SortedSet<AMX>    allAMX  = new TreeSet<AMX>( new AMXComparator<AMX>() );
	    final ProxyFactory  proxyFactory    = Util.getExtra( mDomainRoot ).getProxyFactory();
	    for( final ObjectName objectName : all )
	    {
	        try
	        {
	            final AMX   amx = proxyFactory.getProxy( objectName, AMX.class );
	            
	            allAMX.add( amx );
	        }
	        catch( Exception e )
	        {
	            trace( ExceptionUtil.toString( e ) );
	        }
	    }
	    
		return allAMX;
	
public java.util.SortedSetgetAllAMX(java.lang.Class theInterface)

	    final SortedSet<AMX>   all = getAllAMX();
	    final TreeSet<AMX> allOfInterface = new TreeSet<AMX>( new AMXComparator<AMX>() );
	    
	    for( final AMX amx : all )
	    {
	        if ( theInterface.isAssignableFrom( amx.getClass() ) )
	        {
	            allOfInterface.add( amx );
	        }
	    }
	    
	    return TypeCast.asSortedSet( allOfInterface );
	    
	
public javax.management.ObjectName[]getAllAMXArray()

		final SortedSet<ObjectName> s	= getAllObjectNames();
		final ObjectName[]	objectNames	= new ObjectName[ s.size() ];
		s.toArray( objectNames );
		
		return( objectNames );
	
public java.util.SortedSetgetAllObjectNames()
As an optimization to speed up testing, we always get the Set of AMX ObjectNames using Observer, which maintains such a list.

	    final Set<ObjectName>    s   =
	        Observer.getInstance().getCurrentlyRegisteredAMX();
	    
	    return newSortedSet( s );
	
public java.util.SetgetAvailJ2EETypes()

		final SortedSet<ObjectName>	allObjectNames	= getAllObjectNames();
		final Set<String>	    j2eeTypes	    = new HashSet<String>();
		
		for( final ObjectName objectName : allObjectNames )
		{
			final String	value	= Util.getJ2EEType( objectName );
				
			j2eeTypes.add( value );
		}
		return( j2eeTypes );
	
public java.util.SetgetJ2EETypes(java.util.Set amxs)

return
Set of j2eeTypes found in Set

	    final Set<String>   registered = new HashSet<String>();
	    
	    for( final AMX amx : amxs )
	    {
	        registered.add( amx.getJ2EEType() );
	    }
	    
	    return registered;
	
public static java.util.SortedSetnewSortedSet(javax.management.ObjectName[] objectNames)

	    final SortedSet<ObjectName> s   = new TreeSet<ObjectName>( ObjectNameComparator.INSTANCE );
	    
	    for( final ObjectName   objectName : objectNames )
	    {
	        s.add( objectName );
	    }
	    
	    return s;
	
public static java.util.SortedSetnewSortedSet(java.util.Collection c)

	    final ObjectName[]  objectNames = new ObjectName[ c.size() ];
	    c.toArray( objectNames );
	    
	    return newSortedSet( objectNames );
	
public java.lang.StringsetToSortedString(java.util.Set s, java.lang.String delim)

        final String[]  a    = GSetUtil.toStringArray( s );
        Arrays.sort( a );
	   
	    return StringUtil.toString( NEWLINE, (Object[])a );
	
private voidtrace(java.lang.Object o)

        System.out.println( "" + o );