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

SystemPropertiesAccessTest

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

Fields Summary
Constructors Summary
public SystemPropertiesAccessTest()

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

		final SystemPropertiesAccess	props	=
		    getProxy( src, SystemPropertiesAccess.class );
		
		testSystemPropertiesCreateRemove( props );
	
public synchronized voidcheckGetProperties(javax.management.ObjectName src)

		final AMX	proxy	= getProxy( src, AMX.class);
		
		if ( ! (proxy instanceof SystemPropertiesAccess) )
		{
			throw new IllegalArgumentException(
				"MBean does not implement SystemPropertiesAccess: " + quote( src ) );
		}
		
		final SystemPropertiesAccess	props	= (SystemPropertiesAccess)proxy;
		checkPropertiesGet( props );
	
private voidcheckPropertiesGet(com.sun.appserv.management.config.SystemPropertiesAccess props)

	    final Map<String,String>    all = props.getSystemProperties();
	    
		final String[]	propNames			= props.getSystemPropertyNames();
		
		for( final String name : propNames )
		{
		    assert( props.existsSystemProperty( name ) );
			final String	value	= props.getSystemPropertyValue( name );
		}
	
public voidcheckSetPropertiesSetToSameValue(javax.management.ObjectName src)

		final SystemPropertiesAccess	props	= getProxy( src, SystemPropertiesAccess.class );
		
		testPropertiesSetToSameValue( props );
	
private java.util.SetgetAll()

		final Set<ObjectName>	objectNames	=
		    getQueryMgr().queryInterfaceObjectNameSet(
			    SystemPropertiesAccess.class.getName(), null);
	    
		return( objectNames );
	
private voidtestCreateEmptySystemProperty(com.sun.appserv.management.config.SystemPropertiesAccess props)

	    final String NAME   = "test.empty";
	    
		props.createSystemProperty( NAME, "" );
		assert( props.existsSystemProperty( NAME ) );
		props.removeSystemProperty( NAME );
		assert( ! props.existsSystemProperty( NAME ) );
	
public synchronized voidtestCreateRemove()

	    if ( checkNotOffline( "testCreateRemove" ) )
	    {
    		final Set<ObjectName>	all	= getAll();
    		testAll( all, "checkCreateRemove" );
	    }
	
public synchronized voidtestPropertiesGet()

		final Set<ObjectName>	all	= getAll();
		
		testAll( all, "checkGetProperties" );
	
public synchronized voidtestPropertiesSetToSameValue()

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

		final String[]	propNames			= props.getSystemPropertyNames();
		
		// 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 ];
			
			final String	value	= props.getSystemPropertyValue( propName );
			props.setSystemPropertyValue( propName, value );
			
			assert( props.getSystemPropertyValue( propName ).equals( value ) );
		}
	
private voidtestSystemPropertiesCreateRemove(com.sun.appserv.management.config.SystemPropertiesAccess props)

		final String[]	propNames			= props.getSystemPropertyNames();
		
		// 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.existsSystemProperty( testName ) )
			{
				failure( "test property already exists: " + testName );
			}
			
			props.createSystemProperty( testName, "value_" + i );
			assert( props.existsSystemProperty( testName ) );
		}
		final int	numProps	= props.getSystemPropertyNames().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.removeSystemProperty( testName );
			assert( ! props.existsSystemProperty( testName ) );
		}
		
		assert( props.getSystemPropertyNames().length == propNames.length );