KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmx > compliance > standard > InheritanceTestCase


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.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 JavaDoc;
35 import javax.management.MBeanOperationInfo JavaDoc;
36
37 /**
38  * Beat the heck out of the server's standard MBeanInfo inheritance handling
39  *
40  * @author <a HREF="mailto:trevor@protocool.com">Trevor Squires</a>.
41  */

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 JavaDoc 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 JavaDoc mbean = new StandardDerived1();
59       MBeanInfo JavaDoc info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
60
61       addConstructorTest(testSuite, info, StandardDerived1.class.getName(), new String JavaDoc[0]);
62       testSuite.addTest(new TestCoverageTEST("StandardDerived1 constructor list length", constructorTestCount, info.getConstructors().length));
63       addAttributeTest(testSuite, info, "ParentValue", String JavaDoc.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 JavaDoc[0]);
74       testSuite.addTest(new TestCoverageTEST("StandardDerived2 constructor list length", constructorTestCount, info.getConstructors().length));
75       addAttributeTest(testSuite, info, "DerivedValue", String JavaDoc.class.getName(), false, true, false);
76       addAttributeTest(testSuite, info, "ParentValue", String JavaDoc.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 JavaDoc[0]);
87       testSuite.addTest(new TestCoverageTEST("StandardDerived3 constructor list length", constructorTestCount, info.getConstructors().length));
88       addAttributeTest(testSuite, info, "ArbitraryValue", String JavaDoc.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 JavaDoc info, String JavaDoc name, String JavaDoc[] signature)
112    {
113       testSuite.addTest(new ConstructorInfoTEST("InheritanceSUITE constructor", info, name, signature));
114       constructorTestCount++;
115    }
116
117    public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name)
118    {
119       testSuite.addTest(new SpuriousAttributeTEST("InheritanceSUITE spuriousAttribute", info, name));
120    }
121
122    public static void addAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, String JavaDoc 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 JavaDoc info, String JavaDoc name, int impact, String JavaDoc returnType, String JavaDoc[] 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 JavaDoc msg;
137       private int expected;
138       private int got;
139
140       public TestCoverageTEST(String JavaDoc 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