1 22 package org.jboss.test.jmx.compliance.standard; 23 24 import javax.management.MBeanInfo ; 25 26 import junit.framework.Test; 27 import junit.framework.TestCase; 28 import junit.framework.TestSuite; 29 30 import org.jboss.test.jmx.compliance.standard.support.DynamicDerived1; 31 import org.jboss.test.jmx.compliance.standard.support.StandardDerived1; 32 import org.jboss.test.jmx.compliance.standard.support.StandardDerived2; 33 import org.jboss.test.jmx.compliance.standard.support.StandardDerived3; 34 35 40 public class InheritanceSUITE extends TestSuite 41 { 42 private static int attributeTestCount = 0; 43 private static int operationTestCount = 0; 44 private static int constructorTestCount = 0; 45 46 public static void main(String [] args) 47 { 48 junit.textui.TestRunner.run(suite()); 49 } 50 51 public static Test suite() 52 { 53 TestSuite testSuite = new TestSuite("All MBeanInfo Torture Tests for Standard MBeans"); 54 55 Object mbean = new StandardDerived1(); 56 MBeanInfo info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo"); 57 58 addConstructorTest(testSuite, info, StandardDerived1.class.getName(), new String [0]); 59 testSuite.addTest(new TestCoverageTEST("StandardDerived1 constructor list length", constructorTestCount, info.getConstructors().length)); 60 addAttributeTest(testSuite, info, "ParentValue", String .class.getName(), false, true, false); 61 addAttributeTest(testSuite, info, "Available", boolean.class.getName(), false, true, false); 62 testSuite.addTest(new TestCoverageTEST("StandardDerived1 attribute list length", attributeTestCount, info.getAttributes().length)); 63 testSuite.addTest(new TestCoverageTEST("StandardDerived1 operation list length", operationTestCount, info.getOperations().length)); 64 65 resetCounters(); 66 67 mbean = new StandardDerived2(); 68 info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo"); 69 70 addConstructorTest(testSuite, info, StandardDerived2.class.getName(), new String [0]); 71 testSuite.addTest(new TestCoverageTEST("StandardDerived2 constructor list length", constructorTestCount, info.getConstructors().length)); 72 addAttributeTest(testSuite, info, "DerivedValue", String .class.getName(), false, true, false); 73 addAttributeTest(testSuite, info, "ParentValue", String .class.getName(), true, false, false); 74 addSpuriousAttributeTest(testSuite, info, "Available"); 75 testSuite.addTest(new TestCoverageTEST("StandardDerived2 attribute list length", attributeTestCount, info.getAttributes().length)); 76 testSuite.addTest(new TestCoverageTEST("StandardDerived2 operation list length", operationTestCount, info.getOperations().length)); 77 78 resetCounters(); 79 80 mbean = new StandardDerived3(); 81 info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo"); 82 83 addConstructorTest(testSuite, info, StandardDerived3.class.getName(), new String [0]); 84 testSuite.addTest(new TestCoverageTEST("StandardDerived3 constructor list length", constructorTestCount, info.getConstructors().length)); 85 addAttributeTest(testSuite, info, "ArbitraryValue", String .class.getName(), false, true, false); 86 testSuite.addTest(new TestCoverageTEST("StandardDerived3 attribute list length", attributeTestCount, info.getAttributes().length)); 87 testSuite.addTest(new TestCoverageTEST("StandardDerived3 operation list length", operationTestCount, info.getOperations().length)); 88 89 resetCounters(); 90 91 mbean = new DynamicDerived1(); 92 info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo"); 93 94 testSuite.addTest(new TestCoverageTEST("DynamicDerived1 constructor list length", constructorTestCount, info.getConstructors().length)); 95 testSuite.addTest(new TestCoverageTEST("DynamicDerived1 attribute list length", attributeTestCount, info.getAttributes().length)); 96 testSuite.addTest(new TestCoverageTEST("DynamicDerived1 operation list length", operationTestCount, info.getOperations().length)); 97 98 return testSuite; 99 } 100 101 public static void resetCounters() 102 { 103 constructorTestCount = 0; 104 attributeTestCount = 0; 105 operationTestCount = 0; 106 } 107 108 public static void addConstructorTest(TestSuite testSuite, MBeanInfo info, String name, String [] signature) 109 { 110 testSuite.addTest(new ConstructorInfoTEST("InheritanceSUITE constructor", info, name, signature)); 111 constructorTestCount++; 112 } 113 114 public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo info, String name) 115 { 116 testSuite.addTest(new SpuriousAttributeTEST("InheritanceSUITE spuriousAttribute", info, name)); 117 } 118 119 public static void addAttributeTest(TestSuite testSuite, MBeanInfo info, String name, String type, boolean read, boolean write, boolean is) 120 { 121 testSuite.addTest(new AttributeInfoTEST("InheritanceSUITE attribute", info, name, type, read, write, is)); 122 attributeTestCount++; 123 } 124 125 public static void addOperationTest(TestSuite testSuite, MBeanInfo info, String name, int impact, String returnType, String [] signature) 126 { 127 testSuite.addTest(new OperationInfoTEST("InheritanceSUITE operation", info, name, impact, returnType, signature)); 128 operationTestCount++; 129 } 130 131 public static class TestCoverageTEST extends TestCase 132 { 133 private String msg; 134 private int expected; 135 private int got; 136 137 public TestCoverageTEST(String msg, int expected, int got) 138 { 139 super("testAdequateCoverage"); 140 this.msg = msg; 141 this.expected = expected; 142 this.got = got; 143 } 144 145 public void testAdequateCoverage() 146 { 147 assertEquals(msg, expected, got); 148 } 149 } 150 151 } 152 | Popular Tags |