1 46 47 package groovy.util; 48 49 import javax.management.MBeanServer ; 50 import javax.management.MBeanServerFactory ; 51 import javax.management.ObjectName ; 52 53 import groovy.lang.GroovyObject; 54 55 import org.codehaus.groovy.classgen.TestSupport; 56 57 64 public class MBeanTest extends TestSupport { 65 66 public void testGetProperty() throws Exception { 67 MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(); 68 ObjectName name = new ObjectName ("groovy.test:role=TestMBean,type=Dummy"); 69 mbeanServer.registerMBean(new Dummy(), name); 70 71 assertEquals("JMX value of Name", "James", mbeanServer.getAttribute(name, "Name")); 72 73 GroovyObject object = new GroovyMBean(mbeanServer, name); 74 75 Object value = object.getProperty("Name"); 76 assertEquals("Name property", "James", value); 77 78 object.setProperty("Name", "Bob"); 79 assertEquals("Name property", "Bob", object.getProperty("Name")); 80 81 assertEquals("JMX value of Name", "Bob", mbeanServer.getAttribute(name, "Name")); 83 } 84 } 85 | Popular Tags |