1 22 package test.implementation.registry; 23 24 import java.util.Date ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 28 import javax.management.MBeanServer ; 29 import javax.management.MBeanServerFactory ; 30 import javax.management.ObjectName ; 31 32 import junit.framework.TestCase; 33 34 import org.jboss.mx.server.ServerConstants; 35 36 import test.implementation.registry.support.Trivial; 37 38 43 public class ValuesTestCase 44 extends TestCase 45 implements ServerConstants 46 { 47 49 51 54 public ValuesTestCase(String s) 55 { 56 super(s); 57 } 58 59 61 64 public void testClassLoader() 65 throws Exception 66 { 67 String previous = System.getProperty(MBEAN_REGISTRY_CLASS_PROPERTY); 69 if (previous == null) 70 previous = DEFAULT_MBEAN_REGISTRY_CLASS; 71 MBeanServer server = MBeanServerFactory.createMBeanServer(); 74 try 75 { 76 HashMap valuesMap = new HashMap (); 77 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 78 valuesMap.put(CLASSLOADER, Thread.currentThread().getContextClassLoader()); 79 ObjectName mbean = new ObjectName ("test:test=test"); 80 server.invoke(new ObjectName (MBEAN_REGISTRY), "registerMBean", 81 new Object [] 82 { 83 new Trivial(), 84 mbean, 85 valuesMap 86 }, 87 new String [] 88 { 89 Object .class.getName(), 90 ObjectName .class.getName(), 91 Map .class.getName() 92 } 93 ); 94 Object result = server.invoke(new ObjectName (MBEAN_REGISTRY), "getValue", 95 new Object [] 96 { 97 mbean, 98 CLASSLOADER 99 }, 100 new String [] 101 { 102 ObjectName .class.getName(), 103 String .class.getName() 104 } 105 ); 106 assertEquals(cl, result); 107 } 108 finally 109 { 110 MBeanServerFactory.releaseMBeanServer(server); 111 System.setProperty(MBEAN_REGISTRY_CLASS_PROPERTY, previous); 112 } 113 } 114 115 118 public void testValue() 119 throws Exception 120 { 121 String previous = System.getProperty(MBEAN_REGISTRY_CLASS_PROPERTY); 123 if (previous == null) 124 previous = DEFAULT_MBEAN_REGISTRY_CLASS; 125 MBeanServer server = MBeanServerFactory.createMBeanServer(); 128 try 129 { 130 HashMap valuesMap = new HashMap (); 131 Date date = new Date (System.currentTimeMillis()); 132 valuesMap.put("date", date); 133 ObjectName mbean = new ObjectName ("test:test=test"); 134 server.invoke(new ObjectName (MBEAN_REGISTRY), "registerMBean", 135 new Object [] 136 { 137 new Trivial(), 138 mbean, 139 valuesMap 140 }, 141 new String [] 142 { 143 Object .class.getName(), 144 ObjectName .class.getName(), 145 Map .class.getName() 146 } 147 ); 148 Object result = server.invoke(new ObjectName (MBEAN_REGISTRY), "getValue", 149 new Object [] 150 { 151 mbean, 152 "date" 153 }, 154 new String [] 155 { 156 ObjectName .class.getName(), 157 String .class.getName() 158 } 159 ); 160 assertEquals(date, result); 161 } 162 finally 163 { 164 MBeanServerFactory.releaseMBeanServer(server); 165 System.setProperty(MBEAN_REGISTRY_CLASS_PROPERTY, previous); 166 } 167 } 168 169 172 public void testValueRegistered() 173 throws Exception 174 { 175 String previous = System.getProperty(MBEAN_REGISTRY_CLASS_PROPERTY); 177 if (previous == null) 178 previous = DEFAULT_MBEAN_REGISTRY_CLASS; 179 MBeanServer server = MBeanServerFactory.createMBeanServer(); 182 try 183 { 184 HashMap valuesMap = new HashMap (); 185 Date date = new Date (System.currentTimeMillis()); 186 valuesMap.put("date", date); 187 ObjectName mbean = new ObjectName ("test:test=test"); 188 server.invoke(new ObjectName (MBEAN_REGISTRY), "registerMBean", 189 new Object [] 190 { 191 new Trivial(), 192 mbean, 193 valuesMap 194 }, 195 new String [] 196 { 197 Object .class.getName(), 198 ObjectName .class.getName(), 199 Map .class.getName() 200 } 201 ); 202 Object result = server.invoke(new ObjectName (MBEAN_REGISTRY), "getValue", 203 new Object [] 204 { 205 mbean, 206 "date" 207 }, 208 new String [] 209 { 210 ObjectName .class.getName(), 211 String .class.getName() 212 } 213 ); 214 assertEquals(date, result); 215 216 server.unregisterMBean(mbean); 218 219 Thread.sleep(2); 220 date = new Date (System.currentTimeMillis()); 221 HashMap valueMap2 = new HashMap (); 222 valueMap2.put("date", date); 223 server.invoke(new ObjectName (MBEAN_REGISTRY), "registerMBean", 224 new Object [] 225 { 226 new Trivial(), 227 mbean, 228 valueMap2 229 }, 230 new String [] 231 { 232 Object .class.getName(), 233 ObjectName .class.getName(), 234 Map .class.getName() 235 } 236 ); 237 result = server.invoke(new ObjectName (MBEAN_REGISTRY), "getValue", 238 new Object [] 239 { 240 mbean, 241 "date" 242 }, 243 new String [] 244 { 245 ObjectName .class.getName(), 246 String .class.getName() 247 } 248 ); 249 assertEquals(date, result); 250 } 251 finally 252 { 253 MBeanServerFactory.releaseMBeanServer(server); 254 System.setProperty(MBEAN_REGISTRY_CLASS_PROPERTY, previous); 255 } 256 } 257 } 258 | Popular Tags |