001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.compliance.standard;
023:
024: import javax.management.MBeanInfo;
025:
026: import junit.framework.Test;
027: import junit.framework.TestCase;
028: import junit.framework.TestSuite;
029: import test.compliance.standard.support.DynamicDerived1;
030: import test.compliance.standard.support.StandardDerived1;
031: import test.compliance.standard.support.StandardDerived2;
032: import test.compliance.standard.support.StandardDerived3;
033:
034: /**
035: * Beat the heck out of the server's standard MBeanInfo inheritance handling
036: *
037: * @author <a href="mailto:trevor@protocool.com">Trevor Squires</a>.
038: */
039: public class InheritanceSUITE extends TestSuite {
040: private static int attributeTestCount = 0;
041: private static int operationTestCount = 0;
042: private static int constructorTestCount = 0;
043:
044: public static void main(String[] args) {
045: junit.textui.TestRunner.run(suite());
046: }
047:
048: public static Test suite() {
049: TestSuite testSuite = new TestSuite(
050: "All MBeanInfo Torture Tests for Standard MBeans");
051:
052: Object mbean = new StandardDerived1();
053: MBeanInfo info = InfoUtil.getMBeanInfo(mbean,
054: "test:type=mbeaninfo");
055:
056: addConstructorTest(testSuite, info, StandardDerived1.class
057: .getName(), new String[0]);
058: testSuite.addTest(new TestCoverageTEST(
059: "StandardDerived1 constructor list length",
060: constructorTestCount, info.getConstructors().length));
061: addAttributeTest(testSuite, info, "ParentValue", String.class
062: .getName(), false, true, false);
063: addAttributeTest(testSuite, info, "Available", boolean.class
064: .getName(), false, true, false);
065: testSuite.addTest(new TestCoverageTEST(
066: "StandardDerived1 attribute list length",
067: attributeTestCount, info.getAttributes().length));
068: testSuite.addTest(new TestCoverageTEST(
069: "StandardDerived1 operation list length",
070: operationTestCount, info.getOperations().length));
071:
072: resetCounters();
073:
074: mbean = new StandardDerived2();
075: info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
076:
077: addConstructorTest(testSuite, info, StandardDerived2.class
078: .getName(), new String[0]);
079: testSuite.addTest(new TestCoverageTEST(
080: "StandardDerived2 constructor list length",
081: constructorTestCount, info.getConstructors().length));
082: addAttributeTest(testSuite, info, "DerivedValue", String.class
083: .getName(), false, true, false);
084: addAttributeTest(testSuite, info, "ParentValue", String.class
085: .getName(), true, false, false);
086: addSpuriousAttributeTest(testSuite, info, "Available");
087: testSuite.addTest(new TestCoverageTEST(
088: "StandardDerived2 attribute list length",
089: attributeTestCount, info.getAttributes().length));
090: testSuite.addTest(new TestCoverageTEST(
091: "StandardDerived2 operation list length",
092: operationTestCount, info.getOperations().length));
093:
094: resetCounters();
095:
096: mbean = new StandardDerived3();
097: info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
098:
099: addConstructorTest(testSuite, info, StandardDerived3.class
100: .getName(), new String[0]);
101: testSuite.addTest(new TestCoverageTEST(
102: "StandardDerived3 constructor list length",
103: constructorTestCount, info.getConstructors().length));
104: addAttributeTest(testSuite, info, "ArbitraryValue",
105: String.class.getName(), false, true, false);
106: testSuite.addTest(new TestCoverageTEST(
107: "StandardDerived3 attribute list length",
108: attributeTestCount, info.getAttributes().length));
109: testSuite.addTest(new TestCoverageTEST(
110: "StandardDerived3 operation list length",
111: operationTestCount, info.getOperations().length));
112:
113: resetCounters();
114:
115: mbean = new DynamicDerived1();
116: info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
117:
118: testSuite.addTest(new TestCoverageTEST(
119: "DynamicDerived1 constructor list length",
120: constructorTestCount, info.getConstructors().length));
121: testSuite.addTest(new TestCoverageTEST(
122: "DynamicDerived1 attribute list length",
123: attributeTestCount, info.getAttributes().length));
124: testSuite.addTest(new TestCoverageTEST(
125: "DynamicDerived1 operation list length",
126: operationTestCount, info.getOperations().length));
127:
128: return testSuite;
129: }
130:
131: public static void resetCounters() {
132: constructorTestCount = 0;
133: attributeTestCount = 0;
134: operationTestCount = 0;
135: }
136:
137: public static void addConstructorTest(TestSuite testSuite,
138: MBeanInfo info, String name, String[] signature) {
139: testSuite.addTest(new ConstructorInfoTEST(
140: "InheritanceSUITE constructor", info, name, signature));
141: constructorTestCount++;
142: }
143:
144: public static void addSpuriousAttributeTest(TestSuite testSuite,
145: MBeanInfo info, String name) {
146: testSuite.addTest(new SpuriousAttributeTEST(
147: "InheritanceSUITE spuriousAttribute", info, name));
148: }
149:
150: public static void addAttributeTest(TestSuite testSuite,
151: MBeanInfo info, String name, String type, boolean read,
152: boolean write, boolean is) {
153: testSuite.addTest(new AttributeInfoTEST(
154: "InheritanceSUITE attribute", info, name, type, read,
155: write, is));
156: attributeTestCount++;
157: }
158:
159: public static void addOperationTest(TestSuite testSuite,
160: MBeanInfo info, String name, int impact, String returnType,
161: String[] signature) {
162: testSuite.addTest(new OperationInfoTEST(
163: "InheritanceSUITE operation", info, name, impact,
164: returnType, signature));
165: operationTestCount++;
166: }
167:
168: public static class TestCoverageTEST extends TestCase {
169: private String msg;
170: private int expected;
171: private int got;
172:
173: public TestCoverageTEST(String msg, int expected, int got) {
174: super ("testAdequateCoverage");
175: this .msg = msg;
176: this .expected = expected;
177: this .got = got;
178: }
179:
180: public void testAdequateCoverage() {
181: assertEquals(msg, expected, got);
182: }
183: }
184:
185: }
|