KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > javax > management > openmbean > OpenMBeanConstructorInfoSupportTest


1 /**
2  * Copyright (C) The MX4J Contributors.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the MX4J License version 1.0.
6  * See the terms of the MX4J License in the documentation provided with this software.
7  */

8
9 package test.javax.management.openmbean;
10
11 import java.util.Arrays JavaDoc;
12 import java.util.Set JavaDoc;
13 import javax.management.openmbean.OpenMBeanConstructorInfo JavaDoc;
14 import javax.management.openmbean.OpenMBeanConstructorInfoSupport JavaDoc;
15 import javax.management.openmbean.OpenMBeanParameterInfo JavaDoc;
16 import javax.management.openmbean.OpenMBeanParameterInfoSupport JavaDoc;
17 import javax.management.openmbean.OpenType JavaDoc;
18 import javax.management.openmbean.SimpleType JavaDoc;
19
20 import junit.framework.TestCase;
21 import junit.textui.TestRunner;
22
23 /**
24  */

25 public class OpenMBeanConstructorInfoSupportTest extends TestCase
26 {
27    private static class MyMBeanParameterInfo implements OpenMBeanParameterInfo JavaDoc
28    {
29       public boolean equals(Object JavaDoc o)
30       {
31          return false;
32       }
33
34       public Object JavaDoc getDefaultValue()
35       {
36          return null;
37       }
38
39       public String JavaDoc getDescription()
40       {
41          return null;
42       }
43
44       public Set JavaDoc getLegalValues()
45       {
46          return null;
47       }
48
49       public Comparable JavaDoc getMaxValue()
50       {
51          return null;
52       }
53
54       public Comparable JavaDoc getMinValue()
55       {
56          return null;
57       }
58
59       public String JavaDoc getName()
60       {
61          return null;
62       }
63
64       public OpenType JavaDoc getOpenType()
65       {
66          return null;
67       }
68
69       public boolean hasDefaultValue()
70       {
71          return false;
72       }
73
74       public boolean hasLegalValues()
75       {
76          return false;
77       }
78
79       public boolean hasMinValue()
80       {
81          return false;
82       }
83
84       public boolean hasMaxValue()
85       {
86          return false;
87       }
88
89       public boolean isValue(Object JavaDoc o)
90       {
91          return false;
92       }
93
94       public String JavaDoc toString()
95       {
96          return null;
97       }
98    }
99
100    private OpenMBeanParameterInfo JavaDoc[] signature;
101
102    public static void main(String JavaDoc[] args)
103    {
104       TestRunner.run(OpenMBeanConstructorInfoSupportTest.class);
105    }
106
107    public void testCtor() throws Exception JavaDoc
108    {
109       OpenMBeanConstructorInfoSupport JavaDoc info =
110               new OpenMBeanConstructorInfoSupport JavaDoc("wine",
111                                                   "Non-default constructor",
112                                                   signature);
113       assertTrue("Null info constructed", info != null);
114       assertTrue("Unexpected name", info.getName().compareTo("wine") == 0);
115       assertTrue("Unexpected description",
116                  info.getDescription().compareTo("Non-default constructor") == 0);
117       assertTrue("Unexpected signature",
118                  Arrays.equals(info.getSignature(), signature));
119
120       info =
121       new OpenMBeanConstructorInfoSupport JavaDoc("wine",
122                                           "Non-default constructor",
123                                           null);
124       assertTrue("Null info constructed", info != null);
125       assertTrue("Unexpected name", info.getName().compareTo("wine") == 0);
126       assertTrue("Unexpected description",
127                  info.getDescription().compareTo("Non-default constructor") == 0);
128       assertTrue("Unexpected signature", info.getSignature() == null || info.getSignature().length == 0);
129
130       info =
131       new OpenMBeanConstructorInfoSupport JavaDoc("wine",
132                                           "Non-default constructor",
133                                           new OpenMBeanParameterInfoSupport JavaDoc[0]);
134       assertTrue("Null info constructed", info != null);
135       assertTrue("Unexpected name", info.getName().compareTo("wine") == 0);
136       assertTrue("Unexpected description",
137                  info.getDescription().compareTo("Non-default constructor") == 0);
138       assertTrue("Unexpected signature", info.getSignature().length == 0);
139    }
140
141    public void testCtorNullName() throws Exception JavaDoc
142    {
143       try
144       {
145          OpenMBeanConstructorInfoSupport JavaDoc info =
146                  new OpenMBeanConstructorInfoSupport JavaDoc(null,
147                                                      "Non-default constructor",
148                                                      signature);
149          fail("Expecting IllegalArgumentException");
150       }
151       catch (IllegalArgumentException JavaDoc x)
152       {
153          assertTrue(true);
154       }
155    }
156
157    public void testCtorEmptyName() throws Exception JavaDoc
158    {
159       try
160       {
161          OpenMBeanConstructorInfoSupport JavaDoc info =
162                  new OpenMBeanConstructorInfoSupport JavaDoc("",
163                                                      "Non-default constructor",
164                                                      signature);
165          fail("Expecting IllegalArgumentException");
166       }
167       catch (IllegalArgumentException JavaDoc x)
168       {
169          assertTrue(true);
170       }
171    }
172
173    public void testCtorNullDescription() throws Exception JavaDoc
174    {
175       try
176       {
177          OpenMBeanConstructorInfoSupport JavaDoc info =
178                  new OpenMBeanConstructorInfoSupport JavaDoc("wine", null, signature);
179          fail("Expecting IllegalArgumentException");
180       }
181       catch (IllegalArgumentException JavaDoc x)
182       {
183          assertTrue(true);
184       }
185    }
186
187    public void testCtorEmptyDescription() throws Exception JavaDoc
188    {
189       try
190       {
191          OpenMBeanConstructorInfoSupport JavaDoc info =
192                  new OpenMBeanConstructorInfoSupport JavaDoc("wine", "", signature);
193          fail("Expecting IllegalArgumentException");
194       }
195       catch (IllegalArgumentException JavaDoc x)
196       {
197          assertTrue(true);
198       }
199    }
200
201    public void testCtorBogusSignature() throws Exception JavaDoc
202    {
203       try
204       {
205          MyMBeanParameterInfo[] bogusig =
206                  {
207                     new MyMBeanParameterInfo(),
208                     new MyMBeanParameterInfo(),
209                     new MyMBeanParameterInfo()};
210
211          OpenMBeanConstructorInfoSupport JavaDoc info =
212                  new OpenMBeanConstructorInfoSupport JavaDoc("wine",
213                                                      "Non-default constructor",
214                                                      bogusig);
215          fail("Expecting ArrayStoreException");
216       }
217       catch (ArrayStoreException JavaDoc x)
218       {
219          assertTrue(true);
220       }
221    }
222
223    public void testEquals() throws Exception JavaDoc
224    {
225       OpenMBeanConstructorInfo JavaDoc infoone =
226               new OpenMBeanConstructorInfoSupport JavaDoc("wine", "Vino", signature);
227       assertTrue("Null infoone constructed", infoone != null);
228
229       OpenMBeanConstructorInfo JavaDoc infotwo =
230               new OpenMBeanConstructorInfoSupport JavaDoc("wine",
231                                                   "Nectar of the gods",
232                                                   signature);
233       assertTrue("Null infotwo constructed", infotwo != null);
234
235       assertTrue("Expected equality", infoone.equals(infotwo));
236
237       OpenMBeanConstructorInfo JavaDoc infothree =
238               new OpenMBeanConstructorInfoSupport JavaDoc("Vino", "Vino", signature);
239       assertTrue("Null infothree constructed", infothree != null);
240
241       assertFalse("Expected inequality based on name",
242                   infothree.equals(infoone));
243
244       OpenMBeanConstructorInfo JavaDoc infofour =
245               new OpenMBeanConstructorInfoSupport JavaDoc("wine",
246                                                   "Vino",
247                                                   new OpenMBeanParameterInfoSupport JavaDoc[0]);
248       assertTrue("Null infofour constructed", infofour != null);
249
250       assertFalse("Expected inequality based on signature",
251                   infofour.equals(infoone));
252    }
253
254    public void testHashCode() throws Exception JavaDoc
255    {
256       OpenMBeanConstructorInfo JavaDoc infoone =
257               new OpenMBeanConstructorInfoSupport JavaDoc("wine", "Vino", signature);
258       assertTrue("Null infoone constructed", infoone != null);
259
260       assertTrue("Unexpected hash code",
261                  infoone.hashCode() == hashCode(infoone));
262
263       OpenMBeanConstructorInfo JavaDoc infotwo =
264               new OpenMBeanConstructorInfoSupport JavaDoc("wine",
265                                                   "Nectar of the gods",
266                                                   signature);
267       assertTrue("Null infotwo constructed", infotwo != null);
268
269       assertTrue("Expecting equal hash codes",
270                  infoone.hashCode() == infotwo.hashCode());
271    }
272
273    protected void setUp()
274    {
275       try
276       {
277          signature =
278          new OpenMBeanParameterInfoSupport JavaDoc[]{
279             new OpenMBeanParameterInfoSupport JavaDoc("type",
280                                               "type of wine",
281                                               SimpleType.STRING,
282                                               "Red",
283                                               new String JavaDoc[]{"Red", "White", "Rose"}),
284             new OpenMBeanParameterInfoSupport JavaDoc("winery",
285                                               "who produced the wine",
286                                               SimpleType.STRING),
287             new OpenMBeanParameterInfoSupport JavaDoc("vintage",
288                                               "when the wine was produced",
289                                               SimpleType.INTEGER,
290                                               null,
291                                               new Integer JavaDoc(1900),
292                                               new Integer JavaDoc(2000))
293          };
294       }
295       catch (Exception JavaDoc x)
296       {
297          fail(x.toString());
298       }
299    }
300
301    protected void tearDown()
302    {
303    }
304
305    private int hashCode(OpenMBeanConstructorInfo JavaDoc info)
306    {
307       int result = info.getName().hashCode();
308       result += Arrays.asList(info.getSignature()).hashCode();
309       return result;
310    }
311 }
312
Popular Tags