KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > mx > mxbean > test > CompositeDataInvocationHandlerUnitTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, 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.mx.mxbean.test;
23
24 import javax.management.openmbean.CompositeData JavaDoc;
25 import javax.management.openmbean.InvalidKeyException JavaDoc;
26
27 import junit.framework.AssertionFailedError;
28 import junit.framework.Test;
29 import junit.framework.TestSuite;
30
31 import org.jboss.mx.mxbean.CompositeDataInvocationHandler;
32 import org.jboss.test.mx.mxbean.support.InvalidInterface;
33 import org.jboss.test.mx.mxbean.support.SimpleInterface;
34
35 /**
36  * CompositeDataInvocationHandlerUnitTestCase.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 1.1 $
40  */

41 public class CompositeDataInvocationHandlerUnitTestCase extends AbstractMXBeanTest
42 {
43    public static Test suite()
44    {
45       return new TestSuite(CompositeDataInvocationHandlerUnitTestCase.class);
46    }
47    
48    public CompositeDataInvocationHandlerUnitTestCase(String JavaDoc name)
49    {
50       super(name);
51    }
52    
53    public void testGetCompositeData() throws Exception JavaDoc
54    {
55       CompositeData JavaDoc compositeData = createTestCompositeData();
56       CompositeDataInvocationHandler test = new CompositeDataInvocationHandler(compositeData);
57       assertTrue(compositeData == test.getCompositeData());
58    }
59    
60    public void testNullCompositeData() throws Exception JavaDoc
61    {
62       try
63       {
64          new CompositeDataInvocationHandler(null);
65          fail("Should not be here");
66       }
67       catch (AssertionFailedError e)
68       {
69          throw e;
70       }
71       catch (Throwable JavaDoc t)
72       {
73          checkThrowable(IllegalArgumentException JavaDoc.class, t);
74       }
75    }
76    
77    public void testToEquals() throws Exception JavaDoc
78    {
79       SimpleInterface test1 = createTestCompositeDataProxy("Test1");
80       
81       assertFalse(test1.equals(null));
82       assertFalse(test1.equals(new Object JavaDoc()));
83       assertTrue(test1.equals(test1));
84
85       SimpleInterface test2 = createTestCompositeDataProxy("Test2");
86       
87       assertFalse(test1.equals(test2));
88    }
89    
90    public void testHashCode() throws Exception JavaDoc
91    {
92       CompositeData JavaDoc compositeData = createTestCompositeData();
93       SimpleInterface test = createCompositeDataProxy(SimpleInterface.class, compositeData);
94
95       assertEquals(test.hashCode(), compositeData.hashCode());
96    }
97    
98    public void testToString() throws Exception JavaDoc
99    {
100       CompositeData JavaDoc compositeData = createTestCompositeData();
101       SimpleInterface test = createCompositeDataProxy(SimpleInterface.class, compositeData);
102
103       assertEquals(test.toString(), compositeData.toString());
104    }
105    
106    public void testGetSimpleTypes() throws Exception JavaDoc
107    {
108       SimpleInterface test = createTestCompositeDataProxy();
109       assertEquals(SimpleInterface.bigDecimalValue, test.getBigDecimal());
110       assertEquals(SimpleInterface.bigIntegerValue, test.getBigInteger());
111       assertEquals(SimpleInterface.booleanValue, test.getBoolean());
112       assertEquals(SimpleInterface.primitiveBooleanValue, test.isPrimitiveBoolean());
113       assertEquals(SimpleInterface.byteValue, test.getByte());
114       assertEquals(SimpleInterface.primitiveByteValue, test.getPrimitiveByte());
115       assertEquals(SimpleInterface.characterValue, test.getCharacter());
116       assertEquals(SimpleInterface.primitiveCharValue, test.getPrimitiveChar());
117       assertEquals(SimpleInterface.dateValue, test.getDate());
118       assertEquals(SimpleInterface.doubleValue, test.getDouble());
119       assertEquals(SimpleInterface.primitiveDoubleValue, test.getPrimitiveDouble());
120       assertEquals(SimpleInterface.floatValue, test.getFloat());
121       assertEquals(SimpleInterface.primitiveFloatValue, test.getPrimitiveFloat());
122       assertEquals(SimpleInterface.integerValue, test.getInteger());
123       assertEquals(SimpleInterface.primitiveIntValue, test.getPrimitiveInt());
124       assertEquals(SimpleInterface.longValue, test.getLong());
125       assertEquals(SimpleInterface.primitiveLongValue, test.getPrimitiveLong());
126       assertEquals(SimpleInterface.objectNameValue, test.getObjectName());
127       assertEquals(SimpleInterface.shortValue, test.getShort());
128       assertEquals(SimpleInterface.primitiveShortValue, test.getPrimitiveShort());
129       assertEquals(SimpleInterface.stringValue, test.getString());
130    }
131    
132    public void testNullPrimitives() throws Exception JavaDoc
133    {
134       SimpleInterface test = createNullCompositeDataProxy();
135       assertNull(test.getBigDecimal());
136       assertNull(test.getBigInteger());
137       assertNull(test.getBoolean());
138       try
139       {
140          test.isPrimitiveBoolean();
141          fail("Should not be here");
142       }
143       catch (AssertionFailedError e)
144       {
145          throw e;
146       }
147       catch (Throwable JavaDoc t)
148       {
149          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
150       }
151       assertNull(test.getByte());
152       try
153       {
154          test.getPrimitiveByte();
155          fail("Should not be here");
156       }
157       catch (AssertionFailedError e)
158       {
159          throw e;
160       }
161       catch (Throwable JavaDoc t)
162       {
163          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
164       }
165       assertNull(test.getCharacter());
166       try
167       {
168          test.getPrimitiveChar();
169          fail("Should not be here");
170       }
171       catch (AssertionFailedError e)
172       {
173          throw e;
174       }
175       catch (Throwable JavaDoc t)
176       {
177          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
178       }
179       assertNull(test.getDate());
180       assertNull(test.getDouble());
181       try
182       {
183          test.getPrimitiveDouble();
184          fail("Should not be here");
185       }
186       catch (AssertionFailedError e)
187       {
188          throw e;
189       }
190       catch (Throwable JavaDoc t)
191       {
192          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
193       }
194       assertNull(test.getFloat());
195       try
196       {
197          test.getPrimitiveFloat();
198          fail("Should not be here");
199       }
200       catch (AssertionFailedError e)
201       {
202          throw e;
203       }
204       catch (Throwable JavaDoc t)
205       {
206          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
207       }
208       assertNull(test.getInteger());
209       try
210       {
211          test.getPrimitiveInt();
212          fail("Should not be here");
213       }
214       catch (AssertionFailedError e)
215       {
216          throw e;
217       }
218       catch (Throwable JavaDoc t)
219       {
220          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
221       }
222       assertNull(test.getLong());
223       try
224       {
225          test.getPrimitiveLong();
226          fail("Should not be here");
227       }
228       catch (AssertionFailedError e)
229       {
230          throw e;
231       }
232       catch (Throwable JavaDoc t)
233       {
234          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
235       }
236       assertNull(test.getObjectName());
237       assertNull(test.getShort());
238       try
239       {
240          test.getPrimitiveShort();
241          fail("Should not be here");
242       }
243       catch (AssertionFailedError e)
244       {
245          throw e;
246       }
247       catch (Throwable JavaDoc t)
248       {
249          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
250       }
251       assertNull(SimpleInterface.stringValue, test.getString());
252    }
253    
254    public void testGetInvalid() throws Exception JavaDoc
255    {
256       InvalidInterface test = createInvalidCompositeDataProxy();
257       try
258       {
259          test.getInvalid();
260          fail("Should not be here");
261       }
262       catch (AssertionFailedError e)
263       {
264          throw e;
265       }
266       catch (Throwable JavaDoc t)
267       {
268          checkThrowableDeep(IllegalArgumentException JavaDoc.class, InvalidKeyException JavaDoc.class, t);
269       }
270    }
271    
272    public void testNotAGetter() throws Exception JavaDoc
273    {
274       InvalidInterface test = createInvalidCompositeDataProxy();
275       try
276       {
277          test.notAGetter();
278          fail("Should not be here");
279       }
280       catch (AssertionFailedError e)
281       {
282          throw e;
283       }
284       catch (Throwable JavaDoc t)
285       {
286          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
287       }
288    }
289    
290    public void testGetNoReturnType() throws Exception JavaDoc
291    {
292       InvalidInterface test = createInvalidCompositeDataProxy();
293       try
294       {
295          test.getString();
296          fail("Should not be here");
297       }
298       catch (AssertionFailedError e)
299       {
300          throw e;
301       }
302       catch (Throwable JavaDoc t)
303       {
304          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
305       }
306    }
307    
308    public void testGetWithParameters() throws Exception JavaDoc
309    {
310       InvalidInterface test = createInvalidCompositeDataProxy();
311       try
312       {
313          test.getString(null);
314          fail("Should not be here");
315       }
316       catch (AssertionFailedError e)
317       {
318          throw e;
319       }
320       catch (Throwable JavaDoc t)
321       {
322          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
323       }
324    }
325    
326    public void testIsNotBoolean() throws Exception JavaDoc
327    {
328       InvalidInterface test = createInvalidCompositeDataProxy();
329       try
330       {
331          test.isString();
332          fail("Should not be here");
333       }
334       catch (AssertionFailedError e)
335       {
336          throw e;
337       }
338       catch (Throwable JavaDoc t)
339       {
340          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
341       }
342    }
343    
344    public void testIsBoolean() throws Exception JavaDoc
345    {
346       InvalidInterface test = createInvalidCompositeDataProxy();
347       try
348       {
349          test.isBoolean();
350          fail("Should not be here");
351       }
352       catch (AssertionFailedError e)
353       {
354          throw e;
355       }
356       catch (Throwable JavaDoc t)
357       {
358          checkThrowableDeep(IllegalArgumentException JavaDoc.class, t);
359       }
360    }
361 }
362
Popular Tags