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