FileDocCategorySizeDatePackage
ValueListMapTest.javaAPI DocGlassfish v2 API6394Fri May 04 22:24:28 BST 2007com.sun.enterprise.admin.monitor.registry.spi

ValueListMapTest

public class ValueListMapTest extends TestCase
author
Kedar Mhaswade
since
$Revision: 1.4 $

Fields Summary
private MonitoringLevelListener[]
jvml
private MonitoringLevelListener[]
ejbl
Constructors Summary
public ValueListMapTest(String testName)

		super(testName);
		createListeners();
	
Methods Summary
private voidcreateListeners()

		final int nj = 2;
		jvml = new MonitoringLevelListener[nj];
		jvml[0] = new JvmListener();
		jvml[1] = new JvmListener();
		final int ne = 3;
		ejbl = new MonitoringLevelListener[ne];
		ejbl[0] = new EjbListener();
		ejbl[1] = new EjbListener();
		ejbl[2] = new EjbListener();
	
public static voidmain(java.lang.String[] args)

		junit.textui.TestRunner.run(suite());
		//junit.swingui.TestRunner.run(suite());
	
private voidnyi()

		fail("Not yet implemented");
	
protected voidsetUp()

	
public static junit.framework.Testsuite()

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

	
public voidtestAddOneListenerForTwoTypes()

		final Map m = new ValueListMap();
		m.put(MonitoredObjectType.JVM, jvml[0]);
		m.put(MonitoredObjectType.EJB, jvml[0]);
		//now there should be two keys created
		assertEquals(m.keySet().size(), 2);
		//removed Collection should also contain 2 elements.
		final Collection removed = (Collection) m.remove(jvml[0]); //It is a collection
		assertEquals(removed.size(), 2);
		final Iterator it = removed.iterator();
		while (it.hasNext()) {
			assertSame(jvml[0], it.next());
		}
	
public voidtestCreateMap()

		final Map m = new ValueListMap();
	
public voidtestInvalidPut()

		try {
			final Map m = new ValueListMap(); //value with listener class.
			final String key = "key1";
			final String val = "Invalid Value"; //attempt to put a value with String class.
			m.put(key, val);
			fail ("Should have thrown IllegalArgumentException - Failed Test");
		}
		catch(IllegalArgumentException e) {}
	
public voidtestJvmListenerAdd()

		final Map m = new ValueListMap();
		m.put(MonitoredObjectType.JVM, jvml[0]);
		m.put(MonitoredObjectType.JVM, jvml[1]);
		final Map n = (Map) m.get(MonitoredObjectType.JVM); //I know it is a map
		assertEquals(n.keySet().size(), 2);
	
public voidtestJvmListenerAddRemove()

		final Map m = new ValueListMap();
		m.put(MonitoredObjectType.JVM, jvml[0]);
		m.put(MonitoredObjectType.JVM, jvml[1]);
		m.remove(jvml[1]);
		final Map n = (Map) m.get(MonitoredObjectType.JVM); //I know it is a map
		assertEquals(n.keySet().size(), 1);
	
public voidtestRemoveJvmType()

		final Map m = new ValueListMap();
		m.put(MonitoredObjectType.JVM, jvml[0]);
		m.put(MonitoredObjectType.JVM, jvml[1]);
		final Collection removed = (Collection)m.remove(MonitoredObjectType.JVM);
		assertEquals(m.get(MonitoredObjectType.JVM), null);
		assertEquals(removed.size(), 2);
		final Iterator it = removed.iterator();
		while (it.hasNext()) {
			final Object n = it.next();
			assertTrue(n == jvml[0] || n == jvml[1]); //order is not known
		}