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 org.jboss.test.jbossmx.compliance.standard;
023:
024: import junit.framework.Test;
025: import junit.framework.TestSuite;
026:
027: import org.jboss.test.jbossmx.compliance.TestCase;
028:
029: import org.jboss.test.jbossmx.compliance.standard.support.StandardDerived1;
030: import org.jboss.test.jbossmx.compliance.standard.support.StandardDerived2;
031: import org.jboss.test.jbossmx.compliance.standard.support.DynamicDerived1;
032: import org.jboss.test.jbossmx.compliance.standard.support.StandardDerived3;
033:
034: import javax.management.MBeanInfo;
035: import javax.management.MBeanOperationInfo;
036:
037: /**
038: * Beat the heck out of the server's standard MBeanInfo inheritance handling
039: *
040: * @author <a href="mailto:trevor@protocool.com">Trevor Squires</a>.
041: */
042: public class InheritanceTestCase extends TestCase {
043: private static int attributeTestCount = 0;
044: private static int operationTestCount = 0;
045: private static int constructorTestCount = 0;
046:
047: public InheritanceTestCase(String s) {
048: super (s);
049: }
050:
051: public static Test suite() {
052: TestSuite testSuite = new TestSuite(
053: "All MBeanInfo Torture Tests for Standard MBeans");
054:
055: Object mbean = new StandardDerived1();
056: MBeanInfo info = InfoUtil.getMBeanInfo(mbean,
057: "test:type=mbeaninfo");
058:
059: addConstructorTest(testSuite, info, StandardDerived1.class
060: .getName(), new String[0]);
061: testSuite.addTest(new TestCoverageTEST(
062: "StandardDerived1 constructor list length",
063: constructorTestCount, info.getConstructors().length));
064: addAttributeTest(testSuite, info, "ParentValue", String.class
065: .getName(), false, true, false);
066: addAttributeTest(testSuite, info, "Available", boolean.class
067: .getName(), false, true, false);
068: testSuite.addTest(new TestCoverageTEST(
069: "StandardDerived1 attribute list length",
070: attributeTestCount, info.getAttributes().length));
071: testSuite.addTest(new TestCoverageTEST(
072: "StandardDerived1 operation list length",
073: operationTestCount, info.getOperations().length));
074:
075: resetCounters();
076:
077: mbean = new StandardDerived2();
078: info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
079:
080: addConstructorTest(testSuite, info, StandardDerived2.class
081: .getName(), new String[0]);
082: testSuite.addTest(new TestCoverageTEST(
083: "StandardDerived2 constructor list length",
084: constructorTestCount, info.getConstructors().length));
085: addAttributeTest(testSuite, info, "DerivedValue", String.class
086: .getName(), false, true, false);
087: addAttributeTest(testSuite, info, "ParentValue", String.class
088: .getName(), true, false, false);
089: addSpuriousAttributeTest(testSuite, info, "Available");
090: testSuite.addTest(new TestCoverageTEST(
091: "StandardDerived2 attribute list length",
092: attributeTestCount, info.getAttributes().length));
093: testSuite.addTest(new TestCoverageTEST(
094: "StandardDerived2 operation list length",
095: operationTestCount, info.getOperations().length));
096:
097: resetCounters();
098:
099: mbean = new StandardDerived3();
100: info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
101:
102: addConstructorTest(testSuite, info, StandardDerived3.class
103: .getName(), new String[0]);
104: testSuite.addTest(new TestCoverageTEST(
105: "StandardDerived3 constructor list length",
106: constructorTestCount, info.getConstructors().length));
107: addAttributeTest(testSuite, info, "ArbitraryValue",
108: String.class.getName(), false, true, false);
109: testSuite.addTest(new TestCoverageTEST(
110: "StandardDerived3 attribute list length",
111: attributeTestCount, info.getAttributes().length));
112: testSuite.addTest(new TestCoverageTEST(
113: "StandardDerived3 operation list length",
114: operationTestCount, info.getOperations().length));
115:
116: resetCounters();
117:
118: mbean = new DynamicDerived1();
119: info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
120:
121: testSuite.addTest(new TestCoverageTEST(
122: "DynamicDerived1 constructor list length",
123: constructorTestCount, info.getConstructors().length));
124: testSuite.addTest(new TestCoverageTEST(
125: "DynamicDerived1 attribute list length",
126: attributeTestCount, info.getAttributes().length));
127: testSuite.addTest(new TestCoverageTEST(
128: "DynamicDerived1 operation list length",
129: operationTestCount, info.getOperations().length));
130:
131: return testSuite;
132: }
133:
134: public static void resetCounters() {
135: constructorTestCount = 0;
136: attributeTestCount = 0;
137: operationTestCount = 0;
138: }
139:
140: public static void addConstructorTest(TestSuite testSuite,
141: MBeanInfo info, String name, String[] signature) {
142: testSuite.addTest(new ConstructorInfoTEST(
143: "InheritanceSUITE constructor", info, name, signature));
144: constructorTestCount++;
145: }
146:
147: public static void addSpuriousAttributeTest(TestSuite testSuite,
148: MBeanInfo info, String name) {
149: testSuite.addTest(new SpuriousAttributeTEST(
150: "InheritanceSUITE spuriousAttribute", info, name));
151: }
152:
153: public static void addAttributeTest(TestSuite testSuite,
154: MBeanInfo info, String name, String type, boolean read,
155: boolean write, boolean is) {
156: testSuite.addTest(new AttributeInfoTEST(
157: "InheritanceSUITE attribute", info, name, type, read,
158: write, is));
159: attributeTestCount++;
160: }
161:
162: public static void addOperationTest(TestSuite testSuite,
163: MBeanInfo info, String name, int impact, String returnType,
164: String[] signature) {
165: testSuite.addTest(new OperationInfoTEST(
166: "InheritanceSUITE operation", info, name, impact,
167: returnType, signature));
168: operationTestCount++;
169: }
170:
171: public static class TestCoverageTEST extends TestCase {
172: private String msg;
173: private int expected;
174: private int got;
175:
176: public TestCoverageTEST(String msg, int expected, int got) {
177: super ("testAdequateCoverage");
178: this .msg = msg;
179: this .expected = expected;
180: this .got = got;
181: }
182:
183: public void testAdequateCoverage() {
184: assertEquals(msg, expected, got);
185: }
186: }
187:
188: }
|