KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.management.MBeanOperationInfo JavaDoc;
26
27 import junit.framework.Test;
28 import junit.framework.TestCase;
29 import junit.framework.TestSuite;
30
31 import org.jboss.test.jmx.compliance.standard.support.Torture;
32
33 /**
34  * Beat the heck out of the server's standard MBeanInfo
35  *
36  * @author <a HREF="mailto:trevor@protocool.com">Trevor Squires</a>.
37  */

38 public class InfoTortureSUITE extends TestSuite
39 {
40    private static int attributeTestCount = 0;
41    private static int operationTestCount = 0;
42    private static int constructorTestCount = 0;
43
44    public static void main(String JavaDoc[] args)
45    {
46       junit.textui.TestRunner.run(suite());
47    }
48
49    public static Test suite()
50    {
51       TestSuite testSuite = new TestSuite("All MBeanInfo Torture Tests for Standard MBeans");
52
53       Object JavaDoc mbean = new Torture();
54       MBeanInfo JavaDoc info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
55
56       // Tests for valid constructors
57
addConstructorTest(testSuite, info, Torture.class.getName(), new String JavaDoc[0]);
58       addConstructorTest(testSuite, info, Torture.class.getName(), new String JavaDoc[] { String JavaDoc[][].class.getName() });
59
60       // make sure we are testing all exposed constructors (each ValidConstructorTest increments a counter
61
// which is used to figure out whether we have adequate test coverage)
62
testSuite.addTest(new TestCoverageTEST("Torture constructor list length", constructorTestCount, info.getConstructors().length));
63
64       // Tests for attributes that should not be there
65
addSpuriousAttributeTest(testSuite, info, "peachy");
66       addSpuriousAttributeTest(testSuite, info, "Peachy");
67       addSpuriousAttributeTest(testSuite, info, "suer");
68       addSpuriousAttributeTest(testSuite, info, "settlement");
69       addSpuriousAttributeTest(testSuite, info, "Result");
70       addSpuriousAttributeTest(testSuite, info, "Multi");
71
72       // make sure remaining attributes are correct
73
// Args are: Name, Type, Readable, Writable, IsIS
74
addAttributeTest(testSuite, info, "NiceString", String JavaDoc.class.getName(), true, true, false);
75       addAttributeTest(testSuite, info, "NiceBoolean", boolean.class.getName(), true, true, true);
76       addAttributeTest(testSuite, info, "Something", String JavaDoc.class.getName(), false, true, false);
77       addAttributeTest(testSuite, info, "Int", int.class.getName(), false, true, false);
78       addAttributeTest(testSuite, info, "IntArray", int[].class.getName(), false, true, false);
79       addAttributeTest(testSuite, info, "NestedIntArray", int[][][].class.getName(), false, true, false);
80       addAttributeTest(testSuite, info, "Integer", Integer JavaDoc.class.getName(), false, true, false);
81       addAttributeTest(testSuite, info, "IntegerArray", Integer JavaDoc[].class.getName(), false, true, false);
82       addAttributeTest(testSuite, info, "NestedIntegerArray", Integer JavaDoc[][][].class.getName(), false, true, false);
83       addAttributeTest(testSuite, info, "Myinteger", int.class.getName(), true, false, false);
84       addAttributeTest(testSuite, info, "MyintegerArray", int[].class.getName(), true, false, false);
85       addAttributeTest(testSuite, info, "MyNestedintegerArray", int[][][].class.getName(), true, false, false);
86       addAttributeTest(testSuite, info, "MyInteger", Integer JavaDoc.class.getName(), true, false, false);
87       addAttributeTest(testSuite, info, "MyIntegerArray", Integer JavaDoc[].class.getName(), true, false, false);
88       addAttributeTest(testSuite, info, "MyNestedIntegerArray", Integer JavaDoc[][][].class.getName(), true, false, false);
89       addAttributeTest(testSuite, info, "ready", boolean.class.getName(), true, false, true);
90       addAttributeTest(testSuite, info, "Ready", Boolean JavaDoc.class.getName(), true, false, false);
91
92       // make sure we are testing all exposed attributes (each ValidAttributeTest increments a counter
93
// which is used to figure out whether we have adequate test coverage)
94
testSuite.addTest(new TestCoverageTEST("Torture attribute list length", attributeTestCount, info.getAttributes().length));
95
96       // validate the operations
97
// Args are: Name, impact, returnTypeString, SignatureAsStringArray
98
addOperationTest(testSuite, info, "settlement", MBeanOperationInfo.UNKNOWN, int.class.getName(), new String JavaDoc[] { String JavaDoc.class.getName() });
99       addOperationTest(testSuite, info, "getSomething", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[0]);
100       addOperationTest(testSuite, info, "ispeachy", MBeanOperationInfo.UNKNOWN, boolean.class.getName(), new String JavaDoc[] { int.class.getName() });
101       addOperationTest(testSuite, info, "isPeachy", MBeanOperationInfo.UNKNOWN, Boolean JavaDoc.class.getName(), new String JavaDoc[] { int.class.getName() });
102       addOperationTest(testSuite, info, "setMulti", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[] { String JavaDoc.class.getName(), Integer JavaDoc.class.getName() });
103       addOperationTest(testSuite, info, "getResult", MBeanOperationInfo.UNKNOWN, String JavaDoc.class.getName(), new String JavaDoc[] { String JavaDoc.class.getName() });
104       addOperationTest(testSuite, info, "setNothing", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[0]);
105       addOperationTest(testSuite, info, "getNothing", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[0]);
106       addOperationTest(testSuite, info, "doSomethingCrazy", MBeanOperationInfo.UNKNOWN, String JavaDoc[][].class.getName(), new String JavaDoc[] { Object JavaDoc[].class.getName(), String JavaDoc[].class.getName(), int[][][].class.getName() });
107       // Hmmm... This fails in the RI (which causes the operation coverage test to fail too.
108
// it's odd because in the RI issuer() isn't treated as an attribute and it doesn't
109
// appear as an operation - it just disappears!
110
addOperationTest(testSuite, info, "issuer", MBeanOperationInfo.UNKNOWN, String JavaDoc.class.getName(), new String JavaDoc[0]);
111
112       // make sure we are testing all exposed operations (each ValidOperationTest increments a counter
113
// which is used to figure out whether we have adequate test coverage)
114
testSuite.addTest(new TestCoverageTEST("Torture operation list length", operationTestCount, info.getOperations().length));
115
116       return testSuite;
117    }
118
119    public static void addConstructorTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, String JavaDoc[] signature)
120    {
121       testSuite.addTest(new ConstructorInfoTEST("InfoTortureSUITE constructor", info, name, signature));
122       constructorTestCount++;
123    }
124
125    public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name)
126    {
127       testSuite.addTest(new SpuriousAttributeTEST("InfoTortureSUITE spuriousAttribute", info, name));
128    }
129
130    public static void addAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, String JavaDoc type, boolean read, boolean write, boolean is)
131    {
132       testSuite.addTest(new AttributeInfoTEST("InfoTortureSUITE attribute", info, name, type, read, write, is));
133       attributeTestCount++;
134    }
135
136    public static void addOperationTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, int impact, String JavaDoc returnType, String JavaDoc[] signature)
137    {
138       testSuite.addTest(new OperationInfoTEST("InfoTortureSUITE operation", info, name, impact, returnType, signature));
139       operationTestCount++;
140    }
141
142    public static class TestCoverageTEST extends TestCase
143    {
144       private String JavaDoc msg;
145       private int expected;
146       private int got;
147
148       public TestCoverageTEST(String JavaDoc msg, int expected, int got)
149       {
150          super("testAdequateCoverage");
151          this.msg = msg;
152          this.expected = expected;
153          this.got = got;
154       }
155
156       public void testAdequateCoverage()
157       {
158          assertEquals(msg, expected, got);
159       }
160    }
161
162 }
163
Popular Tags