FileDocCategorySizeDatePackage
StatisticTest.javaAPI DocGlassfish v2 API6059Fri May 04 22:24:06 BST 2007com.sun.enterprise.management.monitor

StatisticTest

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

Fields Summary
Constructors Summary
public StatisticTest()

    
Methods Summary
private voidcheckOpenDataConversion(javax.management.j2ee.statistics.Statistic s)

    	final CompositeData	d	= J2EEUtil.statisticToCompositeData( s );
    	final Statistic	roundTrip	= StatisticFactory.create( d );
    	
		assert( s.equals( roundTrip ) ) :
			"Conversion to CompositeData and back to Statistic failed:\n" +
			toString( s ) + " != " + toString( roundTrip );
    
public voidtestAnyOpenDataConversion()

		// verify that anything implementing Statistic works correctly
		final TestStatistic		test	= new TestStatistic();
		final MapStatisticImpl	testMap	= new MapStatisticImpl( test );
		assert( testMap.getValue( "Foo" ).equals( new Integer( test.getFoo() ) ) );
		assert( testMap.getValue( "Bar" ).equals(  test.getBar() ) );
		
    	final CompositeData	d	= J2EEUtil.statisticToCompositeData( testMap );
    	final CompositeType	t	= d.getCompositeType();
    	final Set<String> values	= TypeCast.asSet( t.keySet() );
    	assert( values.contains( "Name" ) );
    	assert( values.contains( "Foo" ) );
    	assert( values.contains( "Bar" ) );
    	
    	final MapStatisticImpl	roundTrip	= (MapStatisticImpl)StatisticFactory.create( d );
		assert( new Integer( test.getFoo() ).equals( roundTrip.getValue( "Foo" ) ) );
		assert( test.getBar().equals( roundTrip.getValue( "Bar" ) ) );
	
public voidtestStdOpenDataConversion()

		final CountStatisticImpl	c	=
			new CountStatisticImpl( "Count", "desc", "number", 0, now(), 99);
			
		final RangeStatisticImpl	r	=
			new RangeStatisticImpl( "Range", "desc", "number", 0, now(), 0, 50, 100);
			
		final BoundaryStatisticImpl	b	=
			new BoundaryStatisticImpl( "Boundary", "desc", "number", 0, now(), 0, 100);
			
		final BoundedRangeStatisticImpl	br	=
			new BoundedRangeStatisticImpl( "BoundedRange", "desc", "number", 0, now(), 0, 50, 100, 0, 100);
			
		final TimeStatisticImpl	t		=
			new TimeStatisticImpl( "Time", "desc", "seconds", 0, now(), 1, 10, 100, 1000);
			
		final StringStatisticImpl	s		=
			new StringStatisticImpl( "String", "desc", "chars", 0, now(), "hello" );
		
		final NumberStatisticImpl	n		=
			new NumberStatisticImpl( "Number", "desc", "number", 0, now(), 1234.56 );
                
		checkOpenDataConversion( c );
		checkOpenDataConversion( r );
		checkOpenDataConversion( b );
		checkOpenDataConversion( br );
		checkOpenDataConversion( t );
		checkOpenDataConversion( s );
		checkOpenDataConversion( n );