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

PropertiesAccessTest

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

Fields Summary
private static final Set
TEST_CREATE_REMOVE_TYPES
Adding or removing test properties to these types does not cause any side effects. Plus, there is no need to test every MBean.
Constructors Summary
public PropertiesAccessTest()

	
Methods Summary
public voidcheckCreateRemove(javax.management.ObjectName src)

		final PropertiesAccess	props	= (PropertiesAccess)getProxy( src );
		
		testPropertiesCreateRemove( props );
	
public voidcheckGetProperties(javax.management.ObjectName src)

		final AMX	proxy	= getProxy( src );
		
		if ( ! (proxy instanceof PropertiesAccess) )
		{
			throw new IllegalArgumentException(
				"MBean does not implement PropertiesAccess: " + quote( src ) );
		}
		
		final PropertiesAccess	props	= (PropertiesAccess)proxy;
		testPropertiesGet( props );
	
public voidcheckSetPropertiesSetToSameValue(javax.management.ObjectName src)

		final PropertiesAccess	props	= (PropertiesAccess)getProxy( src );
		
		testPropertiesSetToSameValue( props );
	
private java.util.SetgetAllImplementorsOfProperties()

		final Set<AMX>	amxs	= getQueryMgr().queryInterfaceSet(
			PropertiesAccess.class.getName(), null);
		
		return( TestUtil.newSortedSet( Util.toObjectNames( amxs ) ) );
			
	
private voidtestCreateEmptyProperty(com.sun.appserv.management.config.PropertiesAccess props)

	    final String NAME   = "test.empty";
	    
		props.createProperty( NAME, "" );
		assert( props.existsProperty( NAME ) );
		props.removeProperty( NAME );
		assert( ! props.existsProperty( NAME ) );
	
public synchronized voidtestPropertiesCreateRemove()

	    if ( checkNotOffline( "testPropertiesCreateRemove" ) )
	    {
    		final Set<ObjectName>		all	= getAllImplementorsOfProperties();
    		    
    		testAll( all, "checkCreateRemove" );
		}
	
private voidtestPropertiesCreateRemove(com.sun.appserv.management.config.PropertiesAccess props)

	    
		 
	    
	
		final String[]	propNames			= props.getPropertyNames();

        final AMX amx           = Util.asAMX( props );
        final String j2eeType   = amx.getJ2EEType();
        if ( ! TEST_CREATE_REMOVE_TYPES.contains( j2eeType ) )
        {
            return;
        }

		// add some properties, then delete them
		final int	numToAdd	= 1;
		final long	now	= System.currentTimeMillis();
		for( int i = 0; i < numToAdd; ++i )
		{
			final String	testName	= "__junittest_" + i + now;
			
			if ( props.existsProperty( testName ) )
			{
				failure( "test property already exists: " + testName );
			}
			
			props.createProperty( testName, "value_" + i );
			assert( props.existsProperty( testName ) );
		}
		final int	numProps	= props.getPropertyNames().length;
		
		if ( numProps != numToAdd + propNames.length )
		{
			failure( "expecting " + numProps + " have " + numToAdd + propNames.length );
		}
		
		
		// remove the ones we added
		for( int i = 0; i < numToAdd; ++i )
		{
			final String	testName	= "__junittest_" + i + now;
			
			props.removeProperty( testName );
			assert( ! props.existsProperty( testName ) );
		}
		
		assert( props.getPropertyNames().length == propNames.length );
	
public synchronized voidtestPropertiesGet()

		final Set<ObjectName>	all	= getAllImplementorsOfProperties();
		
		testAll( all, "checkGetProperties" );
	
private voidtestPropertiesGet(com.sun.appserv.management.config.PropertiesAccess props)

		final String[]	propNames			= props.getPropertyNames();
		
		for( final String name : propNames )
		{
		    assert( props.existsProperty( name ) );
			final String	value	= props.getPropertyValue( name );
		}
	
public synchronized voidtestPropertiesSetToSameValue()

		final Set<ObjectName>	all	= getAllImplementorsOfProperties();
		
		testAll( all, "checkSetPropertiesSetToSameValue" );
	
private voidtestPropertiesSetToSameValue(com.sun.appserv.management.config.PropertiesAccess props)

		final String[]	propNames			= props.getPropertyNames();
		
		// get each property, set it to the same value, the verify
		// it's the same.
		for( int i = 0; i < propNames.length; ++i )
		{
			final String	propName	= propNames[ i ];
			
			assert( props.existsProperty( propName ) );
			final String	value	= props.getPropertyValue( propName );
			props.setPropertyValue( propName, value );
			
			assert( props.getPropertyValue( propName ).equals( value ) );
		}