1 23 24 28 package com.sun.enterprise.admin.monitor.stats; 29 30 import javax.management.j2ee.statistics.*; 31 import com.sun.enterprise.admin.monitor.stats.*; 32 import java.util.*; 33 import junit.framework.*; 34 35 40 public class GenericStatsImplTest extends TestCase { 41 42 public void testCorrectClassNameConstructor() { 43 try { 44 final String c = "javax.management.j2ee.statistics.EJBStats"; 45 final EJBStats provider = createEjbStatsProvider(); 46 final Stats stats = new GenericStatsImpl(c, provider); 47 assertNotNull("Object is not null", stats); 48 } 49 catch (Exception e) { 50 } 52 } 53 54 public void testInCorrectClassNameConstructor() { 55 try { 56 final String invalid = "javax.management.j2ee.statistics.UnknownStats"; 57 final EJBStats provider = createEjbStatsProvider(); 58 final Stats stats = new GenericStatsImpl(invalid, provider); 59 fail("How can javax.management.j2ee.statistics.UnknownStats be impl????"); 60 } 61 catch (Exception e) { 62 } 64 } 65 66 public void testInvalidInterface() { 67 try { 68 final String invalid = "java.io.Serializable"; 69 final EJBStats provider = createEjbStatsProvider(); 70 final Stats stats = new GenericStatsImpl(invalid, provider); 71 fail("We have not committed to java.io.Serializable as it is not a Stats interface"); 72 } 73 catch (Exception e) { 74 } 76 } 77 78 public void testGetStatisticNamesWithEjbStats() { 79 try { 80 final String c = "javax.management.j2ee.statistics.EJBStats"; 81 final EJBStats provider = createEjbStatsProvider(); 82 final Stats stats = new GenericStatsImpl(c, provider); 83 final String [] s1 = stats.getStatisticNames(); 84 final String [] s2 = new String []{"CreateCount", "RemoveCount"}; 85 final List ls1 = Arrays.asList(s1); 86 final List ls2 = Arrays.asList(s2); 87 assertTrue(ls1.containsAll(ls2)); assertEquals(s1.length, s2.length); 89 } 90 catch (Exception e) { 91 } 93 } 94 95 public void testGetAStatisticWithEjbStats() { 96 try { 97 final String c = "javax.management.j2ee.statistics.EJBStats"; 98 final EJBStats provider = createEjbStatsProvider(); 99 final Stats stats = new GenericStatsImpl(c, provider); 100 final String [] names = new String []{"CreateCount", "RemoveCount"}; 101 final CountStatistic c1 = new CountStatisticImpl(10, names[0], "", "Beans Created", 10, 10); 102 final CountStatistic c2 = new CountStatisticImpl(5, names[1], "", "Beans Removed", 10, 10); 103 104 105 final CountStatistic cc = (CountStatistic)stats.getStatistic(names[0]); 106 final CountStatistic rc = (CountStatistic)stats.getStatistic(names[1]); 107 assertEquals(c1.getCount(), cc.getCount()); 108 assertEquals(c1.getName(), cc.getName()); 109 110 final CountStatistic u = (CountStatistic)stats.getStatistic(names[1]); 111 assertEquals(c2.getCount(), rc.getCount()); 112 assertEquals(c2.getName(), rc.getName()); 113 114 115 final CountStatistic c3 = new CountStatisticImpl(1111, names[0], "", "Beans Created", 10, 10); 116 final CountStatistic c4 = new CountStatisticImpl(444, names[1], "", "Beans Removed", 10, 10); 117 118 assertTrue(c3.getCount() != cc.getCount()); 119 assertTrue(c4.getCount() != rc.getCount()); 120 } 121 catch (Exception e) { 122 } 124 } 125 public GenericStatsImplTest(java.lang.String testName) { 126 super(testName); 127 } 128 protected void setUp() { 129 } 130 131 protected void tearDown() { 132 } 133 private EJBStats createEjbStatsProvider() { 134 return new EjbStatsImpl(); 135 } 136 137 private static class EjbStatsImpl implements EJBStats, java.io.Serializable { 138 final Map m = new HashMap(); 139 final String [] names = new String []{"CreateCount", "RemoveCount"}; 140 final CountStatistic c = new CountStatisticImpl(10, names[0], "", "Beans Created", 10, 10); 141 final CountStatistic r = new CountStatisticImpl(5, names[1], "", "Beans Removed", 10, 10); 142 EjbStatsImpl() { 143 m.put(names[0], c); 144 m.put(names[1], r); 145 } 146 147 public CountStatistic getCreateCount() { 148 return ( c ); 149 } 150 151 public CountStatistic getRemoveCount() { 152 return ( r ); 153 } 154 155 public Statistic getStatistic(String str) { 156 return ( (Statistic) m.get(str) ); 157 } 158 159 public String [] getStatisticNames() { 160 return ( names ); 161 } 162 163 public Statistic[] getStatistics() { 164 return ( (Statistic[]) m.values().toArray() ); 165 } 166 } 167 168 public static Test suite() { 169 TestSuite suite = new TestSuite(GenericStatsImplTest.class); 170 return suite; 171 } 172 173 public static void main(String args[]){ 174 junit.textui.TestRunner.run(suite()); 175 } 177 178 } 179 | Popular Tags |