KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > standard > InheritanceSUITE


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.standard;
9
10 import javax.management.MBeanInfo;
11
12 import junit.framework.Test;
13 import junit.framework.TestCase;
14 import junit.framework.TestSuite;
15 import test.compliance.standard.support.DynamicDerived1;
16 import test.compliance.standard.support.StandardDerived1;
17 import test.compliance.standard.support.StandardDerived2;
18 import test.compliance.standard.support.StandardDerived3;
19
20 /**
21  * Beat the heck out of the server's standard MBeanInfo inheritance handling
22  *
23  * @author <a HREF="mailto:trevor@protocool.com">Trevor Squires</a>.
24  */

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