1 22 package test.implementation.modelmbean; 23 24 import javax.management.Attribute ; 25 import javax.management.Descriptor ; 26 import javax.management.MBeanServer ; 27 import javax.management.MBeanServerFactory ; 28 import javax.management.ObjectName ; 29 import javax.management.modelmbean.DescriptorSupport ; 30 31 import junit.framework.TestCase; 32 33 import org.jboss.mx.modelmbean.XMBean; 34 import org.jboss.mx.modelmbean.XMBeanConstants; 35 36 import test.implementation.modelmbean.support.Trivial; 37 import test.implementation.modelmbean.support.User; 38 39 46 public class XMBeanTEST extends TestCase implements XMBeanConstants 47 { 48 public XMBeanTEST(String s) 49 { 50 super(s); 51 } 52 53 public void testCreateXMBean() throws Exception 54 { 55 MBeanServer server = MBeanServerFactory.createMBeanServer(); 56 57 Descriptor d = new DescriptorSupport (); 58 d.setField(RESOURCE_REFERENCE, new User()); 59 d.setField(RESOURCE_TYPE, "file:./src/main/test/implementation/modelmbean/support/xml/UserManagementInterface.xml"); 60 d.setField(SAX_PARSER, "org.apache.crimson.parser.XMLReaderImpl"); 61 62 XMBean mmb = new XMBean(d, DESCRIPTOR); 63 64 ObjectName name = new ObjectName (":test=test"); 65 66 server.registerMBean(mmb, name); 67 assertTrue(server.isRegistered(name)); 68 69 server.setAttribute(name, new Attribute ("Name", "Juha")); 70 assertTrue(server.getAttribute(name, "Name").equals("Juha")); 71 72 server.setAttribute(name, new Attribute ("Address", "StrawBerry Street")); 73 assertTrue(server.getAttribute(name, "Address").equals("StrawBerry Street")); 74 75 assertTrue(server.invoke(name, "printInfo", null, null) instanceof String ); 76 } 77 78 public void testCreateWithJBossXMBean10DTD() throws Exception 79 { 80 MBeanServer server = MBeanServerFactory.createMBeanServer(); 81 Descriptor d = new DescriptorSupport (); 82 d.setField(RESOURCE_REFERENCE, new User()); 83 d.setField(RESOURCE_TYPE, "file:./src/main/test/implementation/modelmbean/support/xml/User.xml"); 84 d.setField(SAX_PARSER, "org.apache.crimson.parser.XMLReaderImpl"); 85 86 XMBean mmb = new XMBean(d, DESCRIPTOR); 87 88 server.registerMBean(mmb, new ObjectName (":test=test")); 89 90 assertTrue(server.isRegistered(new ObjectName (":test=test"))); 91 92 server.setAttribute(new ObjectName (":test=test"), new Attribute ("Name", "Juha")); 93 94 assertTrue(server.getAttribute(new ObjectName (":test=test"), "Name").equals("Juha")); 95 96 } 97 98 public void testCreateWithStandardInterface() throws Exception 99 { 100 MBeanServer server = MBeanServerFactory.createMBeanServer(); 101 Trivial trivial = new Trivial(); 102 ObjectName name = new ObjectName (":foo=bar"); 103 104 XMBean mmb = new XMBean(trivial, XMBeanConstants.STANDARD_INTERFACE); 105 server.registerMBean(mmb, name); 106 107 assertTrue(server.isRegistered(new ObjectName (":foo=bar"))); 108 109 server.setAttribute(name, new Attribute ("Something", "foobar")); 110 assertTrue(server.getAttribute(name, "Something").equals("foobar")); 111 112 Boolean b = (Boolean )server.invoke(name, "doOperation", new Object [] { "" }, new String [] { "java.lang.String" }); 113 assertTrue(b.booleanValue() == true); 114 } 115 116 117 } 118 | Popular Tags |