KickJava   Java API By Example, From Geeks To Geeks.

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


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.Torture;
30
31 import javax.management.MBeanInfo JavaDoc;
32 import javax.management.MBeanOperationInfo JavaDoc;
33
34 /**
35  * Beat the heck out of the server's standard MBeanInfo
36  *
37  * @author <a HREF="mailto:trevor@protocool.com">Trevor Squires</a>.
38  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>.
39  */

40 public class InfoTortureTestCase
41    extends TestCase
42 {
43    private static int attributeTestCount = 0;
44    private static int operationTestCount = 0;
45    private static int constructorTestCount = 0;
46
47    public InfoTortureTestCase(String JavaDoc s)
48    {
49       super(s);
50    }
51
52    public static Test suite()
53    {
54       TestSuite testSuite = new TestSuite("All MBeanInfo Torture Tests for Standard MBeans");
55
56       Object JavaDoc mbean = new Torture();
57       MBeanInfo JavaDoc info = InfoUtil.getMBeanInfo(mbean, "test:type=mbeaninfo");
58
59       // Tests for valid constructors
60
addConstructorTest(testSuite, info, Torture.class.getName(), new String JavaDoc[0]);
61       addConstructorTest(testSuite, info, Torture.class.getName(), new String JavaDoc[] { String JavaDoc[][].class.getName() });
62
63       // make sure we are testing all exposed constructors (each ValidConstructorTest increments a counter
64
// which is used to figure out whether we have adequate test coverage)
65
testSuite.addTest(new TestCoverageTEST("Torture constructor list length", constructorTestCount, info.getConstructors().length));
66
67       // Tests for attributes that should not be there
68
addSpuriousAttributeTest(testSuite, info, "peachy");
69       addSpuriousAttributeTest(testSuite, info, "Peachy");
70       addSpuriousAttributeTest(testSuite, info, "suer");
71       addSpuriousAttributeTest(testSuite, info, "settlement");
72       addSpuriousAttributeTest(testSuite, info, "Result");
73       addSpuriousAttributeTest(testSuite, info, "Multi");
74
75       // make sure remaining attributes are correct
76
// Args are: Name, Type, Readable, Writable, IsIS
77
addAttributeTest(testSuite, info, "NiceString", String JavaDoc.class.getName(), true, true, false);
78       addAttributeTest(testSuite, info, "NiceBoolean", boolean.class.getName(), true, true, true);
79       addAttributeTest(testSuite, info, "Something", String JavaDoc.class.getName(), false, true, false);
80       addAttributeTest(testSuite, info, "Int", int.class.getName(), false, true, false);
81       addAttributeTest(testSuite, info, "IntArray", int[].class.getName(), false, true, false);
82       addAttributeTest(testSuite, info, "NestedIntArray", int[][][].class.getName(), false, true, false);
83       addAttributeTest(testSuite, info, "Integer", Integer JavaDoc.class.getName(), false, true, false);
84       addAttributeTest(testSuite, info, "IntegerArray", Integer JavaDoc[].class.getName(), false, true, false);
85       addAttributeTest(testSuite, info, "NestedIntegerArray", Integer JavaDoc[][][].class.getName(), false, true, false);
86       addAttributeTest(testSuite, info, "Myinteger", int.class.getName(), true, false, false);
87       addAttributeTest(testSuite, info, "MyintegerArray", int[].class.getName(), true, false, false);
88       addAttributeTest(testSuite, info, "MyNestedintegerArray", int[][][].class.getName(), true, false, false);
89       addAttributeTest(testSuite, info, "MyInteger", Integer JavaDoc.class.getName(), true, false, false);
90       addAttributeTest(testSuite, info, "MyIntegerArray", Integer JavaDoc[].class.getName(), true, false, false);
91       addAttributeTest(testSuite, info, "MyNestedIntegerArray", Integer JavaDoc[][][].class.getName(), true, false, false);
92       addAttributeTest(testSuite, info, "ready", boolean.class.getName(), true, false, true);
93
94       // this is *not* an attribute, it must appear as an operation
95
//addAttributeTest(testSuite, info, "Ready", Boolean.class.getName(), true, false, true);
96

97       // make sure we are testing all exposed attributes (each ValidAttributeTest increments a counter
98
// which is used to figure out whether we have adequate test coverage)
99
testSuite.addTest(new TestCoverageTEST("Torture attribute list length", attributeTestCount, info.getAttributes().length));
100
101       // validate the operations
102
// Args are: Name, impact, returnTypeString, SignatureAsStringArray
103
addOperationTest(testSuite, info, "settlement", MBeanOperationInfo.UNKNOWN, int.class.getName(), new String JavaDoc[] { String JavaDoc.class.getName() });
104       addOperationTest(testSuite, info, "getSomething", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[0]);
105       addOperationTest(testSuite, info, "ispeachy", MBeanOperationInfo.UNKNOWN, boolean.class.getName(), new String JavaDoc[] { int.class.getName() });
106       addOperationTest(testSuite, info, "isPeachy", MBeanOperationInfo.UNKNOWN, Boolean JavaDoc.class.getName(), new String JavaDoc[] { int.class.getName() });
107       addOperationTest(testSuite, info, "setMulti", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[] { String JavaDoc.class.getName(), Integer JavaDoc.class.getName() });
108       addOperationTest(testSuite, info, "getResult", MBeanOperationInfo.UNKNOWN, String JavaDoc.class.getName(), new String JavaDoc[] { String JavaDoc.class.getName() });
109       addOperationTest(testSuite, info, "setNothing", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[0]);
110       addOperationTest(testSuite, info, "getNothing", MBeanOperationInfo.UNKNOWN, Void.TYPE.getName(), new String JavaDoc[0]);
111       addOperationTest(testSuite, info, "doSomethingCrazy", MBeanOperationInfo.UNKNOWN, String JavaDoc[][].class.getName(), new String JavaDoc[] { Object JavaDoc[].class.getName(), String JavaDoc[].class.getName(), int[][][].class.getName() });
112       // Hmmm... This fails in the RI (which causes the operation coverage test to fail too.
113
// it's odd because in the RI issuer() isn't treated as an attribute and it doesn't
114
// appear as an operation - it just disappears!
115
addOperationTest(testSuite, info, "issuer", MBeanOperationInfo.UNKNOWN, String JavaDoc.class.getName(), new String JavaDoc[0]);
116
117       // this must appear as an operation, not an attribute
118
addOperationTest(testSuite, info, "isReady", MBeanOperationInfo.UNKNOWN, Boolean JavaDoc.class.getName(), new String JavaDoc[0]);
119       
120       // make sure we are testing all exposed operations (each ValidOperationTest increments a counter
121
// which is used to figure out whether we have adequate test coverage)
122
testSuite.addTest(new TestCoverageTEST("Torture operation list length", operationTestCount, info.getOperations().length));
123
124       return testSuite;
125    }
126
127    public static void addConstructorTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, String JavaDoc[] signature)
128    {
129       testSuite.addTest(new ConstructorInfoTEST("InfoTortureSUITE constructor", info, name, signature));
130       constructorTestCount++;
131    }
132
133    public static void addSpuriousAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name)
134    {
135       testSuite.addTest(new SpuriousAttributeTEST("InfoTortureSUITE spuriousAttribute", info, name));
136    }
137
138    public static void addAttributeTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, String JavaDoc type, boolean read, boolean write, boolean is)
139    {
140       testSuite.addTest(new AttributeInfoTEST("InfoTortureSUITE attribute", info, name, type, read, write, is));
141       attributeTestCount++;
142    }
143
144    public static void addOperationTest(TestSuite testSuite, MBeanInfo JavaDoc info, String JavaDoc name, int impact, String JavaDoc returnType, String JavaDoc[] signature)
145    {
146       testSuite.addTest(new OperationInfoTEST("InfoTortureSUITE operation", info, name, impact, returnType, signature));
147       operationTestCount++;
148    }
149
150    public static class TestCoverageTEST
151       extends TestCase
152    {
153       private String JavaDoc msg;
154       private int expected;
155       private int got;
156
157       public TestCoverageTEST(String JavaDoc msg, int expected, int got)
158       {
159          super("testAdequateCoverage");
160          this.msg = msg;
161          this.expected = expected;
162          this.got = got;
163       }
164
165       public void testAdequateCoverage()
166       {
167          assertEquals(msg, expected, got);
168       }
169    }
170
171 }
172
Popular Tags