1 23 24 28 29 35 36 package com.sun.enterprise.admin.monitor.util; 37 38 import junit.framework.*; 39 import javax.management.j2ee.statistics.*; 40 import javax.management.*; 41 42 46 public class MonitoringRegistrationHelperTest extends TestCase { 47 55 56 public void testRegisteredMBean(){ 57 Stats stats = new S1ASJVMStatsImplMock(); 58 try{ 59 boolean done = mrh.registerStats(stats, "JVMStats"); 60 assertTrue(done); 61 MBeanServer server = (MBeanServer) (MBeanServerFactory.findMBeanServer(null)).get(0); 62 assertNotNull(server); 63 ObjectName obj = new ObjectName("defaultDomain:name=JVMStats,type=statsMonitor"); 64 MBeanInfo mInfo = (MBeanInfo)server.getMBeanInfo(obj); 65 assertNotNull(mInfo); 66 MBeanAttributeInfo[] attrInfo = mInfo.getAttributes(); 67 assertNotNull(attrInfo); 68 for(int i=0; i<attrInfo.length;i++){ 69 String attr = attrInfo[i].getName(); 70 System.out.println("getting attribute:"+attr); 71 Object n = server.getAttribute(obj,attr); 72 try{ 73 assertEquals(Long .class, n.getClass()); 74 } 75 catch(Error ex){ 76 ex.getLocalizedMessage(); 77 assertEquals(String .class, n.getClass()); 78 } 79 catch(Exception e){ 80 assertNull(n); 81 } 82 } 83 } 84 catch(Exception ex){ 85 ex.printStackTrace(); 86 assertEquals(NullPointerException .class, ex.getClass()); 87 } 88 } 89 90 public void testUnregisterStats(){ 91 Stats stats = new S1ASJVMStatsImplMock(); 92 try{ 93 boolean done = mrh.registerStats(stats, "JVMStats"); 94 assertTrue(done); 95 done = mrh.unregisterStats("JVMStats"); 96 assertTrue(done); 97 }catch(Exception e){ 98 e.getLocalizedMessage(); 99 } 100 } 101 102 public void testRegisterStats(){ 103 Stats stats = new S1ASJVMStatsImplMock(); 104 try{ 105 boolean done = mrh.registerStats(stats, "JVMStats"); 106 assertTrue(done); 107 }catch(Exception e){ 108 e.getLocalizedMessage(); 109 } 110 } 111 112 public void testCreation(){ 113 assertNotNull(mrh); 114 } 115 116 public MonitoringRegistrationHelperTest(java.lang.String testName) { 117 super(testName); 118 } 119 120 MonitoringRegistration mrh; 121 protected void setUp() { 122 mrh = MonitoringRegistrationHelper.getInstance(); 123 } 124 125 protected void tearDown() { 126 127 } 128 public static Test suite() { 129 TestSuite suite = new TestSuite(MonitoringRegistrationHelperTest.class); 130 return suite; 131 } 132 133 public static void main(String [] args){ 134 junit.textui.TestRunner.run(suite()); 135 } 136 } 137 | Popular Tags |