KickJava   Java API By Example, From Geeks To Geeks.

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


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.OpenMBeanParameterInfoSupport;
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 Parameter Info tests.<p>
28  *
29  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
30  */

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

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

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

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

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

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