1 7 8 package test.compliance.standard; 9 10 import junit.framework.Test; 11 import junit.framework.TestCase; 12 import junit.framework.TestSuite; 13 import test.compliance.standard.support.Torture; 14 15 import javax.management.MBeanInfo; 16 import javax.management.MBeanOperationInfo; 17 18 23 public class InfoTortureSUITE extends TestSuite 24 { 25 private static int attributeTestCount = 0; 26 private static int operationTestCount = 0; 27 private static int constructorTestCount = 0; 28 29 public static void main(String[] args) 30 { 31 junit.textui.TestRunner.run(suite()); 32 } 33 34 public static Test suite() 35 { 36 TestSuite testSuite = new TestSuite("All MBeanInfo Torture Tests for Standard MBeans"); 37 38 Object mbean = new Torture(); 39 MBeanInfo info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo"); 40 41 addConstructorTest(testSuite, info, Torture.class.getName(), new String[0]); 43 addConstructorTest(testSuite, info, Torture.class.getName(), new String[] { String[][].class.getName() }); 44 45 testSuite.addTest(new TestCoverageTEST("Torture constructor list length", constructorTestCount, info.getConstructors().length)); 48 49 addSpuriousAttributeTest(testSuite, info, "peachy"); 51 addSpuriousAttributeTest(testSuite, info, "Peachy"); 52 addSpuriousAttributeTest(testSuite, info, "suer"); 53 addSpuriousAttributeTest(testSuite, info, "settlement"); 54 addSpuriousAttributeTest(testSuite, info, "Result"); 55 addSpuriousAttributeTest(testSuite, info, "Multi"); 56 57 addAttributeTest(testSuite, info, "NiceString", String.class.getName(), true, true, false); 60 addAttributeTest(testSuite, info, "NiceBoolean", boolean.class.getName(), true, true, true); 61 addAttributeTest(testSuite, info, "Something", String.class.getName(), false, true, false); 62 addAttributeTest(testSuite, info, "Int", int.class.getName(), false, true, false); 63 addAttributeTest(testSuite, info, "IntArray", int[].class.getName(), false, true, false); 64 addAttributeTest(testSuite, info, "NestedIntArray", int[][][].class.getName(), false, true, false); 65 addAttributeTest(testSuite, info, "Integer", Integer.class.getName(), false, true, false); 66 addAttributeTest(testSuite, info, "IntegerArray", Integer[].class.getName(), false, true, false); 67 addAttributeTest(testSuite, info, "NestedIntegerArray", Integer[][][].class.getName(), false, true, false); 68 addAttributeTest(testSuite, info, "Myinteger", int.class.getName(), true, false, false); 69 addAttributeTest(testSuite, info, "MyintegerArray", int[].class.getName(), true, false, false); 70 addAttributeTest(testSuite, info, "MyNestedintegerArray", int[][][].class.getName(), true, false, false); 71 addAttributeTest(testSuite, info, "MyInteger", Integer.class.getName(), true, false, false); 72 addAttributeTest(testSuite, info, "MyIntegerArray", Integer[].class.getName(), true, false, false); 73 addAttributeTest(testSuite, info, "MyNestedIntegerArray", Integer[][][].class.getName(), true, false, false); 74 addAttributeTest(testSuite, info, "ready", boolean.class.getName(), true, false, true); 75 addAttributeTest(testSuite, info, "Ready", Boolean.class.getName(), true, false, true); 76 77 testSuite.addTest(new TestCoverageTEST("Torture attribute list length", attributeTestCount, info.getAttributes().length)); 80 81 addOperationTest(testSuite, info, "settlement", MBeanOperationInfo.UNKNOWN, int.class.getName(), new String[] { String.class.getName() }); 84 addOperationTest(testSuite, info, "getSomething", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String[0]); 85 addOperationTest(testSuite, info, "ispeachy", MBeanOperationInfo.UNKNOWN, boolean.class.getName(), new String[] { int.class.getName() }); 86 addOperationTest(testSuite, info, "isPeachy", MBeanOperationInfo.UNKNOWN, Boolean.class.getName(), new String[] { int.class.getName() }); 87 addOperationTest(testSuite, info, "setMulti", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String[] { String.class.getName(), Integer.class.getName() }); 88 addOperationTest(testSuite, info, "getResult", MBeanOperationInfo.UNKNOWN, String.class.getName(), new String[] { String.class.getName() }); 89 addOperationTest(testSuite, info, "setNothing", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String[0]); 90 addOperationTest(testSuite, info, "getNothing", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String[0]); 91 addOperationTest(testSuite, info, "doSomethingCrazy", MBeanOperationInfo.UNKNOWN, String[][].class.getName(), new String[] { Object[].class.getName(), String[].class.getName(), int[][][].class.getName() }); 92 addOperationTest(testSuite, info, "issuer", MBeanOperationInfo.UNKNOWN, String.class.getName(), new String[0]); 96 97 testSuite.addTest(new TestCoverageTEST("Torture operation list length", operationTestCount, info.getOperations().length)); 100 101 return testSuite; 102 } 103 104 public static void addConstructorTest(TestSuite testSuite, MBeanInfo info, String name, String[] signature) 105 { 106 testSuite.addTest(new ConstructorInfoTEST("InfoTortureSUITE constructor", info, name, signature)); 107 constructorTestCount++; 108 } 109 110 public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo info, String name) 111 { 112 testSuite.addTest(new SpuriousAttributeTEST("InfoTortureSUITE spuriousAttribute", info, name)); 113 } 114 115 public static void addAttributeTest(TestSuite testSuite, MBeanInfo info, String name, String type, boolean read, boolean write, boolean is) 116 { 117 testSuite.addTest(new AttributeInfoTEST("InfoTortureSUITE attribute", info, name, type, read, write, is)); 118 attributeTestCount++; 119 } 120 121 public static void addOperationTest(TestSuite testSuite, MBeanInfo info, String name, int impact, String returnType, String[] signature) 122 { 123 testSuite.addTest(new OperationInfoTEST("InfoTortureSUITE operation", info, name, impact, returnType, signature)); 124 operationTestCount++; 125 } 126 127 public static class TestCoverageTEST extends TestCase 128 { 129 private String msg; 130 private int expected; 131 private int got; 132 133 public TestCoverageTEST(String msg, int expected, int got) 134 { 135 super("testAdequateCoverage"); 136 this.msg = msg; 137 this.expected = expected; 138 this.got = got; 139 } 140 141 public void testAdequateCoverage() 142 { 143 assertEquals(msg, expected, got); 144 } 145 } 146 147 } 148 | Popular Tags |