KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > compliance > standard > InheritanceSUITE


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jmx.compliance.standard;
23
24 import javax.management.MBeanInfo JavaDoc;
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 /**
36  * Beat the heck out of the server's standard MBeanInfo inheritance handling
37  *
38  * @author <a HREF="mailto:trevor@protocool.com">Trevor Squires</a>.
39  */

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 JavaDoc[] 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 JavaDoc mbean = new StandardDerived1();
56       MBeanInfo JavaDoc info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
57
58       addConstructorTest(testSuite, info, StandardDerived1.class.getName(), new String JavaDoc[0]);
59       testSuite.addTest(new TestCoverageTEST("StandardDerived1 constructor list length", constructorTestCount, info.getConstructors().length));
60       addAttributeTest(testSuite, info, "ParentValue", String JavaDoc.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 JavaDoc[0]);
71       testSuite.addTest(new TestCoverageTEST("StandardDerived2 constructor list length", constructorTestCount, info.getConstructors().length));
72       addAttributeTest(testSuite, info, "DerivedValue", String JavaDoc.class.getName(), false, true, false);
73       addAttributeTest(testSuite, info, "ParentValue", String JavaDoc.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 JavaDoc[0]);
84       testSuite.addTest(new TestCoverageTEST("StandardDerived3 constructor list length", constructorTestCount, info.getConstructors().length));
85       addAttributeTest(testSuite, info, "ArbitraryValue", String JavaDoc.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 JavaDoc info, String JavaDoc name, String JavaDoc[] signature)
109    {
110       testSuite.addTest(new ConstructorInfoTEST("InheritanceSUITE constructor", info, name, signature));
111       constructorTestCount++;
112    }
113
114    public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name)
115    {
116       testSuite.addTest(new SpuriousAttributeTEST("InheritanceSUITE spuriousAttribute", info, name));
117    }
118
119    public static void addAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, String JavaDoc 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 JavaDoc info, String JavaDoc name, int impact, String JavaDoc returnType, String JavaDoc[] 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 JavaDoc msg;
134       private int expected;
135       private int got;
136
137       public TestCoverageTEST(String JavaDoc 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