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