KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > compliance > openmbean > OpenMBeanAttributeInfoSupportTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package test.compliance.openmbean;
9
10 import junit.framework.TestCase;
11
12 import java.io.ByteArrayInputStream;
13 import java.io.ByteArrayOutputStream;
14 import java.io.ObjectInputStream;
15 import java.io.ObjectOutputStream;
16
17 import javax.management.openmbean.ArrayType;
18 import javax.management.openmbean.CompositeType;
19 import javax.management.openmbean.OpenDataException;
20 import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
21 import javax.management.openmbean.OpenType;
22 import javax.management.openmbean.SimpleType;
23 import javax.management.openmbean.TabularDataSupport;
24 import javax.management.openmbean.TabularType;
25
26 /**
27  * Open MBean Attribute Info tests.<p>
28  *
29  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
30  */

31 public class OpenMBeanAttributeInfoSupportTestCase
32   extends TestCase
33 {
34    // Static --------------------------------------------------------------------
35

36    // Attributes ----------------------------------------------------------------
37

38    // Constructor ---------------------------------------------------------------
39

40    /**
41     * Construct the test
42     */

43    public OpenMBeanAttributeInfoSupportTestCase(String s)
44    {
45       super(s);
46    }
47
48    // Tests ---------------------------------------------------------------------
49

50    public void testOpenMBeanAttributeInfoSupport()
51       throws Exception
52    {
53       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
54          "name", "description", SimpleType.STRING, true, true, false);
55       assertEquals("name", info.getName());
56       assertEquals("description", info.getDescription());
57       assertEquals("java.lang.String", info.getType());
58       assertEquals(true, info.isWritable());
59       assertEquals(true, info.isReadable());
60       assertEquals(false, info.isIs());
61
62       info = new OpenMBeanAttributeInfoSupport(
63          "name", "description", SimpleType.STRING, true, true, false, "default");
64       assertEquals("name", info.getName());
65       assertEquals("description", info.getDescription());
66       assertEquals("java.lang.String", info.getType());
67       assertEquals(true, info.isWritable());
68       assertEquals(true, info.isReadable());
69       assertEquals(false, info.isIs());
70       assertEquals("default", info.getDefaultValue());
71       assertEquals(true, info.hasDefaultValue());
72
73       info = new OpenMBeanAttributeInfoSupport(
74          "name", "description", SimpleType.STRING, true, true, false, null);
75       assertEquals("name", info.getName());
76       assertEquals("description", info.getDescription());
77       assertEquals("java.lang.String", info.getType());
78       assertEquals(true, info.isWritable());
79       assertEquals(true, info.isReadable());
80       assertEquals(false, info.isIs());
81       assertEquals(null, info.getDefaultValue());
82       assertEquals(false, info.hasDefaultValue());
83
84       info = new OpenMBeanAttributeInfoSupport(
85          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(2), new Integer(4));
86       assertEquals("name", info.getName());
87       assertEquals("description", info.getDescription());
88       assertEquals("java.lang.Integer", info.getType());
89       assertEquals(true, info.isWritable());
90       assertEquals(true, info.isReadable());
91       assertEquals(false, info.isIs());
92       assertEquals(new Integer(3), info.getDefaultValue());
93       assertEquals(new Integer(2), info.getMinValue());
94       assertEquals(new Integer(4), info.getMaxValue());
95
96       info = new OpenMBeanAttributeInfoSupport(
97          "name", "description", SimpleType.INTEGER, true, true, false, null, new Integer(2), new Integer(4));
98       assertEquals("name", info.getName());
99       assertEquals("description", info.getDescription());
100       assertEquals("java.lang.Integer", info.getType());
101       assertEquals(true, info.isWritable());
102       assertEquals(true, info.isReadable());
103       assertEquals(false, info.isIs());
104       assertEquals(null, info.getDefaultValue());
105       assertEquals(new Integer(2), info.getMinValue());
106       assertEquals(new Integer(4), info.getMaxValue());
107
108       info = new OpenMBeanAttributeInfoSupport(
109          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3), null, new Integer(4));
110       assertEquals("name", info.getName());
111       assertEquals("description", info.getDescription());
112       assertEquals("java.lang.Integer", info.getType());
113       assertEquals(true, info.isWritable());
114       assertEquals(true, info.isReadable());
115       assertEquals(false, info.isIs());
116       assertEquals(new Integer(3), info.getDefaultValue());
117       assertEquals(null, info.getMinValue());
118       assertEquals(new Integer(4), info.getMaxValue());
119
120       info = new OpenMBeanAttributeInfoSupport(
121          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(2), null);
122       assertEquals("name", info.getName());
123       assertEquals("description", info.getDescription());
124       assertEquals("java.lang.Integer", info.getType());
125       assertEquals(true, info.isWritable());
126       assertEquals(true, info.isReadable());
127       assertEquals(false, info.isIs());
128       assertEquals(new Integer(3), info.getDefaultValue());
129       assertEquals(new Integer(2), info.getMinValue());
130       assertEquals(null, info.getMaxValue());
131
132       info = new OpenMBeanAttributeInfoSupport(
133          "name", "description", SimpleType.INTEGER, true, true, false, null, null, new Integer(4));
134       assertEquals("name", info.getName());
135       assertEquals("description", info.getDescription());
136       assertEquals("java.lang.Integer", info.getType());
137       assertEquals(true, info.isWritable());
138       assertEquals(true, info.isReadable());
139       assertEquals(false, info.isIs());
140       assertEquals(null, info.getDefaultValue());
141       assertEquals(null, info.getMinValue());
142       assertEquals(new Integer(4), info.getMaxValue());
143
144       info = new OpenMBeanAttributeInfoSupport(
145          "name", "description", SimpleType.INTEGER, true, true, false, null, new Integer(2), null);
146       assertEquals("name", info.getName());
147       assertEquals("description", info.getDescription());
148       assertEquals("java.lang.Integer", info.getType());
149       assertEquals(true, info.isWritable());
150       assertEquals(true, info.isReadable());
151       assertEquals(false, info.isIs());
152       assertEquals(null, info.getDefaultValue());
153       assertEquals(new Integer(2), info.getMinValue());
154       assertEquals(null, info.getMaxValue());
155
156       info = new OpenMBeanAttributeInfoSupport(
157          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3), null, null);
158       assertEquals("name", info.getName());
159       assertEquals("description", info.getDescription());
160       assertEquals("java.lang.Integer", info.getType());
161       assertEquals(true, info.isWritable());
162       assertEquals(true, info.isReadable());
163       assertEquals(false, info.isIs());
164       assertEquals(new Integer(3), info.getDefaultValue());
165       assertEquals(null, info.getMinValue());
166       assertEquals(null, info.getMaxValue());
167
168       info = new OpenMBeanAttributeInfoSupport(
169          "name", "description", SimpleType.INTEGER, true, true, false, null, null, null);
170       assertEquals("name", info.getName());
171       assertEquals("description", info.getDescription());
172       assertEquals("java.lang.Integer", info.getType());
173       assertEquals(true, info.isWritable());
174       assertEquals(true, info.isReadable());
175       assertEquals(false, info.isIs());
176       assertEquals(null, info.getDefaultValue());
177       assertEquals(null, info.getMinValue());
178       assertEquals(null, info.getMaxValue());
179
180       info = new OpenMBeanAttributeInfoSupport(
181          "name", "description", SimpleType.STRING, true, true, false, "default",
182          new Object[] { "legal1", "legal2", "default" });
183       assertEquals("name", info.getName());
184       assertEquals("description", info.getDescription());
185       assertEquals("java.lang.String", info.getType());
186       assertEquals(true, info.isWritable());
187       assertEquals(true, info.isReadable());
188       assertEquals(false, info.isIs());
189       assertEquals("default", info.getDefaultValue());
190       assertEquals(3, info.getLegalValues().size());
191       assertTrue("legal1 should be a legal value", info.getLegalValues().contains("legal1"));
192       assertTrue("legal2 should be a legal value", info.getLegalValues().contains("legal2"));
193       assertTrue("default should be a legal value", info.getLegalValues().contains("default"));
194
195       info = new OpenMBeanAttributeInfoSupport(
196          "name", "description", SimpleType.STRING, true, true, false, null,
197          new Object[] { "legal1", "legal2", "default" });
198       assertEquals("name", info.getName());
199       assertEquals("description", info.getDescription());
200       assertEquals("java.lang.String", info.getType());
201       assertEquals(true, info.isWritable());
202       assertEquals(true, info.isReadable());
203       assertEquals(false, info.isIs());
204       assertEquals(null, info.getDefaultValue());
205       assertEquals(3, info.getLegalValues().size());
206       assertTrue("legal1 should be a legal value", info.getLegalValues().contains("legal1"));
207       assertTrue("legal2 should be a legal value", info.getLegalValues().contains("legal2"));
208       assertTrue("default should be a legal value", info.getLegalValues().contains("default"));
209
210       info = new OpenMBeanAttributeInfoSupport(
211          "name", "description", SimpleType.STRING, true, true, false, "default", null);
212       assertEquals("name", info.getName());
213       assertEquals("description", info.getDescription());
214       assertEquals("java.lang.String", info.getType());
215       assertEquals(true, info.isWritable());
216       assertEquals(true, info.isReadable());
217       assertEquals(false, info.isIs());
218       assertEquals("default", info.getDefaultValue());
219       assertEquals(null, info.getLegalValues());
220
221       info = new OpenMBeanAttributeInfoSupport(
222          "name", "description", SimpleType.STRING, true, true, false, null, null);
223       assertEquals("name", info.getName());
224       assertEquals("description", info.getDescription());
225       assertEquals("java.lang.String", info.getType());
226       assertEquals(true, info.isWritable());
227       assertEquals(true, info.isReadable());
228       assertEquals(false, info.isIs());
229       assertEquals(null, info.getDefaultValue());
230       assertEquals(null, info.getLegalValues());
231    }
232
233    public void testOpenType()
234       throws Exception
235    {
236       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
237          "name", "description", SimpleType.STRING, true, true, false);
238       assertEquals(SimpleType.STRING, info.getOpenType());
239    }
240
241    public void testHas()
242       throws Exception
243    {
244       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
245          "name", "description", SimpleType.STRING, true, true, false, "default");
246       assertEquals(true, info.hasDefaultValue());
247
248       info = new OpenMBeanAttributeInfoSupport(
249          "name", "description", SimpleType.STRING, true, true, false, null);
250       assertEquals(false, info.hasDefaultValue());
251
252       info = new OpenMBeanAttributeInfoSupport(
253          "name", "description", SimpleType.INTEGER, true, true, false, null, new Integer(3), null);
254       assertEquals(true, info.hasMinValue());
255
256       info = new OpenMBeanAttributeInfoSupport(
257          "name", "description", SimpleType.INTEGER, true, true, false, null, null, null);
258       assertEquals(false, info.hasMinValue());
259
260       info = new OpenMBeanAttributeInfoSupport(
261          "name", "description", SimpleType.INTEGER, true, true, false, null, null, new Integer(3));
262       assertEquals(true, info.hasMaxValue());
263
264       info = new OpenMBeanAttributeInfoSupport(
265          "name", "description", SimpleType.INTEGER, true, true, false, null, null, null);
266       assertEquals(false, info.hasMaxValue());
267
268       info = new OpenMBeanAttributeInfoSupport(
269          "name", "description", SimpleType.INTEGER, true, true, false, null, new Object[] { new Integer(3) });
270       assertEquals(true, info.hasLegalValues());
271
272       info = new OpenMBeanAttributeInfoSupport(
273          "name", "description", SimpleType.INTEGER, true, true, false, null, null);
274       assertEquals(false, info.hasLegalValues());
275    }
276
277    public void testIsValue()
278       throws Exception
279    {
280       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
281          "name", "description", SimpleType.STRING, true, true, false);
282       assertTrue("String should be a value", info.isValue("string"));
283       assertTrue("Integer should not be a value", info.isValue(new Integer(3)) == false);
284       assertTrue("Null should not be a value", info.isValue(null) == false);
285    }
286
287    public void testIsWritable()
288       throws Exception
289    {
290       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
291          "name", "description", SimpleType.STRING, true, true, false);
292       assertEquals(true, info.isWritable());
293       info = new OpenMBeanAttributeInfoSupport(
294          "name", "description", SimpleType.STRING, true, false, false);
295       assertEquals(false, info.isWritable());
296    }
297
298    public void testIsReadable()
299       throws Exception
300    {
301       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
302          "name", "description", SimpleType.STRING, true, true, false);
303       assertEquals(true, info.isReadable());
304       info = new OpenMBeanAttributeInfoSupport(
305          "name", "description", SimpleType.STRING, false, true, false);
306       assertEquals(false, info.isReadable());
307    }
308
309    public void testIsIs()
310       throws Exception
311    {
312       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
313          "name", "description", SimpleType.BOOLEAN, true, true, true);
314       assertEquals(true, info.isIs());
315       info = new OpenMBeanAttributeInfoSupport(
316          "name", "description", SimpleType.STRING, true, true, false);
317       assertEquals(false, info.isIs());
318    }
319
320    public void testEquals()
321       throws Exception
322    {
323       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
324          "name", "description", SimpleType.STRING, true, true, false);
325
326       assertTrue("Null should not be equal", info.equals(null) == false);
327       assertTrue("Only OpenMBeanAttributeInfo should be equal", info.equals(new Object()) == false);
328
329       OpenMBeanAttributeInfoSupport info2 = new OpenMBeanAttributeInfoSupport(
330          "name", "description", SimpleType.STRING, true, true, false);
331
332       assertTrue("Different instances of the same data are equal", info.equals(info2));
333       assertTrue("Different instances of the same data are equal", info2.equals(info));
334
335       info2 = new OpenMBeanAttributeInfoSupport(
336          "name", "description2", SimpleType.STRING, true, true, false);
337
338       assertTrue("Different instances with different descriptions are equal", info.equals(info2));
339       assertTrue("Different instances with different descritpions are equal", info2.equals(info));
340
341       info2 = new OpenMBeanAttributeInfoSupport(
342          "name2", "description", SimpleType.STRING, true, true, false);
343
344       assertTrue("Instances with different names are not equal", info.equals(info2) == false);
345       assertTrue("Instances with different names are not equal", info2.equals(info) == false);
346
347       info2 = new OpenMBeanAttributeInfoSupport(
348          "name", "description", SimpleType.INTEGER, true, true, false);
349
350       assertTrue("Instances with different types are not equal", info.equals(info2) == false);
351       assertTrue("Instances with different types are not equal", info2.equals(info) == false);
352
353       info2 = new OpenMBeanAttributeInfoSupport(
354          "name", "description", SimpleType.INTEGER, false, true, false);
355
356       assertTrue("Instances with different read are not equal", info.equals(info2) == false);
357       assertTrue("Instances with different read are not equal", info2.equals(info) == false);
358
359       info2 = new OpenMBeanAttributeInfoSupport(
360          "name", "description", SimpleType.INTEGER, true, false, false);
361
362       assertTrue("Instances with different write are not equal", info.equals(info2) == false);
363       assertTrue("Instances with different write are not equal", info2.equals(info) == false);
364
365       info2 = new OpenMBeanAttributeInfoSupport(
366          "name", "description", SimpleType.BOOLEAN, true, true, true);
367       info2 = new OpenMBeanAttributeInfoSupport(
368          "name", "description", SimpleType.BOOLEAN, true, true, true);
369
370       assertTrue("Instances with different write are not equal", info.equals(info2) == false);
371       assertTrue("Instances with different write are not equal", info2.equals(info) == false);
372
373       info = new OpenMBeanAttributeInfoSupport(
374          "name", "description", SimpleType.INTEGER, true, true, false,
375           new Integer(3), new Integer(2), new Integer(4));
376       info2 = new OpenMBeanAttributeInfoSupport(
377          "name", "description", SimpleType.INTEGER, true, true, false,
378          new Integer(2), new Integer(2), new Integer(4));
379
380       assertTrue("Instances with different default values are not equal", info.equals(info2) == false);
381       assertTrue("Instances with different default values are not equal", info2.equals(info) == false);
382
383       info = new OpenMBeanAttributeInfoSupport(
384          "name", "description", SimpleType.INTEGER, true, true, false,
385          new Integer(3), new Integer(2), new Integer(4));
386       info2 = new OpenMBeanAttributeInfoSupport(
387          "name", "description", SimpleType.INTEGER, true, true, false,
388          new Integer(2), null, new Integer(4));
389
390       assertTrue("Instances with different default values are not equal", info.equals(info2) == false);
391       assertTrue("Instances with different default values are not equal", info2.equals(info) == false);
392
393       info = new OpenMBeanAttributeInfoSupport(
394          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3));
395       info2 = new OpenMBeanAttributeInfoSupport(
396          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3));
397
398       assertTrue("Different instances of the same default value are equal", info.equals(info2));
399       assertTrue("Different instances of the same default value are equal", info2.equals(info));
400
401       info = new OpenMBeanAttributeInfoSupport(
402          "name", "description", SimpleType.INTEGER, true, true, false,
403          null, new Integer(2), null);
404       info2 = new OpenMBeanAttributeInfoSupport(
405          "name", "description", SimpleType.INTEGER, true, true, false,
406          null, new Integer(2), null);
407
408       assertTrue("Different instances of the same minimum are equal", info.equals(info2));
409       assertTrue("Different instances of the same minimum are equal", info2.equals(info));
410
411       info = new OpenMBeanAttributeInfoSupport(
412          "name", "description", SimpleType.INTEGER, true, true, false,
413          null, null, new Integer(2));
414       info2 = new OpenMBeanAttributeInfoSupport(
415          "name", "description", SimpleType.INTEGER, true, true, false,
416          null, null, new Integer(2));
417
418       assertTrue("Different instances of the same maximum are equal", info.equals(info2));
419       assertTrue("Different instances of the same maximum are equal", info2.equals(info));
420
421       info = new OpenMBeanAttributeInfoSupport(
422          "name", "description", SimpleType.INTEGER, true, true, false,
423          new Integer(3), new Integer(2), new Integer(4));
424       info2 = new OpenMBeanAttributeInfoSupport(
425          "name", "description", SimpleType.INTEGER, true, true, false,
426          new Integer(3), new Integer(1), new Integer(4));
427
428       assertTrue("Instances with different minimums are not equal", info.equals(info2) == false);
429       assertTrue("Instances with different minimums are not equal", info2.equals(info) == false);
430
431       info = new OpenMBeanAttributeInfoSupport(
432          "name", "description", SimpleType.INTEGER, true, true, false,
433          new Integer(3), new Integer(2), new Integer(4));
434       info2 = new OpenMBeanAttributeInfoSupport(
435          "name", "description", SimpleType.INTEGER, true, true, false,
436          new Integer(3), null, new Integer(4));
437
438       assertTrue("Instances with different minimums are not equal", info.equals(info2) == false);
439       assertTrue("Instances with different minimums are not equal", info2.equals(info) == false);
440
441       info = new OpenMBeanAttributeInfoSupport(
442          "name", "description", SimpleType.INTEGER, true, true, false,
443          new Integer(3), new Integer(2), new Integer(4));
444       info2 = new OpenMBeanAttributeInfoSupport(
445          "name", "description", SimpleType.INTEGER, true, true, false,
446          new Integer(3), new Integer(2), new Integer(5));
447
448       assertTrue("Instances with different maximums are not equal", info.equals(info2) == false);
449       assertTrue("Instances with different maximums are not equal", info2.equals(info) == false);
450
451       info = new OpenMBeanAttributeInfoSupport(
452          "name", "description", SimpleType.INTEGER, true, true, false,
453          new Integer(3), new Integer(2), new Integer(4));
454       info2 = new OpenMBeanAttributeInfoSupport(
455          "name", "description", SimpleType.INTEGER, true, true, false,
456          new Integer(3), new Integer(2), null);
457
458       assertTrue("Instances with different maximums are not equal", info.equals(info2) == false);
459       assertTrue("Instances with different maximums are not equal", info2.equals(info) == false);
460
461       info = new OpenMBeanAttributeInfoSupport(
462          "name", "description", SimpleType.INTEGER, true, true, false,
463          null, new Object[] { new Integer(2), new Integer(3) });
464       info2 = new OpenMBeanAttributeInfoSupport(
465          "name", "description", SimpleType.INTEGER, true, true, false,
466          null, new Object[] { new Integer(2), new Integer(3) });
467
468       assertTrue("Different instances of the same legal values are equal", info.equals(info2));
469       assertTrue("Different instances of the same legal values are equal", info2.equals(info));
470
471       info = new OpenMBeanAttributeInfoSupport(
472          "name", "description", SimpleType.INTEGER, true, true, false,
473          null, new Object[] { new Integer(2), new Integer(3) });
474       info2 = new OpenMBeanAttributeInfoSupport(
475          "name", "description", SimpleType.INTEGER, true, true, false,
476          null, new Object[] { new Integer(2), new Integer(4) });
477
478       assertTrue("Different instances with different legal values are equal", info.equals(info2) == false);
479       assertTrue("Different instances with different legal values are equal", info2.equals(info) == false);
480
481       info = new OpenMBeanAttributeInfoSupport(
482          "name", "description", SimpleType.INTEGER, true, true, false,
483          null, new Object[] { new Integer(2), new Integer(3) });
484       info2 = new OpenMBeanAttributeInfoSupport(
485          "name", "description", SimpleType.INTEGER, true, true, false,
486          null, new Object[] { new Integer(2) });
487
488       assertTrue("Different instances with different legal values are equal", info.equals(info2) == false);
489       assertTrue("Different instances with different legal values are equal", info2.equals(info) == false);
490
491       info = new OpenMBeanAttributeInfoSupport(
492          "name", "description", SimpleType.INTEGER, true, true, false,
493          null, new Object[] { new Integer(2), new Integer(3) });
494       info2 = new OpenMBeanAttributeInfoSupport(
495          "name", "description", SimpleType.INTEGER, true, true, false,
496          null, null);
497
498       assertTrue("Different instances with different legal values are equal", info.equals(info2) == false);
499       assertTrue("Different instances with different legal values are equal", info2.equals(info) == false);
500    }
501
502    public void testHashCode()
503       throws Exception
504    {
505
506       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
507          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(2), new Integer(4));
508       int myHash = "name".hashCode() + SimpleType.INTEGER.hashCode() +
509          new Integer(3).hashCode() + new Integer(2).hashCode() + new Integer(4).hashCode();
510       assertEquals(myHash, info.hashCode());
511       info = new OpenMBeanAttributeInfoSupport(
512          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3),
513          new Object[] { new Integer(2), new Integer(3), new Integer(4) } );
514       myHash = "name".hashCode() + SimpleType.INTEGER.hashCode() +
515          new Integer(3).hashCode() + new Integer(2).hashCode() + new Integer(3).hashCode() + new Integer(4).hashCode();
516       assertEquals(myHash, info.hashCode());
517    }
518
519    public void testToString()
520       throws Exception
521    {
522       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
523          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(2), new Integer(4));
524
525       String toString = info.toString();
526       assertTrue("info.toString() should contain the name", toString.indexOf("name") != -1);
527       assertTrue("info.toString() should contain the simple type",
528          toString.indexOf(SimpleType.INTEGER.toString()) != -1);
529       assertTrue("info.toString() should contain the default value",
530          toString.indexOf(new Integer(3).toString()) != -1);
531       assertTrue("info.toString() should contain the minimum value",
532          toString.indexOf(new Integer(2).toString()) != -1);
533       assertTrue("info.toString() should contain the maximum value",
534          toString.indexOf(new Integer(4).toString()) != -1);
535
536       info = new OpenMBeanAttributeInfoSupport(
537          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3),
538          new Object[] { new Integer(2), new Integer(3), new Integer(4) } );
539       assertTrue("info.toString() should contain the legal value 2",
540          toString.indexOf(new Integer(2).toString()) != -1);
541       assertTrue("info.toString() should contain the legal value 3",
542          toString.indexOf(new Integer(3).toString()) != -1);
543       assertTrue("info.toString() should contain the legal value 4",
544          toString.indexOf(new Integer(4).toString()) != -1);
545    }
546
547    public void testSerialization()
548       throws Exception
549    {
550       OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
551          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(2), new Integer(4));
552
553       // Serialize it
554
ByteArrayOutputStream baos = new ByteArrayOutputStream();
555       ObjectOutputStream oos = new ObjectOutputStream(baos);
556       oos.writeObject(info);
557     
558       // Deserialize it
559
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
560       ObjectInputStream ois = new ObjectInputStream(bais);
561       Object result = ois.readObject();
562
563       assertEquals(info, result);
564
565       info = new OpenMBeanAttributeInfoSupport(
566          "name", "description", SimpleType.INTEGER, true, true, false, new Integer(3),
567          new Object[] { new Integer(2), new Integer(3), new Integer(4) } );
568
569       // Serialize it
570
baos = new ByteArrayOutputStream();
571       oos = new ObjectOutputStream(baos);
572       oos.writeObject(info);
573     
574       // Deserialize it
575
bais = new ByteArrayInputStream(baos.toByteArray());
576       ois = new ObjectInputStream(bais);
577       result = ois.readObject();
578
579       assertEquals(info, result);
580    }
581
582    public void testErrors1()
583       throws Exception
584    {
585       boolean caught = false;
586       try
587       {
588          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
589             null, "description", SimpleType.INTEGER, true, true, false);
590       }
591       catch (IllegalArgumentException e)
592       {
593          caught = true;
594       }
595       if (caught == false)
596          fail("Expected IllegalArgumentException for null name");
597
598       caught = false;
599       try
600       {
601          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
602             "", "description", SimpleType.INTEGER, true, true, false);
603       }
604       catch (IllegalArgumentException e)
605       {
606          caught = true;
607       }
608       if (caught == false)
609          fail("Expected IllegalArgumentException for an empty name");
610
611       caught = false;
612       try
613       {
614          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
615             "name", null, SimpleType.INTEGER, true, true, false);
616       }
617       catch (IllegalArgumentException e)
618       {
619          caught = true;
620       }
621       if (caught == false)
622          fail("Expected IllegalArgumentException for null description");
623
624       caught = false;
625       try
626       {
627          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
628             "name", "", SimpleType.INTEGER, true, true, false);
629       }
630       catch (IllegalArgumentException e)
631       {
632          caught = true;
633       }
634       if (caught == false)
635          fail("Expected IllegalArgumentException for an empty description");
636
637       caught = false;
638       try
639       {
640          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
641             "", "description", SimpleType.INTEGER, true, true, false);
642       }
643       catch (IllegalArgumentException e)
644       {
645          caught = true;
646       }
647       if (caught == false)
648          fail("Expected IllegalArgumentException for an empty name");
649
650       caught = false;
651       try
652       {
653          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
654             "name", "description", null, true, true, false);
655       }
656       catch (IllegalArgumentException e)
657       {
658          caught = true;
659       }
660       if (caught == false)
661          fail("Expected IllegalArgumentException for null simple type");
662    }
663
664    public void testErrors2()
665       throws Exception
666    {
667       boolean caught = false;
668       try
669       {
670          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
671             null, "description", SimpleType.INTEGER, true, true, false, new Integer(3));
672       }
673       catch (IllegalArgumentException e)
674       {
675          caught = true;
676       }
677       if (caught == false)
678          fail("Expected IllegalArgumentException for null name");
679
680       caught = false;
681       try
682       {
683          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
684             "", "description", SimpleType.INTEGER, true, true, false, new Integer(3));
685       }
686       catch (IllegalArgumentException e)
687       {
688          caught = true;
689       }
690       if (caught == false)
691          fail("Expected IllegalArgumentException for an empty name");
692
693       caught = false;
694       try
695       {
696          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
697             "name", null, SimpleType.INTEGER, true, true, false, new Integer(3));
698       }
699       catch (IllegalArgumentException e)
700       {
701          caught = true;
702       }
703       if (caught == false)
704          fail("Expected IllegalArgumentException for null description");
705
706       caught = false;
707       try
708       {
709          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
710             "name", "", SimpleType.INTEGER, true, true, false, new Integer(3));
711       }
712       catch (IllegalArgumentException e)
713       {
714          caught = true;
715       }
716       if (caught == false)
717          fail("Expected IllegalArgumentException for an empty description");
718
719       caught = false;
720       try
721       {
722          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
723             "", "description", SimpleType.INTEGER, true, true, false, new Integer(3));
724       }
725       catch (IllegalArgumentException e)
726       {
727          caught = true;
728       }
729       if (caught == false)
730          fail("Expected IllegalArgumentException for an empty name");
731
732       caught = false;
733       try
734       {
735          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
736             "name", "description", null, true, true, false, new Integer(3));
737       }
738       catch (IllegalArgumentException e)
739       {
740          caught = true;
741       }
742       if (caught == false)
743          fail("Expected IllegalArgumentException for null simple type");
744
745       caught = false;
746       try
747       {
748          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
749             "name", "description", SimpleType.STRING, true, true, false, new Integer(3));
750       }
751       catch (OpenDataException e)
752       {
753          caught = true;
754       }
755       if (caught == false)
756          fail("Expected OpenDataException for wrong simple type and default value");
757
758       caught = false;
759       try
760       {
761          ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
762          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
763             "name", "description", arrayType, true, true, false, new String[0]);
764       }
765       catch (OpenDataException e)
766       {
767          caught = true;
768       }
769       if (caught == false)
770          fail("Expected OpenDataException for array type and default value");
771
772       caught = false;
773       try
774       {
775          ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
776          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
777             "name", "description", arrayType, true, true, false, null);
778       }
779       catch (OpenDataException e)
780       {
781          caught = true;
782       }
783       if (caught == true)
784          fail("Didn't execpt OpenDataException for array type and no default value");
785
786       caught = false;
787       try
788       {
789          String[] itemNames = new String[] { "name1", "name2" };
790          String[] itemDescriptions = new String[] { "desc1", "desc2" };
791          OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
792          CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
793             itemNames, itemDescriptions, itemTypes);
794
795          String[] indexNames = new String[] { "name1", "name2" };
796          TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
797          TabularDataSupport data = new TabularDataSupport(tabularType);
798
799          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
800             "name", "description", tabularType, true, true, false, data);
801       }
802       catch (OpenDataException e)
803       {
804          caught = true;
805       }
806       if (caught == false)
807          fail("Expected OpenDataException for tabular type and default value");
808
809       caught = false;
810       try
811       {
812          String[] itemNames = new String[] { "name1", "name2" };
813          String[] itemDescriptions = new String[] { "desc1", "desc2" };
814          OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
815          CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
816             itemNames, itemDescriptions, itemTypes);
817
818          String[] indexNames = new String[] { "name1", "name2" };
819          TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
820
821          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
822             "name", "description", tabularType, true, true, false, null);
823       }
824       catch (OpenDataException e)
825       {
826          caught = true;
827       }
828       if (caught == true)
829          fail("Didn't execpt OpenDataException for tabular type and null default value");
830    }
831
832    public void testErrors3()
833       throws Exception
834    {
835       boolean caught = false;
836       try
837       {
838          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
839             null, "description", SimpleType.INTEGER, true, true, false,
840             new Integer(3), new Integer[] { new Integer(3), new Integer(4) });
841       }
842       catch (IllegalArgumentException e)
843       {
844          caught = true;
845       }
846       if (caught == false)
847          fail("Expected IllegalArgumentException for null name");
848
849       caught = false;
850       try
851       {
852          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
853             "", "description", SimpleType.INTEGER, true, true, false,
854             new Integer(3), new Integer[] { new Integer(3), new Integer(4) });
855       }
856       catch (IllegalArgumentException e)
857       {
858          caught = true;
859       }
860       if (caught == false)
861          fail("Expected IllegalArgumentException for an empty name");
862
863       caught = false;
864       try
865       {
866          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
867             "name", null, SimpleType.INTEGER, true, true, false,
868             new Integer(3), new Integer[] { new Integer(3), new Integer(4) });
869       }
870       catch (IllegalArgumentException e)
871       {
872          caught = true;
873       }
874       if (caught == false)
875          fail("Expected IllegalArgumentException for null description");
876
877       caught = false;
878       try
879       {
880          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
881             "name", "", SimpleType.INTEGER, true, true, false, new Integer(3),
882             new Integer[] { new Integer(3), new Integer(4) });
883       }
884       catch (IllegalArgumentException e)
885       {
886          caught = true;
887       }
888       if (caught == false)
889          fail("Expected IllegalArgumentException for an empty description");
890
891       caught = false;
892       try
893       {
894          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
895             "", "description", SimpleType.INTEGER, true, true, false,
896             new Integer(3), new Integer[] { new Integer(3), new Integer(4) });
897       }
898       catch (IllegalArgumentException e)
899       {
900          caught = true;
901       }
902       if (caught == false)
903          fail("Expected IllegalArgumentException for an empty name");
904
905       caught = false;
906       try
907       {
908          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
909             "name", "description", null, true, true, false,
910             new Integer(3), new Integer[] { new Integer(3), new Integer(4) });
911       }
912       catch (IllegalArgumentException e)
913       {
914          caught = true;
915       }
916       if (caught == false)
917          fail("Expected IllegalArgumentException for null simple type");
918
919       caught = false;
920       try
921       {
922          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
923             "name", "description", SimpleType.STRING, true, true, false,
924             new Integer(3), new Integer[] { new Integer(3), new Integer(4) });
925       }
926       catch (OpenDataException e)
927       {
928          caught = true;
929       }
930       if (caught == false)
931          fail("Expected OpenDataException for wrong simple type and default value");
932
933       caught = false;
934       try
935       {
936          ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
937          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
938             "name", "description", arrayType, true, true, false, new String[0], null);
939       }
940       catch (OpenDataException e)
941       {
942          caught = true;
943       }
944       if (caught == false)
945          fail("Expected OpenDataException for array type and default value");
946
947       caught = false;
948       try
949       {
950          ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
951          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
952             "name", "description", arrayType, true, true, false, null, null);
953       }
954       catch (OpenDataException e)
955       {
956          caught = true;
957       }
958       if (caught == true)
959          fail("Didn't expect OpenDataException for array type and no default value and legals");
960
961       caught = false;
962       try
963       {
964          String[] itemNames = new String[] { "name1", "name2" };
965          String[] itemDescriptions = new String[] { "desc1", "desc2" };
966          OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
967          CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
968             itemNames, itemDescriptions, itemTypes);
969
970          String[] indexNames = new String[] { "name1", "name2" };
971          TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
972          TabularDataSupport data = new TabularDataSupport(tabularType);
973
974          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
975             "name", "description", tabularType, true, true, false, data, null);
976       }
977       catch (OpenDataException e)
978       {
979          caught = true;
980       }
981       if (caught == false)
982          fail("Expected OpenDataException for tabular type and default value");
983
984       caught = false;
985       try
986       {
987          String[] itemNames = new String[] { "name1", "name2" };
988          String[] itemDescriptions = new String[] { "desc1", "desc2" };
989          OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
990          CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
991             itemNames, itemDescriptions, itemTypes);
992
993          String[] indexNames = new String[] { "name1", "name2" };
994          TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
995
996          OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
997             "name", "description", tabularType, true, true, false, null, null);
998       }
999       catch (OpenDataException e)
1000      {
1001         caught = true;
1002      }
1003      if (caught == true)
1004         fail("Didn't expect OpenDataException for tabular type and null default value and legals");
1005
1006      caught = false;
1007      try
1008      {
1009         ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1010         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1011            "name", "description", arrayType, true, true, false, null, new String[] { "hello", "goodbye" });
1012      }
1013      catch (OpenDataException e)
1014      {
1015         caught = true;
1016      }
1017      if (caught == false)
1018         fail("Expected OpenDataException for array type and default value");
1019
1020      caught = false;
1021      try
1022      {
1023         ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1024         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1025            "name", "description", arrayType, true, true, false, null, new String[0]);
1026      }
1027      catch (OpenDataException e)
1028      {
1029         caught = true;
1030      }
1031      if (caught == true)
1032         fail("Didn't expect OpenDataException for array type and no default value and empty legals");
1033
1034      caught = false;
1035      try
1036      {
1037         String[] itemNames = new String[] { "name1", "name2" };
1038         String[] itemDescriptions = new String[] { "desc1", "desc2" };
1039         OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
1040         CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
1041            itemNames, itemDescriptions, itemTypes);
1042
1043         String[] indexNames = new String[] { "name1", "name2" };
1044         TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
1045         TabularDataSupport data = new TabularDataSupport(tabularType);
1046
1047         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1048            "name", "description", tabularType, true, true, false, null, new TabularDataSupport[] { data });
1049      }
1050      catch (OpenDataException e)
1051      {
1052         caught = true;
1053      }
1054      if (caught == false)
1055         fail("Expected OpenDataException for tabular type and legal values");
1056
1057      caught = false;
1058      try
1059      {
1060         String[] itemNames = new String[] { "name1", "name2" };
1061         String[] itemDescriptions = new String[] { "desc1", "desc2" };
1062         OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
1063         CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
1064            itemNames, itemDescriptions, itemTypes);
1065
1066         String[] indexNames = new String[] { "name1", "name2" };
1067         TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
1068
1069         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1070            "name", "description", tabularType, true, true, false, null, new TabularDataSupport[0]);
1071      }
1072      catch (OpenDataException e)
1073      {
1074         caught = true;
1075      }
1076      if (caught == true)
1077         fail("Didn't expect OpenDataException for tabular type and null default value and empty legals");
1078
1079      caught = false;
1080      try
1081      {
1082         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1083            "name", "description", SimpleType.STRING, true, true, false,
1084            new Integer(3), new Integer[] { new Integer(2), new Integer(4) });
1085      }
1086      catch (OpenDataException e)
1087      {
1088         caught = true;
1089      }
1090      if (caught == false)
1091         fail("Expected OpenDataException for default value not a legal value");
1092   }
1093
1094   public void testErrors4()
1095      throws Exception
1096   {
1097      boolean caught = false;
1098      try
1099      {
1100         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1101            null, "description", SimpleType.INTEGER, true, true, false,
1102            new Integer(3), new Integer(3), new Integer(4));
1103      }
1104      catch (IllegalArgumentException e)
1105      {
1106         caught = true;
1107      }
1108      if (caught == false)
1109         fail("Expected IllegalArgumentException for null name");
1110
1111      caught = false;
1112      try
1113      {
1114         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1115            "", "description", SimpleType.INTEGER, true, true, false,
1116            new Integer(3), new Integer(3), new Integer(4));
1117      }
1118      catch (IllegalArgumentException e)
1119      {
1120         caught = true;
1121      }
1122      if (caught == false)
1123         fail("Expected IllegalArgumentException for an empty name");
1124
1125      caught = false;
1126      try
1127      {
1128         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1129            "name", null, SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(3), new Integer(4));
1130      }
1131      catch (IllegalArgumentException e)
1132      {
1133         caught = true;
1134      }
1135      if (caught == false)
1136         fail("Expected IllegalArgumentException for null description");
1137
1138      caught = false;
1139      try
1140      {
1141         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1142            "name", "", SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(3), new Integer(4));
1143      }
1144      catch (IllegalArgumentException e)
1145      {
1146         caught = true;
1147      }
1148      if (caught == false)
1149         fail("Expected IllegalArgumentException for an empty description");
1150
1151      caught = false;
1152      try
1153      {
1154         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1155            "", "description", SimpleType.INTEGER, true, true, false, new Integer(3), new Integer(3), new Integer(4));
1156      }
1157      catch (IllegalArgumentException e)
1158      {
1159         caught = true;
1160      }
1161      if (caught == false)
1162         fail("Expected IllegalArgumentException for an empty name");
1163
1164      caught = false;
1165      try
1166      {
1167         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1168            "name", "description", null, true, true, false, new Integer(3), new Integer(3), new Integer(4));
1169      }
1170      catch (IllegalArgumentException e)
1171      {
1172         caught = true;
1173      }
1174      if (caught == false)
1175         fail("Expected IllegalArgumentException for null simple type");
1176
1177      caught = false;
1178      try
1179      {
1180         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1181            "name", "description", SimpleType.STRING, true, true, false, new Integer(3), null, null);
1182      }
1183      catch (OpenDataException e)
1184      {
1185         caught = true;
1186      }
1187      if (caught == false)
1188         fail("Expected OpenDataException for wrong simple type and default value");
1189
1190      caught = false;
1191      try
1192      {
1193         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1194            "name", "description", SimpleType.STRING, true, true, false, null, new Integer(3), null);
1195      }
1196      catch (OpenDataException e)
1197      {
1198         caught = true;
1199      }
1200      if (caught == false)
1201         fail("Expected OpenDataException for wrong simple type and minimum value");
1202
1203      caught = false;
1204      try
1205      {
1206         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1207            "name", "description", SimpleType.STRING, true, true, false, null, null, new Integer(3));
1208      }
1209      catch (OpenDataException e)
1210      {
1211         caught = true;
1212      }
1213      if (caught == false)
1214         fail("Expected OpenDataException for wrong simple type and maximum value");
1215
1216      caught = false;
1217      try
1218      {
1219         ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1220         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1221            "name", "description", arrayType, true, true, false, new String[0], null, null);
1222      }
1223      catch (OpenDataException e)
1224      {
1225         caught = true;
1226      }
1227      if (caught == false)
1228         fail("Expected OpenDataException for array type and default value");
1229
1230      caught = false;
1231      try
1232      {
1233         ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1234         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1235            "name", "description", arrayType, true, true, false, null, null, null);
1236      }
1237      catch (OpenDataException e)
1238      {
1239         caught = true;
1240      }
1241      if (caught == true)
1242         fail("Didn't expect OpenDataException for array type and no default value");
1243
1244      caught = false;
1245      try
1246      {
1247         String[] itemNames = new String[] { "name1", "name2" };
1248         String[] itemDescriptions = new String[] { "desc1", "desc2" };
1249         OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
1250         CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
1251            itemNames, itemDescriptions, itemTypes);
1252
1253         String[] indexNames = new String[] { "name1", "name2" };
1254         TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
1255         TabularDataSupport data = new TabularDataSupport(tabularType);
1256
1257         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1258            "name", "description", tabularType, true, true, false, data, null, null);
1259      }
1260      catch (OpenDataException e)
1261      {
1262         caught = true;
1263      }
1264      if (caught == false)
1265         fail("Expected OpenDataException for tabular type and default value");
1266
1267      caught = false;
1268      try
1269      {
1270         String[] itemNames = new String[] { "name1", "name2" };
1271         String[] itemDescriptions = new String[] { "desc1", "desc2" };
1272         OpenType[] itemTypes = new OpenType[] { SimpleType.STRING, SimpleType.INTEGER };
1273         CompositeType rowType = new CompositeType("rowTypeName", "rowDescription",
1274            itemNames, itemDescriptions, itemTypes);
1275
1276         String[] indexNames = new String[] { "name1", "name2" };
1277         TabularType tabularType = new TabularType("typeName", "description", rowType, indexNames);
1278
1279         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1280            "name", "description", tabularType, true, true, false, null, null, null);
1281      }
1282      catch (OpenDataException e)
1283      {
1284         caught = true;
1285      }
1286      if (caught == true)
1287         fail("Didn't expect OpenDataException for tabular type and null default value");
1288
1289      caught = false;
1290      try
1291      {
1292         ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1293         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1294            "name", "description", arrayType, true, true, false, new String[] { "hello", "goodbye" }, null, null);
1295      }
1296      catch (OpenDataException e)
1297      {
1298         caught = true;
1299      }
1300      if (caught == false)
1301         fail("Expected OpenDataException for array type and default value");
1302
1303      caught = false;
1304      try
1305      {
1306         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1307            "name", "description", SimpleType.STRING, true, true, false,
1308            new Integer(3), new Integer(4), new Integer(5));
1309      }
1310      catch (OpenDataException e)
1311      {
1312         caught = true;
1313      }
1314      if (caught == false)
1315         fail("Expected OpenDataException for default value less than minimum value");
1316
1317      caught = false;
1318      try
1319      {
1320         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1321            "name", "description", SimpleType.INTEGER, true, true, false,
1322            new Integer(4), new Integer(4), new Integer(5));
1323      }
1324      catch (OpenDataException e)
1325      {
1326         caught = true;
1327      }
1328      if (caught == true)
1329         fail("Didn't expect OpenDataException for default value equal minimum value");
1330
1331      caught = false;
1332      try
1333      {
1334         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1335            "name", "description", SimpleType.INTEGER, true, true, false,
1336            new Integer(6), new Integer(4), new Integer(5));
1337      }
1338      catch (OpenDataException e)
1339      {
1340         caught = true;
1341      }
1342      if (caught == false)
1343         fail("Expected OpenDataException for default value greater than maximum value");
1344
1345      caught = false;
1346      try
1347      {
1348         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1349            "name", "description", SimpleType.INTEGER, true, true, false,
1350            new Integer(5), new Integer(4), new Integer(5));
1351      }
1352      catch (OpenDataException e)
1353      {
1354         caught = true;
1355      }
1356      if (caught == true)
1357         fail("Didn't expect OpenDataException for default value equal maximum value");
1358
1359      caught = false;
1360      try
1361      {
1362         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1363            "name", "description", SimpleType.INTEGER, true, true, false,
1364            null, new Integer(4), new Integer(3));
1365      }
1366      catch (OpenDataException e)
1367      {
1368         caught = true;
1369      }
1370      if (caught == false)
1371         fail("Expected OpenDataException for minimum greater than maximum value");
1372
1373      caught = false;
1374      try
1375      {
1376         OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1377            "name", "description", SimpleType.INTEGER, true, true, false,
1378            null, new Integer(4), new Integer(4));
1379      }
1380      catch (OpenDataException e)
1381      {
1382         caught = true;
1383      }
1384      if (caught == true)
1385         fail("Didn't expect OpenDataException for minimum equal maximum value");
1386   }
1387}
1388
Popular Tags