FileDocCategorySizeDatePackage
GenericStatsImplTest.javaAPI DocGlassfish v2 API7050Fri May 04 22:25:54 BST 2007com.sun.enterprise.admin.monitor.stats

GenericStatsImplTest

public class GenericStatsImplTest extends TestCase
Tests the class GenericStatsImplTescc. No need to import the class being tested, as the package name is the same.
author
Kedar Mhaswade
version
$Revision: 1.3 $

Fields Summary
Constructors Summary
public GenericStatsImplTest(String testName)

		super(testName);
	
Methods Summary
private EJBStatscreateEjbStatsProvider()

		return new EjbStatsImpl();
	
public static voidmain(java.lang.String[] args)

		junit.textui.TestRunner.run(suite());
		//junicc.swingui.TestRunner.run(suite());
	
protected voidsetUp()

	
public static junit.framework.Testsuite()

		TestSuite suite = new TestSuite(GenericStatsImplTest.class);
		return suite;
	
protected voidtearDown()

	
public voidtestCorrectClassNameConstructor()

		try {
			final String c = "javax.management.j2ee.statistics.EJBStats";
			final EJBStats provider = createEjbStatsProvider();
			final Stats stats = new GenericStatsImpl(c, provider);
			assertNotNull("Object is not null", stats);
		}
		catch (Exception e) {
			// It should never get here as this should never be exceptional
		}
	
public voidtestGetAStatisticWithEjbStats()

		try {
			final String c = "javax.management.j2ee.statistics.EJBStats";
			final EJBStats provider = createEjbStatsProvider();
			final Stats stats = new GenericStatsImpl(c, provider);
			final String[] names = new String[]{"CreateCount", "RemoveCount"};
			final CountStatistic c1 = new CountStatisticImpl(10, names[0], "", "Beans Created", 10, 10);
			final CountStatistic c2 = new CountStatisticImpl(5, names[1], "", "Beans Removed", 10, 10);

			/* tests for equality */
			final CountStatistic cc = (CountStatistic)stats.getStatistic(names[0]);
			final CountStatistic rc = (CountStatistic)stats.getStatistic(names[1]);
			assertEquals(c1.getCount(), cc.getCount());
			assertEquals(c1.getName(), cc.getName());

			final CountStatistic  u = (CountStatistic)stats.getStatistic(names[1]);
			assertEquals(c2.getCount(), rc.getCount());
			assertEquals(c2.getName(), rc.getName());

			/* tests for inequality */
			final CountStatistic c3 = new CountStatisticImpl(1111, names[0], "", "Beans Created", 10, 10);
			final CountStatistic c4 = new CountStatisticImpl(444, names[1], "", "Beans Removed", 10, 10);
			
			assertTrue(c3.getCount() != cc.getCount());			
			assertTrue(c4.getCount() != rc.getCount());
		}
		catch (Exception e) {
			// It should never get here as this should never be exceptional
		}
	
public voidtestGetStatisticNamesWithEjbStats()

		try {
			final String c = "javax.management.j2ee.statistics.EJBStats";
			final EJBStats provider = createEjbStatsProvider();
			final Stats stats = new GenericStatsImpl(c, provider);
			final String[] s1 = stats.getStatisticNames();
			final String[] s2 = new String[]{"CreateCount", "RemoveCount"};
			final List ls1 = Arrays.asList(s1);
			final List ls2 = Arrays.asList(s2);
			assertTrue(ls1.containsAll(ls2)); //order is unimportant
			assertEquals(s1.length, s2.length);
		}
		catch (Exception e) {
			// It should never get here as this should never be exceptional
		}
	
public voidtestInCorrectClassNameConstructor()

		try {
			final String invalid = "javax.management.j2ee.statistics.UnknownStats";
			final EJBStats provider = createEjbStatsProvider();
			final Stats stats = new GenericStatsImpl(invalid, provider);
			fail("How can javax.management.j2ee.statistics.UnknownStats be impl????");
		}
		catch (Exception e) {
			//We always should get this exception -- so this test should PASS.
		}
	
public voidtestInvalidInterface()

		try {
			final String invalid = "java.io.Serializable";
			final EJBStats provider = createEjbStatsProvider();
			final Stats stats = new GenericStatsImpl(invalid, provider);
			fail("We have not committed to java.io.Serializable as it is not a Stats interface");
		}
		catch (Exception e) {
			//We always should get this exception -- so this test should PASS.
		}