1 22 package org.jboss.test.jbossmx.compliance.standard; 23 24 import org.jboss.test.jbossmx.compliance.TestCase; 25 import org.jboss.test.jbossmx.compliance.standard.support.Trivial; 26 27 import javax.management.InstanceAlreadyExistsException ; 28 import javax.management.InstanceNotFoundException ; 29 import javax.management.IntrospectionException ; 30 import javax.management.MBeanAttributeInfo ; 31 import javax.management.MBeanConstructorInfo ; 32 import javax.management.MBeanInfo ; 33 import javax.management.MBeanNotificationInfo ; 34 import javax.management.MBeanOperationInfo ; 35 import javax.management.MBeanParameterInfo ; 36 import javax.management.MBeanRegistrationException ; 37 import javax.management.MBeanServer ; 38 import javax.management.MBeanServerFactory ; 39 import javax.management.MalformedObjectNameException ; 40 import javax.management.NotCompliantMBeanException ; 41 import javax.management.ObjectInstance ; 42 import javax.management.ObjectName ; 43 import javax.management.ReflectionException ; 44 45 48 49 public class TrivialTestCase 50 extends TestCase 51 { 52 public TrivialTestCase(String s) 53 { 54 super(s); 55 } 56 57 public void testRegistration() 58 { 59 MBeanServer server = MBeanServerFactory.newMBeanServer(); 60 Trivial trivial = new Trivial(); 61 62 ObjectName name = null; 63 try 64 { 65 name = new ObjectName ("trivial:key=val"); 66 ObjectInstance instance = server.registerMBean(trivial, name); 67 } 68 catch (Exception e) 69 { 70 fail("registration failed: " + e.getMessage()); 71 } 72 assertTrue("expected server to report it as registered", server.isRegistered(name)); 73 } 74 75 public void testConstructorInfo() 76 { 77 MBeanInfo info = getTrivialInfo(); 78 79 MBeanConstructorInfo [] constructors = info.getConstructors(); 80 assertEquals("constructor list length", 1, constructors.length); 81 82 assertEquals("constructor name", Trivial.class.getName(), constructors[0].getName()); 85 86 MBeanParameterInfo [] params = constructors[0].getSignature(); 87 assertEquals("constructor signature length", 0, params.length); 88 } 89 90 public void testAttributeInfo() 91 { 92 MBeanInfo info = getTrivialInfo(); 93 94 MBeanAttributeInfo [] attributes = info.getAttributes(); 95 assertEquals("attribute list length", 1, attributes.length); 96 assertEquals("attribute name", "Something", attributes[0].getName()); 97 assertEquals("attribute type", String .class.getName(), attributes[0].getType()); 98 assertEquals("attribute readable", true, attributes[0].isReadable()); 99 assertEquals("attribute writable", true, attributes[0].isWritable()); 100 assertEquals("attribute isIs", false, attributes[0].isIs()); 101 } 102 103 public void testOperationInfo() 104 { 105 MBeanInfo info = getTrivialInfo(); 106 107 MBeanOperationInfo [] operations = info.getOperations(); 108 assertEquals("operations list length", 1, operations.length); 109 assertEquals("operation name", "doOperation", operations[0].getName()); 110 assertEquals("operation return type", Void.TYPE.getName(), operations[0].getReturnType()); 111 assertEquals("operation impact", MBeanOperationInfo.UNKNOWN, operations[0].getImpact()); 112 113 MBeanParameterInfo [] params = operations[0].getSignature(); 114 assertEquals("signature length", 1, params.length); 115 assertEquals("parameter type", String .class.getName(), params[0].getType()); 116 } 117 118 public void testNotificationInfo() 119 { 120 MBeanInfo info = getTrivialInfo(); 121 122 MBeanNotificationInfo [] notifications = info.getNotifications(); 123 assertEquals("notification list length", 0, notifications.length); 124 } 125 126 127 private MBeanInfo getTrivialInfo() 128 { 129 MBeanInfo info = null; 130 131 try 132 { 133 MBeanServer server = MBeanServerFactory.newMBeanServer(); 134 Trivial trivial = new Trivial(); 135 136 ObjectName name = new ObjectName ("trivial:key=val"); 137 ObjectInstance instance = server.registerMBean(trivial, name); 138 info = server.getMBeanInfo(name); 139 } 140 catch (MalformedObjectNameException e) 141 { 142 fail("got spurious MalformedObjectNameException"); 143 } 144 catch (InstanceAlreadyExistsException e) 145 { 146 fail("got spurious InstanceAlreadyExistsException"); 147 } 148 catch (MBeanRegistrationException e) 149 { 150 fail("got spurious MBeanRegistrationException"); 151 } 152 catch (NotCompliantMBeanException e) 153 { 154 fail("got spurious NotCompliantMBeanException"); 155 } 156 catch (InstanceNotFoundException e) 157 { 158 fail("got spurious InstanceNotFoundException"); 159 } 160 catch (IntrospectionException e) 161 { 162 fail("got spurious IntrospectionException"); 163 } 164 catch (ReflectionException e) 165 { 166 fail("got spurious ReflectionException"); 167 } 168 169 return info; 170 } 171 } 172 | Popular Tags |