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