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 junit.framework.Test;
025: import junit.framework.TestCase;
026: import junit.framework.TestSuite;
027: import test.compliance.standard.support.Torture;
028:
029: import javax.management.MBeanInfo;
030: import javax.management.MBeanOperationInfo;
031:
032: /**
033: * Beat the heck out of the server's standard MBeanInfo
034: *
035: * @author <a href="mailto:trevor@protocool.com">Trevor Squires</a>.
036: */
037: public class InfoTortureSUITE extends TestSuite {
038: private static int attributeTestCount = 0;
039: private static int operationTestCount = 0;
040: private static int constructorTestCount = 0;
041:
042: public static void main(String[] args) {
043: junit.textui.TestRunner.run(suite());
044: }
045:
046: public static Test suite() {
047: TestSuite testSuite = new TestSuite(
048: "All MBeanInfo Torture Tests for Standard MBeans");
049:
050: Object mbean = new Torture();
051: MBeanInfo info = InfoUtil.getMBeanInfo(mbean,
052: "test:type=mbeaninfo");
053:
054: // Tests for valid constructors
055: addConstructorTest(testSuite, info, Torture.class.getName(),
056: new String[0]);
057: addConstructorTest(testSuite, info, Torture.class.getName(),
058: new String[] { String[][].class.getName() });
059:
060: // make sure we are testing all exposed constructors (each ValidConstructorTest increments a counter
061: // which is used to figure out whether we have adequate test coverage)
062: testSuite.addTest(new TestCoverageTEST(
063: "Torture constructor list length",
064: constructorTestCount, info.getConstructors().length));
065:
066: // Tests for attributes that should not be there
067: addSpuriousAttributeTest(testSuite, info, "peachy");
068: addSpuriousAttributeTest(testSuite, info, "Peachy");
069: addSpuriousAttributeTest(testSuite, info, "suer");
070: addSpuriousAttributeTest(testSuite, info, "settlement");
071: addSpuriousAttributeTest(testSuite, info, "Result");
072: addSpuriousAttributeTest(testSuite, info, "Multi");
073:
074: // make sure remaining attributes are correct
075: // Args are: Name, Type, Readable, Writable, IsIS
076: addAttributeTest(testSuite, info, "NiceString", String.class
077: .getName(), true, true, false);
078: addAttributeTest(testSuite, info, "NiceBoolean", boolean.class
079: .getName(), true, true, true);
080: addAttributeTest(testSuite, info, "Something", String.class
081: .getName(), false, true, false);
082: addAttributeTest(testSuite, info, "Int", int.class.getName(),
083: false, true, false);
084: addAttributeTest(testSuite, info, "IntArray", int[].class
085: .getName(), false, true, false);
086: addAttributeTest(testSuite, info, "NestedIntArray",
087: int[][][].class.getName(), false, true, false);
088: addAttributeTest(testSuite, info, "Integer", Integer.class
089: .getName(), false, true, false);
090: addAttributeTest(testSuite, info, "IntegerArray",
091: Integer[].class.getName(), false, true, false);
092: addAttributeTest(testSuite, info, "NestedIntegerArray",
093: Integer[][][].class.getName(), false, true, false);
094: addAttributeTest(testSuite, info, "Myinteger", int.class
095: .getName(), true, false, false);
096: addAttributeTest(testSuite, info, "MyintegerArray", int[].class
097: .getName(), true, false, false);
098: addAttributeTest(testSuite, info, "MyNestedintegerArray",
099: int[][][].class.getName(), true, false, false);
100: addAttributeTest(testSuite, info, "MyInteger", Integer.class
101: .getName(), true, false, false);
102: addAttributeTest(testSuite, info, "MyIntegerArray",
103: Integer[].class.getName(), true, false, false);
104: addAttributeTest(testSuite, info, "MyNestedIntegerArray",
105: Integer[][][].class.getName(), true, false, false);
106: addAttributeTest(testSuite, info, "ready", boolean.class
107: .getName(), true, false, true);
108: addAttributeTest(testSuite, info, "Ready", Boolean.class
109: .getName(), true, false, true);
110:
111: // make sure we are testing all exposed attributes (each ValidAttributeTest increments a counter
112: // which is used to figure out whether we have adequate test coverage)
113: testSuite.addTest(new TestCoverageTEST(
114: "Torture attribute list length", attributeTestCount,
115: info.getAttributes().length));
116:
117: // validate the operations
118: // Args are: Name, impact, returnTypeString, SignatureAsStringArray
119: addOperationTest(testSuite, info, "settlement",
120: MBeanOperationInfo.UNKNOWN, int.class.getName(),
121: new String[] { String.class.getName() });
122: addOperationTest(testSuite, info, "getSomething",
123: MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(),
124: new String[0]);
125: addOperationTest(testSuite, info, "ispeachy",
126: MBeanOperationInfo.UNKNOWN, boolean.class.getName(),
127: new String[] { int.class.getName() });
128: addOperationTest(testSuite, info, "isPeachy",
129: MBeanOperationInfo.UNKNOWN, Boolean.class.getName(),
130: new String[] { int.class.getName() });
131: addOperationTest(testSuite, info, "setMulti",
132: MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(),
133: new String[] { String.class.getName(),
134: Integer.class.getName() });
135: addOperationTest(testSuite, info, "getResult",
136: MBeanOperationInfo.UNKNOWN, String.class.getName(),
137: new String[] { String.class.getName() });
138: addOperationTest(testSuite, info, "setNothing",
139: MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(),
140: new String[0]);
141: addOperationTest(testSuite, info, "getNothing",
142: MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(),
143: new String[0]);
144: addOperationTest(testSuite, info, "doSomethingCrazy",
145: MBeanOperationInfo.UNKNOWN, String[][].class.getName(),
146: new String[] { Object[].class.getName(),
147: String[].class.getName(),
148: int[][][].class.getName() });
149: // Hmmm... This fails in the RI (which causes the operation coverage test to fail too.
150: // it's odd because in the RI issuer() isn't treated as an attribute and it doesn't
151: // appear as an operation - it just disappears!
152: addOperationTest(testSuite, info, "issuer",
153: MBeanOperationInfo.UNKNOWN, String.class.getName(),
154: new String[0]);
155:
156: // make sure we are testing all exposed operations (each ValidOperationTest increments a counter
157: // which is used to figure out whether we have adequate test coverage)
158: testSuite.addTest(new TestCoverageTEST(
159: "Torture operation list length", operationTestCount,
160: info.getOperations().length));
161:
162: return testSuite;
163: }
164:
165: public static void addConstructorTest(TestSuite testSuite,
166: MBeanInfo info, String name, String[] signature) {
167: testSuite.addTest(new ConstructorInfoTEST(
168: "InfoTortureSUITE constructor", info, name, signature));
169: constructorTestCount++;
170: }
171:
172: public static void addSpuriousAttributeTest(TestSuite testSuite,
173: MBeanInfo info, String name) {
174: testSuite.addTest(new SpuriousAttributeTEST(
175: "InfoTortureSUITE spuriousAttribute", info, name));
176: }
177:
178: public static void addAttributeTest(TestSuite testSuite,
179: MBeanInfo info, String name, String type, boolean read,
180: boolean write, boolean is) {
181: testSuite.addTest(new AttributeInfoTEST(
182: "InfoTortureSUITE attribute", info, name, type, read,
183: write, is));
184: attributeTestCount++;
185: }
186:
187: public static void addOperationTest(TestSuite testSuite,
188: MBeanInfo info, String name, int impact, String returnType,
189: String[] signature) {
190: testSuite.addTest(new OperationInfoTEST(
191: "InfoTortureSUITE operation", info, name, impact,
192: returnType, signature));
193: operationTestCount++;
194: }
195:
196: public static class TestCoverageTEST extends TestCase {
197: private String msg;
198: private int expected;
199: private int got;
200:
201: public TestCoverageTEST(String msg, int expected, int got) {
202: super ("testAdequateCoverage");
203: this .msg = msg;
204: this .expected = expected;
205: this .got = got;
206: }
207:
208: public void testAdequateCoverage() {
209: assertEquals(msg, expected, got);
210: }
211: }
212:
213: }
|