1 22 package org.jboss.test.jmx.compliance.notcompliant; 23 24 import javax.management.MBeanInfo ; 25 import javax.management.MBeanServer ; 26 import javax.management.MBeanServerFactory ; 27 import javax.management.NotCompliantMBeanException ; 28 import javax.management.ObjectName ; 29 30 import org.jboss.test.jmx.compliance.notcompliant.support.DynamicAndStandard; 31 import org.jboss.test.jmx.compliance.notcompliant.support.InterfaceProblems; 32 import org.jboss.test.jmx.compliance.notcompliant.support.NullDynamic; 33 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute1; 34 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute2; 35 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute3; 36 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute4; 37 import org.jboss.test.jmx.compliance.notcompliant.support.OverloadedAttribute5; 38 39 import junit.framework.TestCase; 40 41 public class NCMBeanTEST extends TestCase 42 { 43 public NCMBeanTEST(String s) 44 { 45 super(s); 46 } 47 48 public void testOverloadedAttribute1() 49 { 50 registerAndTest(new OverloadedAttribute1()); 51 } 52 53 public void testOverloadedAttribute2() 54 { 55 registerAndTest(new OverloadedAttribute2()); 56 } 57 58 public void testOverloadedAttribute3() 59 { 60 registerAndTest(new OverloadedAttribute3()); 61 } 62 63 public void testOverloadedAttribute4() 64 { 65 registerAndTest(new OverloadedAttribute4()); 66 } 67 68 public void testOverloadedAttribute5() 69 { 70 registerAndTest(new OverloadedAttribute5()); 71 } 72 73 public void testMixedDynamicStandard() 74 { 75 MBeanServer server = MBeanServerFactory.createMBeanServer(); 76 try 77 { 78 server.registerMBean(new DynamicAndStandard(), new ObjectName ("test:foo=bar")); 79 MBeanInfo info = server.getMBeanInfo(new ObjectName ("test:foo=bar")); 80 assertTrue("A mixed dynamic and standard mbean should be dynamic", 81 info.getDescription().equals(DynamicAndStandard.DESCRIPTION)); 82 } 83 catch (NotCompliantMBeanException e) 84 { 85 fail("A mixed dynamic and standardmbean is allowed from jmx 1.1"); 86 } 87 catch (Exception e) 88 { 89 fail("unexpected exception when registering " + DynamicAndStandard.class.getName() + ": " + e.getMessage()); 90 } 91 finally 92 { 93 MBeanServerFactory.releaseMBeanServer(server); 94 } 95 } 96 97 public void testNoConstructor() 98 { 99 try 100 { 101 registerAndDontTest(NoConstructor.getInstance()); 102 } 103 catch (NotCompliantMBeanException e) 104 { 105 fail("An MBean without a public constructor is allowed from jmx 1.1"); 106 } 107 } 108 109 public void testInterfaceProblems() 110 { 111 try 112 { 113 registerAndDontTest(new InterfaceProblems()); 114 } 115 catch (NotCompliantMBeanException e) 116 { 117 fail("FAILS IN RI: Cannot cope with overriden get/is in interfaces"); 118 } 119 } 120 121 public void testNullDynamic() 122 throws Exception 123 { 124 MBeanServer server = MBeanServerFactory.newMBeanServer(); 125 ObjectName name = new ObjectName ("test:test=test"); 126 boolean caught = false; 127 try 128 { 129 server.registerMBean(new NullDynamic(), name); 130 } 131 catch (NotCompliantMBeanException e) 132 { 133 caught = true; 134 } 135 assertTrue("Expected NCME for null MBeanInfo", caught); 136 } 137 138 private void registerAndTest(Object mbean) 139 { 140 MBeanServer server = MBeanServerFactory.createMBeanServer(); 141 try 142 { 143 server.registerMBean(mbean, new ObjectName ("test:foo=bar")); 144 fail("expected a NotCompliantMBeanException for " + mbean.getClass().getName()); 145 } 146 catch (NotCompliantMBeanException e) 147 { 148 } 150 catch (Exception e) 151 { 152 fail("unexpected exception when registering " + mbean.getClass().getName() + ": " + e); 153 } 154 finally 155 { 156 MBeanServerFactory.releaseMBeanServer(server); 157 } 158 } 159 160 private void registerAndDontTest(Object mbean) 161 throws NotCompliantMBeanException 162 { 163 MBeanServer server = MBeanServerFactory.createMBeanServer(); 164 try 165 { 166 server.registerMBean(mbean, new ObjectName ("test:foo=bar")); 167 } 168 catch (NotCompliantMBeanException e) 169 { 170 throw e; 171 } 172 catch (Exception e) 173 { 174 fail("unexpected exception when registering " + mbean.getClass().getName() + ": " + e.getMessage()); 175 } 176 finally 177 { 178 MBeanServerFactory.releaseMBeanServer(server); 179 } 180 } 181 } 182 | Popular Tags |