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