1 23 24 28 29 35 36 package com.sun.enterprise.admin.monitor.registry.spi; 37 import com.sun.enterprise.admin.monitor.registry.*; 38 import junit.framework.*; 39 import javax.management.j2ee.statistics.*; 40 import javax.management.*; 41 import java.util.*; 42 43 47 public class MonitoringRegistrationHelperTest extends TestCase implements MonitoringLevelListener { 48 56 57 public void testRegisteredMBean(){ 58 try{ 59 assertNotNull(server); 60 ObjectName obj = getObjectName(); 61 Stats stats = new S1ASJVMStatsImplMock(); 62 try{ 63 mrh.registerJVMStats((JVMStats)stats, this); 64 } 65 catch(Exception e){ 66 e.printStackTrace(); 67 assertEquals("MonitoringRegistrationException", e.getClass().getName()); 68 } 69 MBeanInfo mInfo = (MBeanInfo)server.getMBeanInfo(obj); 71 assertNotNull(mInfo); 72 MBeanAttributeInfo[] attrInfo = mInfo.getAttributes(); 73 assertNotNull(attrInfo); 74 for(int i=0; i<attrInfo.length;i++){ 75 String attr = attrInfo[i].getName(); 76 System.out.println("getting attribute:"+attr); 77 Object n = server.getAttribute(obj,attr); 78 try{ 79 assertEquals(Long .class, n.getClass()); 80 } 81 catch(Error ex){ 82 ex.getLocalizedMessage(); 83 assertEquals(String .class, n.getClass()); 84 } 85 catch(Exception e){ 86 assertNull(n); 87 } 88 } 89 } 90 catch(Exception ex){ 91 ex.printStackTrace(); 92 assertEquals(NullPointerException .class, ex.getClass()); 93 } 94 } 95 96 public void testUnregisterStats(){ 97 try{ 98 ObjectName obj = getObjectName(); 99 mrh.unregisterJVMStats(); 100 assertEquals(false, server.isRegistered(obj)); 101 assertEquals(0, server.queryMBeans(obj, null).size()); 102 }catch(Exception e){ 103 e.getLocalizedMessage(); 104 } 105 } 106 107 public void testRegisterStats(){ 108 try{ 109 ObjectName obj = getObjectName(); 110 Stats stats = new S1ASJVMStatsImplMock(); 111 try{ 112 mrh.registerJVMStats((JVMStats)stats, this); 113 } 114 catch(Exception e){ 115 e.printStackTrace(); 116 assertEquals("MonitoringRegistrationException", e.getClass().getName()); 117 } 118 119 assertEquals(1, server.getMBeanCount().intValue()); 120 assertEquals(true, server.isInstanceOf(obj, "GeneratedMonitoringMBeanImpl")); 121 }catch(Exception e){ 122 e.getLocalizedMessage(); 123 } 124 } 125 126 public void testCreation(){ 127 assertNotNull(mrh); 128 } 129 130 public MonitoringRegistrationHelperTest(java.lang.String testName) { 131 super(testName); 132 } 133 134 MonitoringRegistry mrh; 135 MBeanServer server; 136 137 protected void setUp() { 138 server = (MBeanServer) (MBeanServerFactory.createMBeanServer(null)); 139 mrh = MonitoringRegistrationHelper.getInstance(); 140 } 141 private ObjectName getObjectName(){ 142 ObjectName obj =null; 143 try{ 144 obj = new ObjectName("defaultDomain:category=monitor,type=jvm,name=jvm"); 145 }catch (Exception e){ 146 e.printStackTrace(); 147 } 148 return obj; 149 } 150 protected void tearDown() { 151 152 } 153 public static Test suite() { 154 TestSuite suite = new TestSuite(MonitoringRegistrationHelperTest.class); 155 return suite; 156 } 157 158 public static void main(String [] args){ 159 junit.textui.TestRunner.run(suite()); 160 } 161 162 public void setLevel(MonitoringLevel level) { 163 164 } 165 166 public void changeLevel(MonitoringLevel from, MonitoringLevel to, MonitoredObjectType type) { 167 } 168 169 public void changeLevel(MonitoringLevel from, MonitoringLevel to, javax.management.j2ee.statistics.Stats handback) { 170 } 171 172 } 173 | Popular Tags |