1 23 24 28 29 34 35 package com.sun.enterprise.admin.monitor.registry.spi; 36 37 import junit.framework.*; 38 import javax.management.j2ee.statistics.Stats ; 39 import javax.management.*; 40 import java.util.*; 41 42 48 public class GeneratedMonitoringMBeanTest extends TestCase{ 49 50 public void testGetAttributeWithNull(){ 51 try{ 52 Enumeration e = attributes.keys(); 53 while(e.hasMoreElements()){ 54 Object n = mbean.getAttribute(null); 55 try{ 56 assertEquals(Long .class, n.getClass()); 57 } 58 catch(Error ex){ 59 ex.getLocalizedMessage(); 60 assertEquals(String .class, n.getClass()); 61 } 62 } 63 } 64 catch(Exception ex){ 65 assertEquals(NullPointerException .class, ex.getClass()); 66 } 67 } 68 69 public void testGetAttributeWithIncorrectAttrName(){ 70 try{ 71 Enumeration e = attributes.keys(); 72 while(e.hasMoreElements()){ 73 String elem = (String )e.nextElement(); 74 Object n = mbean.getAttribute(elem+"o"); 75 try{ 76 assertEquals(Long .class, n.getClass()); 77 } 78 catch(Error ex){ 79 ex.getLocalizedMessage(); 80 assertEquals(String .class, n.getClass()); 81 } 82 } 83 } 84 catch(Exception ex){ 85 assertEquals(AttributeNotFoundException.class, ex.getClass()); 86 } 87 } 88 89 public void testGetAttributeWithCorrectAttrName(){ 90 try{ 91 Enumeration e = attributes.keys(); 92 while(e.hasMoreElements()){ 93 String elem = (String )e.nextElement(); 94 Object n = mbean.getAttribute(elem); 95 try{ 96 assertEquals(Long .class, n.getClass()); 97 } 98 catch(Error ex){ 99 ex.getLocalizedMessage(); 100 assertEquals(String .class, n.getClass()); 101 } 102 } 103 } 104 catch(Exception ex){ 105 assertEquals(NullPointerException .class, ex.getClass()); 106 } 107 } 108 public void testAtrributes(){ 109 Enumeration en = attributes.elements(); 110 while(en.hasMoreElements()){ 111 String attr = (String )en.nextElement(); 112 System.out.println("testing attribute:"+attr); 113 try{ assertEquals("HeapSize", attr.substring(0,attr.indexOf("_"))); 114 }catch(Error ex){ 115 try{assertEquals("MaxMemory",attr.substring(0,attr.indexOf("_"))); 116 }catch(Error e){ 117 try{assertEquals("UpTime",attr.substring(0,attr.indexOf("_"))); 118 }catch(Error e1){ 119 assertEquals("AvailableProcessors",attr.substring(0,attr.indexOf("_"))); 120 } 121 } 122 } 123 } 124 } 125 126 public void testCreation(){ 127 assertNotNull(mbean); 128 assertNotNull(m); 129 assertNotNull(jvm); 130 assertNotNull(attrs); 131 } 132 133 public GeneratedMonitoringMBeanTest(java.lang.String testName) { 134 super(testName); 135 } 136 GeneratedMonitoringMBeanImpl mbean; 137 S1ASJVMStatsImplMock jvm; 138 MBeanInfo m; 139 MBeanAttributeInfo[] attrs; 140 Hashtable attributes = new Hashtable(); 141 142 protected void setUp() { 143 jvm = new S1ASJVMStatsImplMock(); 144 mbean = new GeneratedMonitoringMBeanImpl(jvm); 145 m = mbean.introspect(); 146 attrs = m.getAttributes(); 147 for(int i=0; i< attrs.length;i++){ 148 attributes.put(attrs[i].getName(),attrs[i].getName()); 149 } 150 } 151 152 protected void tearDown() { 153 154 } 155 156 public static Test suite() { 157 TestSuite suite = new TestSuite(GeneratedMonitoringMBeanTest.class); 158 return suite; 159 } 160 161 public static void main(String [] args){ 162 junit.textui.TestRunner.run(suite()); 163 } 164 } 165 | Popular Tags |