1 23 24 29 package com.sun.enterprise.admin.monitor.registry.spi; 30 31 import javax.management.j2ee.statistics.*; 32 import com.sun.enterprise.admin.monitor.registry.*; 33 import com.sun.enterprise.admin.monitor.stats.*; 34 import java.util.*; 35 import junit.framework.*; 36 37 41 public class ValueListMapTest extends TestCase { 42 43 44 private MonitoringLevelListener[] jvml; 45 private MonitoringLevelListener[] ejbl; 46 public void testCreateMap() { 47 final Map m = new ValueListMap(); 48 } 49 public void testInvalidPut() { 50 try { 51 final Map m = new ValueListMap(); final String key = "key1"; 53 final String val = "Invalid Value"; m.put(key, val); 55 fail ("Should have thrown IllegalArgumentException - Failed Test"); 56 } 57 catch(IllegalArgumentException e) {} 58 } 59 public void testJvmListenerAdd() { 60 final Map m = new ValueListMap(); 61 m.put(MonitoredObjectType.JVM, jvml[0]); 62 m.put(MonitoredObjectType.JVM, jvml[1]); 63 final Map n = (Map) m.get(MonitoredObjectType.JVM); assertEquals(n.keySet().size(), 2); 65 } 66 public void testJvmListenerAddRemove() { 67 final Map m = new ValueListMap(); 68 m.put(MonitoredObjectType.JVM, jvml[0]); 69 m.put(MonitoredObjectType.JVM, jvml[1]); 70 m.remove(jvml[1]); 71 final Map n = (Map) m.get(MonitoredObjectType.JVM); assertEquals(n.keySet().size(), 1); 73 } 74 75 public void testRemoveJvmType() { 76 final Map m = new ValueListMap(); 77 m.put(MonitoredObjectType.JVM, jvml[0]); 78 m.put(MonitoredObjectType.JVM, jvml[1]); 79 final Collection removed = (Collection)m.remove(MonitoredObjectType.JVM); 80 assertEquals(m.get(MonitoredObjectType.JVM), null); 81 assertEquals(removed.size(), 2); 82 final Iterator it = removed.iterator(); 83 while (it.hasNext()) { 84 final Object n = it.next(); 85 assertTrue(n == jvml[0] || n == jvml[1]); } 87 } 88 89 public void testAddOneListenerForTwoTypes() { 90 final Map m = new ValueListMap(); 91 m.put(MonitoredObjectType.JVM, jvml[0]); 92 m.put(MonitoredObjectType.EJB, jvml[0]); 93 assertEquals(m.keySet().size(), 2); 95 final Collection removed = (Collection) m.remove(jvml[0]); assertEquals(removed.size(), 2); 98 final Iterator it = removed.iterator(); 99 while (it.hasNext()) { 100 assertSame(jvml[0], it.next()); 101 } 102 } 103 public ValueListMapTest(java.lang.String testName) { 104 super(testName); 105 createListeners(); 106 } 107 protected void setUp() { 108 } 109 110 protected void tearDown() { 111 } 112 113 private void createListeners() { 114 final int nj = 2; 115 jvml = new MonitoringLevelListener[nj]; 116 jvml[0] = new JvmListener(); 117 jvml[1] = new JvmListener(); 118 final int ne = 3; 119 ejbl = new MonitoringLevelListener[ne]; 120 ejbl[0] = new EjbListener(); 121 ejbl[1] = new EjbListener(); 122 ejbl[2] = new EjbListener(); 123 } 124 125 private static class JvmListener implements MonitoringLevelListener { 126 JvmListener() { 127 } 128 public void changeLevel(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType type) { 129 System.out.println("from = " + from + " to = " + to + " type = " + type); 130 } 131 132 public void changeLevel(MonitoringLevel from, MonitoringLevel to, javax.management.j2ee.statistics.Stats handback) { 133 } 135 public void setLevel(MonitoringLevel level) { 136 } 138 } 139 private static class EjbListener implements MonitoringLevelListener { 140 EjbListener() { 141 } 142 public void changeLevel(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType type) { 143 System.out.println("from = " + from + " to = " + to + " type = " + type); 144 } 145 146 public void changeLevel(MonitoringLevel from, MonitoringLevel to, javax.management.j2ee.statistics.Stats handback) { 147 } 149 public void setLevel(MonitoringLevel level) { 150 } 152 } 153 private void nyi() { 154 fail("Not yet implemented"); 155 } 156 157 public static Test suite(){ 158 TestSuite suite = new TestSuite(ValueListMapTest.class); 159 return suite; 160 } 161 162 public static void main(String args[]){ 163 junit.textui.TestRunner.run(suite()); 164 } 166 167 } 168 | Popular Tags |