KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > serialization > SerializeTestCase


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.serialization;
9
10 import java.io.ByteArrayInputStream;
11 import java.io.ByteArrayOutputStream;
12 import java.io.IOException;
13 import java.io.ObjectInputStream;
14 import java.io.ObjectOutputStream;
15 import java.lang.reflect.Array;
16 import java.lang.reflect.Constructor;
17 import java.lang.reflect.Method;
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import junit.framework.TestCase;
22
23 /**
24  * Tests serialization with the RI
25  *
26  * @todo Proper equality tests instead of toString()
27  *
28  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
29  */

30 public class SerializeTestCase
31    extends TestCase
32 {
33    // Attributes ----------------------------------------------------------------
34

35    // Constructor ---------------------------------------------------------------
36

37    /**
38     * Construct the test
39     */

40    public SerializeTestCase(String s)
41    {
42       super(s);
43    }
44
45    public void testArrayType()
46       throws Exception
47    {
48       if (SerializationSUITE.form < 11)
49          return;
50       Class clazz = loadClass("javax.management.openmbean.SimpleType");
51       Object elementType = clazz.getField("BIGDECIMAL").get(null);
52       Object obj = instantiate(
53          "javax.management.openmbean.ArrayType",
54          new Class[] { Integer.TYPE,
55                        loadClass("javax.management.openmbean.OpenType") },
56          new Object[] { new Integer(3), elementType }
57       );
58       Object result = runTest(obj);
59       assertEquals(obj, result);
60    }
61
62    public void testAttribute()
63       throws Exception
64    {
65       Object obj = instantiate(
66          "javax.management.Attribute",
67          new Class[] { String.class, Object.class },
68          new Object[] { "name", "value" }
69       );
70       Object result = runTest(obj);
71       assertEquals(obj, result);
72    }
73
74    public void testAttributeChangeNotification()
75       throws Exception
76    {
77       Object obj = instantiate(
78          "javax.management.AttributeChangeNotification",
79          new Class[] { Object.class, Long.TYPE, Long.TYPE,
80                        String.class, String.class, String.class,
81                        Object.class, Object.class },
82          new Object[] { "source", new Long(1), new Long(2), "message", "name",
83                         "type", "old", "new" }
84       );
85       Object result = runTest(obj);
86       assertEquals(obj.toString(), result.toString());
87    }
88
89    public void testAttributeChangeNotificationFilter()
90       throws Exception
91    {
92       Object obj = instantiate(
93          "javax.management.AttributeChangeNotificationFilter",
94          new Class[0],
95          new Object[0]
96       );
97       Method method = obj.getClass().getMethod("enableAttribute",
98           new Class[] { String.class });
99       method.invoke(obj, new Object[] { "attribute" });
100       Object result = runTest(obj);
101       assertEquals(obj.toString(), result.toString());
102    }
103
104    public void testAttributeList()
105       throws Exception
106    {
107       Object obj = instantiate(
108          "javax.management.AttributeList",
109          new Class[0],
110          new Object[0]
111       );
112       Object attr = instantiate(
113          "javax.management.Attribute",
114          new Class[] { String.class, Object.class },
115          new Object[] { "name", "value" }
116       );
117       Method method = obj.getClass().getMethod("add",
118           new Class[] { attr.getClass() });
119       method.invoke(obj, new Object[] { attr });
120       Object result = runTest(obj);
121       assertEquals(obj.toString(), result.toString());
122    }
123
124    public void testAttributeNotFoundException()
125       throws Exception
126    {
127       Object obj = instantiate(
128          "javax.management.AttributeNotFoundException",
129          new Class[] { String.class },
130          new Object[] { "message" }
131       );
132       Object result = runTest(obj);
133       assertEquals(obj.toString(), result.toString());
134    }
135
136    public void testAttributeValueExp()
137       throws Exception
138    {
139       Object obj = instantiate(
140          "javax.management.AttributeValueExp",
141          new Class[] { String.class },
142          new Object[] { "attr" }
143       );
144       Object result = runTest(obj);
145       assertEquals(obj.toString(), result.toString());
146    }
147
148    public void testBadAttributeValueExpException()
149       throws Exception
150    {
151       Object obj = instantiate(
152          "javax.management.BadAttributeValueExpException",
153          new Class[] { Object.class },
154          new Object[] { "value" }
155       );
156       Object result = runTest(obj);
157       assertEquals(obj.toString(), result.toString());
158    }
159
160    public void testBadBinaryOpValueExpException()
161       throws Exception
162    {
163       Object exp = instantiate(
164          "javax.management.AttributeValueExp",
165          new Class[] { String.class },
166          new Object[] { "attr" }
167       );
168
169       Object obj = instantiate(
170          "javax.management.BadBinaryOpValueExpException",
171          new Class[] { loadClass("javax.management.ValueExp") },
172          new Object[] { exp }
173       );
174       Object result = runTest(obj);
175       assertEquals(obj.toString(), result.toString());
176    }
177
178    public void testBadStringOperationException()
179       throws Exception
180    {
181       Object obj = instantiate(
182          "javax.management.BadStringOperationException",
183          new Class[] { String.class },
184          new Object[] { "message" }
185       );
186       Object result = runTest(obj);
187       assertEquals(obj.toString(), result.toString());
188    }
189
190    public void testCompositeDataSupport()
191       throws Exception
192    {
193       if (SerializationSUITE.form < 11)
194          return;
195       Class clazz = loadClass("javax.management.openmbean.SimpleType");
196       Object openType = clazz.getField("STRING").get(null);
197
198       Class elementClass = loadClass("javax.management.openmbean.OpenType");
199       Object array = Array.newInstance(elementClass, 2);
200       Array.set(array, 0, openType);
201       Array.set(array, 1, openType);
202
203       Object compositeType = instantiate(
204          "javax.management.openmbean.CompositeType",
205          new Class[] { String.class, String.class, String[].class, String[].class, array.getClass() },
206          new Object[] { "typeName", "description", new String[] { "name1", "name2" },
207             new String[] { "desc1", "desc2" }, array }
208       );
209       Object obj = instantiate(
210          "javax.management.openmbean.CompositeDataSupport",
211          new Class[] { compositeType.getClass(), String[].class, Object[].class },
212          new Object[] { compositeType, new String[] { "name1", "name2" },
213             new Object[] { "itemValue1", "itemValue2" } }
214       );
215       Object result = runTest(obj);
216       assertEquals(obj, result);
217    }
218
219    public void testCompositeType()
220       throws Exception
221    {
222       if (SerializationSUITE.form < 11)
223          return;
224       Class clazz = loadClass("javax.management.openmbean.SimpleType");
225       Object openType = clazz.getField("STRING").get(null);
226
227       Class elementClass = loadClass("javax.management.openmbean.OpenType");
228       Object array = Array.newInstance(elementClass, 2);
229       Array.set(array, 0, openType);
230       Array.set(array, 1, openType);
231
232       Object obj = instantiate(
233          "javax.management.openmbean.CompositeType",
234          new Class[] { String.class, String.class, String[].class, String[].class, array.getClass() },
235          new Object[] { "typeName", "description", new String[] { "name1", "name2" },
236             new String[] { "desc1", "desc2" }, array }
237       );
238       Object result = runTest(obj);
239       assertEquals(obj, result);
240    }
241
242    public void testDescriptorSupport()
243       throws Exception
244    {
245       Object obj = instantiate(
246          "javax.management.modelmbean.DescriptorSupport",
247          new Class[] { new String[0].getClass(), new Object[0].getClass() },
248          new Object[] { new String[] { "name1", "name2"},
249                         new Object[] { "value1", "value2" } }
250       );
251       Object result = runTest(obj);
252       assertEquals(obj.toString(), result.toString());
253    }
254
255    public void testInstanceAlreadyExistsException()
256       throws Exception
257    {
258       Object obj = instantiate(
259          "javax.management.InstanceAlreadyExistsException",
260          new Class[] { String.class },
261          new Object[] { "message" }
262       );
263       Object result = runTest(obj);
264       assertEquals(obj.toString(), result.toString());
265    }
266
267    public void testInstanceNotFoundException()
268       throws Exception
269    {
270       Object obj = instantiate(
271          "javax.management.InstanceNotFoundException",
272          new Class[] { String.class },
273          new Object[] { "message" }
274       );
275       Object result = runTest(obj);
276       assertEquals(obj.toString(), result.toString());
277    }
278
279    public void testIntrospectionException()
280       throws Exception
281    {
282       Object obj = instantiate(
283          "javax.management.IntrospectionException",
284          new Class[] { String.class },
285          new Object[] { "message" }
286       );
287       Object result = runTest(obj);
288       assertEquals(obj.toString(), result.toString());
289    }
290
291    public void testInvalidApplicationException()
292       throws Exception
293    {
294       Object obj = instantiate(
295          "javax.management.InvalidApplicationException",
296          new Class[] { Object.class },
297          new Object[] { "value" }
298       );
299       Object result = runTest(obj);
300       assertEquals(obj.toString(), result.toString());
301    }
302
303    public void testInvalidAttributeValueException()
304       throws Exception
305    {
306       Object obj = instantiate(
307          "javax.management.InvalidAttributeValueException",
308          new Class[] { String.class },
309          new Object[] { "message" }
310       );
311       Object result = runTest(obj);
312       assertEquals(obj.toString(), result.toString());
313    }
314
315    public void testInvalidKeyException()
316       throws Exception
317    {
318       if (SerializationSUITE.form < 11)
319          return;
320       Object obj = instantiate(
321          "javax.management.openmbean.InvalidKeyException",
322          new Class[] { String.class },
323          new Object[] { "message" }
324       );
325       Object result = runTest(obj);
326       assertEquals(obj.toString(), result.toString());
327    }
328
329    public void testInvalidOpenTypeException()
330       throws Exception
331    {
332       if (SerializationSUITE.form < 11)
333          return;
334       Object obj = instantiate(
335          "javax.management.openmbean.InvalidOpenTypeException",
336          new Class[] { String.class },
337          new Object[] { "message" }
338       );
339       Object result = runTest(obj);
340       assertEquals(obj.toString(), result.toString());
341    }
342
343    public void testInvalidRelationIdException()
344       throws Exception
345    {
346       Object obj = instantiate(
347          "javax.management.relation.InvalidRelationIdException",
348          new Class[] { String.class },
349          new Object[] { "message" }
350       );
351       Object result = runTest(obj);
352       assertEquals(obj.toString(), result.toString());
353    }
354
355    public void testInvalidRelationServiceException()
356       throws Exception
357    {
358       Object obj = instantiate(
359          "javax.management.relation.InvalidRelationServiceException",
360          new Class[] { String.class },
361          new Object[] { "message" }
362       );
363       Object result = runTest(obj);
364       assertEquals(obj.toString(), result.toString());
365    }
366
367    public void testInvalidRelationTypeException()
368       throws Exception
369    {
370       Object obj = instantiate(
371          "javax.management.relation.InvalidRelationTypeException",
372          new Class[] { String.class },
373          new Object[] { "message" }
374       );
375       Object result = runTest(obj);
376       assertEquals(obj.toString(), result.toString());
377    }
378
379    public void testInvalidRoleInfoException()
380       throws Exception
381    {
382       Object obj = instantiate(
383          "javax.management.relation.InvalidRoleInfoException",
384          new Class[] { String.class },
385          new Object[] { "message" }
386       );
387       Object result = runTest(obj);
388       assertEquals(obj.toString(), result.toString());
389    }
390
391    public void testInvalidRoleValueException()
392       throws Exception
393    {
394       Object obj = instantiate(
395          "javax.management.relation.InvalidRoleValueException",
396          new Class[] { String.class },
397          new Object[] { "message" }
398       );
399       Object result = runTest(obj);
400       assertEquals(obj.toString(), result.toString());
401    }
402
403    public void testInvalidTargetObjectTypeException()
404       throws Exception
405    {
406       Object obj = instantiate(
407          "javax.management.modelmbean.InvalidTargetObjectTypeException",
408          new Class[] { Exception.class, String.class },
409          new Object[] { new Exception("exception"), "message" }
410       );
411       Object result = runTest(obj);
412       assertEquals(obj.toString(), result.toString());
413    }
414
415    public void testKeyAlreadyExistsException()
416       throws Exception
417    {
418       if (SerializationSUITE.form < 11)
419          return;
420       Object obj = instantiate(
421          "javax.management.openmbean.KeyAlreadyExistsException",
422          new Class[] { String.class },
423          new Object[] { "message" }
424       );
425       Object result = runTest(obj);
426       assertEquals(obj.toString(), result.toString());
427    }
428
429    public void testJMException()
430       throws Exception
431    {
432       Object obj = instantiate(
433          "javax.management.JMException",
434          new Class[] { String.class },
435          new Object[] { "message" }
436       );
437       Object result = runTest(obj);
438       assertEquals(obj.toString(), result.toString());
439    }
440
441    public void testJMRuntimeException()
442       throws Exception
443    {
444       Object obj = instantiate(
445          "javax.management.JMRuntimeException",
446          new Class[] { String.class },
447          new Object[] { "message" }
448       );
449       Object result = runTest(obj);
450       assertEquals(obj.toString(), result.toString());
451    }
452
453    public void testListenerNotFoundException()
454       throws Exception
455    {
456       Object obj = instantiate(
457          "javax.management.ListenerNotFoundException",
458          new Class[] { String.class },
459          new Object[] { "message" }
460       );
461       Object result = runTest(obj);
462       assertEquals(obj.toString(), result.toString());
463    }
464
465    public void testMalformedObjectNameException()
466       throws Exception
467    {
468       Object obj = instantiate(
469          "javax.management.MalformedObjectNameException",
470          new Class[] { String.class },
471          new Object[] { "message" }
472       );
473       Object result = runTest(obj);
474       assertEquals(obj.toString(), result.toString());
475    }
476
477    public void testMBeanAttributeInfo()
478       throws Exception
479    {
480       Object obj = instantiate(
481          "javax.management.MBeanAttributeInfo",
482          new Class[] { String.class, String.class, String.class,
483                        Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
484          new Object[] { "name", "type", "description", new Boolean(true),
485                         new Boolean(true), new Boolean(false)}
486       );
487       try
488       {
489          Object result = runTest(obj);
490          assertEquals(obj.toString(), result.toString());
491       }
492       catch (java.io.InvalidClassException e)
493       {
494          fail("FAILS IN RI 1.1: Wrong serialization for form 1.0");
495       }
496    }
497
498    public void testMBeanConstructorInfo()
499       throws Exception
500    {
501       Object parm = instantiate(
502          "javax.management.MBeanParameterInfo",
503          new Class[] { String.class, String.class, String.class },
504          new Object[] { "name", "type", "description" }
505       );
506       Object array = Array.newInstance(parm.getClass(), 1);
507       Array.set(array, 0, parm);
508       Object obj = instantiate(
509          "javax.management.MBeanConstructorInfo",
510          new Class[] { String.class, String.class, array.getClass() },
511          new Object[] { "name", "description", array }
512       );
513       Object result = runTest(obj);
514       assertEquals(obj.toString(), result.toString());
515    }
516
517    public void testMBeanException()
518       throws Exception
519    {
520       Object obj = instantiate(
521          "javax.management.MBeanException",
522          new Class[] { Exception.class, String.class },
523          new Object[] { new Exception("Cause"), "message" }
524       );
525       Object result = runTest(obj);
526       assertEquals(obj.toString(), result.toString());
527    }
528
529    public void testMBeanFeatureInfo()
530       throws Exception
531    {
532       Object obj = instantiate(
533          "javax.management.MBeanFeatureInfo",
534          new Class[] { String.class, String.class },
535          new Object[] { "name", "description" }
536       );
537       Object result = runTest(obj);
538       assertEquals(obj.toString(), result.toString());
539    }
540
541    public void testMBeanInfo()
542       throws Exception
543    {
544       Object parm = instantiate(
545          "javax.management.MBeanParameterInfo",
546          new Class[] { String.class, String.class, String.class },
547          new Object[] { "name", "type", "description" }
548       );
549       Object parms = Array.newInstance(parm.getClass(), 1);
550       Array.set(parms, 0, parm);
551
552       Object att = instantiate(
553          "javax.management.MBeanAttributeInfo",
554          new Class[] { String.class, String.class, String.class,
555                        Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
556          new Object[] { "name", "type", "description", new Boolean(true),
557                         new Boolean(true), new Boolean(false)}
558       );
559       Object atts = Array.newInstance(att.getClass(), 1);
560       Array.set(atts, 0, att);
561
562       Object con = instantiate(
563          "javax.management.MBeanConstructorInfo",
564          new Class[] { String.class, String.class, parms.getClass() },
565          new Object[] { "name", "description", parms }
566       );
567       Object cons = Array.newInstance(con.getClass(), 1);
568       Array.set(cons, 0, con);
569
570       Class clazz = loadClass("javax.management.MBeanOperationInfo");
571       Integer impact = new Integer(clazz.getField("ACTION").getInt(null));
572       Object op = instantiate(
573          "javax.management.MBeanOperationInfo",
574          new Class[] { String.class, String.class, parms.getClass(),
575                        String.class, Integer.TYPE },
576          new Object[] { "name", "description", parms, "type", impact }
577       );
578       Object ops = Array.newInstance(op.getClass(), 1);
579       Array.set(ops, 0, op);
580
581       String[] types = { "type1", "type2" };
582       Object not = instantiate(
583          "javax.management.MBeanNotificationInfo",
584          new Class[] { types.getClass(), String.class, String.class },
585          new Object[] { types, "name", "description" }
586       );
587       Object nots = Array.newInstance(not.getClass(), 1);
588       Array.set(nots, 0, not);
589
590       Object obj = instantiate(
591          "javax.management.MBeanInfo",
592          new Class[] { String.class, String.class, atts.getClass(),
593                        cons.getClass(), ops.getClass(), nots.getClass() },
594          new Object[] { "className", "description", atts, cons, ops, nots }
595       );
596       try
597       {
598          Object result = runTest(obj);
599          assertEquals(obj.toString(), result.toString());
600       }
601       catch (java.io.InvalidClassException e)
602       {
603          fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 " +
604               "The real error is in MBeanAttributeInfo");
605       }
606    }
607
608    public void testMBeanNotificationInfo()
609       throws Exception
610    {
611       String[] types = { "type1", "type2" };
612       Object obj = instantiate(
613          "javax.management.MBeanNotificationInfo",
614          new Class[] { types.getClass(), String.class, String.class },
615          new Object[] { types, "name", "description" }
616       );
617       Object result = runTest(obj);
618       assertEquals(obj.toString(), result.toString());
619    }
620
621    public void testMBeanOperationInfo()
622       throws Exception
623    {
624       Object parm = instantiate(
625          "javax.management.MBeanParameterInfo",
626          new Class[] { String.class, String.class, String.class },
627          new Object[] { "name", "type", "description" }
628       );
629       Object array = Array.newInstance(parm.getClass(), 1);
630       Array.set(array, 0, parm);
631       Class clazz = loadClass("javax.management.MBeanOperationInfo");
632       Integer impact = new Integer(clazz.getField("ACTION").getInt(null));
633       Object obj = instantiate(
634          "javax.management.MBeanOperationInfo",
635          new Class[] { String.class, String.class, array.getClass(),
636                        String.class, Integer.TYPE },
637          new Object[] { "name", "description", array, "type", impact }
638       );
639       Object result = runTest(obj);
640       assertEquals(obj.toString(), result.toString());
641    }
642
643    public void testMBeanParameterInfo()
644       throws Exception
645    {
646       Object obj = instantiate(
647          "javax.management.MBeanParameterInfo",
648          new Class[] { String.class, String.class, String.class },
649          new Object[] { "name", "type", "description" }
650       );
651       Object result = runTest(obj);
652       assertEquals(obj.toString(), result.toString());
653    }
654
655    public void testMBeanRegistrationException()
656       throws Exception
657    {
658       Object obj = instantiate(
659          "javax.management.MBeanRegistrationException",
660          new Class[] { Exception.class, String.class },
661          new Object[] { new Exception("Cause"), "message" }
662       );
663       Object result = runTest(obj);
664       assertEquals(obj.toString(), result.toString());
665    }
666
667    public void testMBeanServerNotification()
668       throws Exception
669    {
670       Object objectName = instantiate(
671          "javax.management.ObjectName",
672          new Class[] { String.class },
673          new Object[] { "domain:x=y" }
674       );
675
676       Class clazz = loadClass("javax.management.MBeanServerNotification");
677       String type = (String) clazz.getField("REGISTRATION_NOTIFICATION").get(null);
678
679       Object obj = instantiate(
680          "javax.management.MBeanServerNotification",
681          new Class[] { String.class, Object.class, Long.TYPE,
682                        objectName.getClass() },
683          new Object[] { type, "source", new Long(1), objectName }
684       );
685       Object result = runTest(obj);
686       assertEquals(obj.toString(), result.toString());
687    }
688
689    public void testMBeanServerNotificationFilter()
690       throws Exception
691    {
692       Object objectName = instantiate(
693          "javax.management.ObjectName",
694          new Class[] { String.class },
695          new Object[] { "domain:x=y" }
696       );
697       Object obj = instantiate(
698          "javax.management.relation.MBeanServerNotificationFilter",
699          new Class[0],
700          new Object[0]
701       );
702       Method method = obj.getClass().getMethod("enableType",
703           new Class[] { String.class });
704       method.invoke(obj, new Object[] { "prefix" });
705       method = obj.getClass().getMethod("enableObjectName",
706           new Class[] { objectName.getClass() });
707       method.invoke(obj, new Object[] { objectName });
708       Object result = runTest(obj);
709       assertEquals(obj.toString(), result.toString());
710    }
711
712    public void testMBeanServerPermission()
713       throws Exception
714    {
715       if (SerializationSUITE.form < 11)
716          return;
717       Object obj = instantiate(
718          "javax.management.MBeanServerPermission",
719          new Class[] { String.class },
720          new Object[] { "*" }
721       );
722       Object result = runTest(obj);
723       assertEquals(obj.toString(), result.toString());
724    }
725
726    public void testModelMBeanAttributeInfo()
727       throws Exception
728    {
729       Object obj = instantiate(
730          "javax.management.modelmbean.ModelMBeanAttributeInfo",
731          new Class[] { String.class, String.class, String.class,
732                        Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
733          new Object[] { "name", "type", "description", new Boolean(true),
734                         new Boolean(true), new Boolean(false)}
735       );
736       try
737       {
738          Object result = runTest(obj);
739          assertEquals(obj.toString(), result.toString());
740       }
741       catch (java.io.InvalidClassException e)
742       {
743          fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
744       }
745    }
746
747    /**
748     * @todo equals test
749     */

750    public void testModelMBeanConstructorInfo()
751       throws Exception
752    {
753       Object parm = instantiate(
754          "javax.management.MBeanParameterInfo",
755          new Class[] { String.class, String.class, String.class },
756          new Object[] { "name", "type", "description" }
757       );
758       Object array = Array.newInstance(parm.getClass(), 1);
759       Array.set(array, 0, parm);
760       Object obj = instantiate(
761          "javax.management.modelmbean.ModelMBeanConstructorInfo",
762          new Class[] { String.class, String.class, array.getClass() },
763          new Object[] { "name", "description", array }
764       );
765       Object result = runTest(obj);
766    }
767
768    /**
769     * @todo equals test
770     */

771    public void testModelMBeanInfoSupport()
772       throws Exception
773    {
774       Object parm = instantiate(
775          "javax.management.MBeanParameterInfo",
776          new Class[] { String.class, String.class, String.class },
777          new Object[] { "name", "type", "description" }
778       );
779       Object parms = Array.newInstance(parm.getClass(), 1);
780       Array.set(parms, 0, parm);
781
782       Object att = instantiate(
783          "javax.management.modelmbean.ModelMBeanAttributeInfo",
784          new Class[] { String.class, String.class, String.class,
785                        Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
786          new Object[] { "name", "type", "description", new Boolean(true),
787                         new Boolean(true), new Boolean(false)}
788       );
789       Object atts = Array.newInstance(att.getClass(), 1);
790       Array.set(atts, 0, att);
791
792       Object con = instantiate(
793          "javax.management.modelmbean.ModelMBeanConstructorInfo",
794          new Class[] { String.class, String.class, parms.getClass() },
795          new Object[] { "name", "description", parms }
796       );
797       Object cons = Array.newInstance(con.getClass(), 1);
798       Array.set(cons, 0, con);
799
800       Class clazz = loadClass("javax.management.modelmbean.ModelMBeanOperationInfo");
801       Integer impact = new Integer(clazz.getField("ACTION").getInt(null));
802       Object op = instantiate(
803          "javax.management.modelmbean.ModelMBeanOperationInfo",
804          new Class[] { String.class, String.class, parms.getClass(),
805                        String.class, Integer.TYPE },
806          new Object[] { "name", "description", parms, "type", impact }
807       );
808       Object ops = Array.newInstance(op.getClass(), 1);
809       Array.set(ops, 0, op);
810
811       String[] types = { "type1", "type2" };
812       Object not = instantiate(
813          "javax.management.modelmbean.ModelMBeanNotificationInfo",
814          new Class[] { types.getClass(), String.class, String.class },
815          new Object[] { types, "name", "description" }
816       );
817       Object nots = Array.newInstance(not.getClass(), 1);
818       Array.set(nots, 0, not);
819
820       Object obj = instantiate(
821          "javax.management.modelmbean.ModelMBeanInfoSupport",
822          new Class[] { String.class, String.class, atts.getClass(),
823                        cons.getClass(), ops.getClass(), nots.getClass() },
824          new Object[] { "className", "description", atts, cons, ops, nots }
825       );
826       try
827       {
828          Object result = runTest(obj);
829       }
830       catch (java.io.InvalidClassException e)
831       {
832          fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
833       }
834    }
835
836    /**
837     * @todo equals test
838     */

839    public void testModelMBeanNotificationInfo()
840       throws Exception
841    {
842       String[] types = { "type1", "type2" };
843       Object obj = instantiate(
844          "javax.management.modelmbean.ModelMBeanNotificationInfo",
845          new Class[] { types.getClass(), String.class, String.class },
846          new Object[] { types, "name", "description" }
847       );
848       try
849       {
850          Object result = runTest(obj);
851       }
852       catch (java.io.StreamCorruptedException e)
853       {
854          fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
855       }
856    }
857
858    /**
859     * @todo equals test
860     */

861    public void testModelMBeanOperationInfo()
862       throws Exception
863    {
864       Object parm = instantiate(
865          "javax.management.MBeanParameterInfo",
866          new Class[] { String.class, String.class, String.class },
867          new Object[] { "name", "type", "description" }
868       );
869       Object array = Array.newInstance(parm.getClass(), 1);
870       Array.set(array, 0, parm);
871       Class clazz = loadClass("javax.management.MBeanOperationInfo");
872       Integer impact = new Integer(clazz.getField("ACTION").getInt(null));
873       Object obj = instantiate(
874          "javax.management.modelmbean.ModelMBeanOperationInfo",
875          new Class[] { String.class, String.class, array.getClass(),
876                        String.class, Integer.TYPE },
877          new Object[] { "name", "description", array, "type", impact }
878       );
879       try
880       {
881          Object result = runTest(obj);
882          assertEquals(obj.toString(), result.toString());
883       }
884       catch (java.io.StreamCorruptedException e)
885       {
886          fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
887       }
888    }
889
890    /**
891     * @todo the constructor is package private
892     * Actually tested by temporarily making the constructor public
893     */

894    public void testMonitorNotification()
895       throws Exception
896    {
897 /*****
898       Object monitorName = instantiate(
899          "javax.management.ObjectName",
900          new Class[] { String.class },
901          new Object[] { "monitor:x=y" }
902       );
903       Object objectName = instantiate(
904          "javax.management.ObjectName",
905          new Class[] { String.class },
906          new Object[] { "domain:x=y" }
907       );
908       Object obj = instantiate(
909          "javax.management.monitor.MonitorNotification",
910          new Class[] { String.class, Object.class, Long.TYPE, Long.TYPE,
911                        String.class, Object.class, String.class,
912                        objectName.getClass(), Object.class },
913          new Object[] { "type", monitorName, new Long(1), new Long(2),
914                         "message", "derivedGauge", "attribute", objectName,
915                         "trigger"}
916       );
917       Object result = runTest(obj);
918       assertEquals(obj.toString(), result.toString());
919 *****/

920    }
921
922    public void testMonitorSettingException()
923       throws Exception
924    {
925       Object obj = instantiate(
926          "javax.management.monitor.MonitorSettingException",
927          new Class[] { String.class },
928          new Object[] { "message" }
929       );
930       Object result = runTest(obj);
931       assertEquals(obj.toString(), result.toString());
932    }
933
934    public void testNotCompliantMBeanException()
935       throws Exception
936    {
937       Object obj = instantiate(
938          "javax.management.NotCompliantMBeanException",
939          new Class[] { String.class },
940          new Object[] { "message" }
941       );
942       Object result = runTest(obj);
943       assertEquals(obj.toString(), result.toString());
944    }
945
946    public void testNotification()
947       throws Exception
948    {
949       Object objectName = instantiate(
950          "javax.management.ObjectName",
951          new Class[] { String.class },
952          new Object[] { "domain:x=y" }
953       );
954       Object obj = instantiate(
955          "javax.management.Notification",
956          new Class[] { String.class, Object.class, Long.TYPE, Long.TYPE,
957                        String.class },
958          new Object[] { "type", objectName, new Long(1), new Long(2),
959                         "message" }
960       );
961       Object result = runTest(obj);
962       assertEquals(obj.toString(), result.toString());
963    }
964
965    /**
966     * @todo equals tests
967     */

968    public void testNotificationFilterSupport()
969       throws Exception
970    {
971       Object obj = instantiate(
972          "javax.management.NotificationFilterSupport",
973          new Class[0],
974          new Object[0]
975       );
976       Method method = obj.getClass().getMethod("enableType",
977           new Class[] { String.class });
978       method.invoke(obj, new Object[] { "prefix" });
979       Object result = runTest(obj);
980    }
981
982    public void testObjectInstance()
983       throws Exception
984    {
985       Object objectName = instantiate(
986          "javax.management.ObjectName",
987          new Class[] { String.class },
988          new Object[] { "domain:x=y" }
989       );
990       Object obj = instantiate(
991          "javax.management.ObjectInstance",
992          new Class[] { objectName.getClass(), String.class },
993          new Object[] { objectName, "DummyClass" }
994       );
995       Object result = runTest(obj);
996       assertEquals(obj, result);
997    }
998
999    public void testObjectName()
1000      throws Exception
1001   {
1002      Object obj = instantiate(
1003         "javax.management.ObjectName",
1004         new Class[] { String.class },
1005         new Object[] { "domain:x=y" }
1006      );
1007      Object result = runTest(obj);
1008      assertEquals(obj, result);
1009   }
1010
1011   public void testObjectNamePattern()
1012      throws Exception
1013   {
1014      Object obj = instantiate(
1015         "javax.management.ObjectName",
1016         new Class[] { String.class },
1017         new Object[] { "domain*:x=y" }
1018      );
1019      Object result = runTest(obj);
1020      assertEquals(obj, result);
1021   }
1022
1023   public void testObjectNamePropertyPattern()
1024      throws Exception
1025   {
1026      Object obj = instantiate(
1027         "javax.management.ObjectName",
1028         new Class[] { String.class },
1029         new Object[] { "domain:x=y,*" }
1030      );
1031      Object result = runTest(obj);
1032      assertEquals(obj, result);
1033   }
1034
1035   public void testObjectNameRawPropertyPattern()
1036      throws Exception
1037   {
1038      Object obj = instantiate(
1039         "javax.management.ObjectName",
1040         new Class[] { String.class },
1041         new Object[] { "domain:*" }
1042      );
1043      Object result = runTest(obj);
1044      assertEquals(obj, result);
1045   }
1046
1047   public void testOpenDataException()
1048      throws Exception
1049   {
1050      if (SerializationSUITE.form < 11)
1051         return;
1052      Object obj = instantiate(
1053         "javax.management.openmbean.OpenDataException",
1054         new Class[] { String.class },
1055         new Object[] { "message" }
1056      );
1057      Object result = runTest(obj);
1058      assertEquals(obj.toString(), result.toString());
1059   }
1060
1061   public void testOpenMBeanAttributeInfoSupportMinMax()
1062      throws Exception
1063   {
1064      if (SerializationSUITE.form < 11)
1065         return;
1066      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1067      Object elementType = clazz.getField("INTEGER").get(null);
1068
1069      Object obj = instantiate(
1070         "javax.management.openmbean.OpenMBeanAttributeInfoSupport",
1071         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1072                       boolean.class, boolean.class, boolean.class, Object.class, Comparable.class, Comparable.class },
1073         new Object[] { "name", "description", elementType, new Boolean(true), new Boolean(true), new Boolean(false),
1074                        new Integer(12), new Integer(11), new Integer(13) }
1075      );
1076      Object result = runTest(obj);
1077      assertEquals(obj, result);
1078   }
1079
1080   public void testOpenMBeanAttributeInfoSupportLegal()
1081      throws Exception
1082   {
1083      if (SerializationSUITE.form < 11)
1084         return;
1085      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1086      Object elementType = clazz.getField("INTEGER").get(null);
1087
1088      Object obj = instantiate(
1089         "javax.management.openmbean.OpenMBeanAttributeInfoSupport",
1090         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1091                       boolean.class, boolean.class, boolean.class, Object.class, Object[].class },
1092         new Object[] { "name", "description", elementType, new Boolean(true), new Boolean(true), new Boolean(false),
1093                        new Integer(12), new Integer[] { new Integer(12), new Integer(13) }}
1094      );
1095      Object result = runTest(obj);
1096      assertEquals(obj, result);
1097   }
1098
1099   public void testOpenMBeanConstructorInfoSupport()
1100      throws Exception
1101   {
1102      if (SerializationSUITE.form < 11)
1103         return;
1104      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1105      Object elementType = clazz.getField("INTEGER").get(null);
1106
1107      Object parmInfo = instantiate(
1108         "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1109         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1110                       Object.class, Object[].class },
1111         new Object[] { "name", "description", elementType,
1112                        new Integer(12), new Integer[] {new Integer(12), new Integer(13) }}
1113      );
1114      Object array = Array.newInstance(parmInfo.getClass(), 1);
1115      Array.set(array, 0, parmInfo);
1116
1117      Object obj = instantiate(
1118         "javax.management.openmbean.OpenMBeanConstructorInfoSupport",
1119         new Class[] { String.class, String.class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;")},
1120         new Object[] { "name", "description", array }
1121      );
1122      Object result = runTest(obj);
1123      assertEquals(obj, result);
1124   }
1125
1126   public void testOpenMBeanInfoSupport()
1127      throws Exception
1128   {
1129      if (SerializationSUITE.form < 11)
1130         return;
1131      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1132      Object elementType = clazz.getField("INTEGER").get(null);
1133
1134      Object parmInfo = instantiate(
1135         "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1136         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1137                       Object.class, Object[].class },
1138         new Object[] { "name", "description", elementType,
1139                        new Integer(12), new Integer[] {new Integer(12), new Integer(13) }}
1140      );
1141      Object parmArray = Array.newInstance(parmInfo.getClass(), 1);
1142      Array.set(parmArray, 0, parmInfo);
1143
1144      Object attInfo = instantiate(
1145         "javax.management.openmbean.OpenMBeanAttributeInfoSupport",
1146         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1147                       boolean.class, boolean.class, boolean.class, Object.class, Object[].class },
1148         new Object[] { "name", "description", elementType, new Boolean(true), new Boolean(true), new Boolean(false),
1149                        new Integer(12), new Integer[] { new Integer(12), new Integer(13) }}
1150      );
1151
1152      Object conInfo = instantiate(
1153         "javax.management.openmbean.OpenMBeanConstructorInfoSupport",
1154         new Class[] { String.class, String.class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;")},
1155         new Object[] { "name", "description", parmArray }
1156      );
1157
1158      clazz = loadClass("javax.management.MBeanOperationInfo");
1159      Object impact = clazz.getField("INFO").get(null);
1160
1161      Object opInfo = instantiate(
1162         "javax.management.openmbean.OpenMBeanOperationInfoSupport",
1163         new Class[] { String.class, String.class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;"),
1164                       loadClass("javax.management.openmbean.OpenType"), int.class },
1165         new Object[] { "name", "description", parmArray, elementType, impact }
1166      );
1167
1168      String[] types = { "type1", "type2" };
1169      Object notInfo = instantiate(
1170         "javax.management.MBeanNotificationInfo",
1171         new Class[] { types.getClass(), String.class, String.class },
1172         new Object[] { types, "name", "description" }
1173      );
1174
1175      Object attArray = Array.newInstance(attInfo.getClass(), 1);
1176      Array.set(attArray, 0, attInfo);
1177
1178      Object conArray = Array.newInstance(conInfo.getClass(), 1);
1179      Array.set(conArray, 0, conInfo);
1180
1181      Object opArray = Array.newInstance(opInfo.getClass(), 1);
1182      Array.set(opArray, 0, opInfo);
1183
1184      Object notArray = Array.newInstance(notInfo.getClass(), 1);
1185      Array.set(notArray, 0, notInfo);
1186
1187      Object obj = instantiate(
1188         "javax.management.openmbean.OpenMBeanInfoSupport",
1189         new Class[] { String.class, String.class,
1190                       loadClass("[Ljavax.management.openmbean.OpenMBeanAttributeInfo;"),
1191                       loadClass("[Ljavax.management.openmbean.OpenMBeanConstructorInfo;"),
1192                       loadClass("[Ljavax.management.openmbean.OpenMBeanOperationInfo;"),
1193                       loadClass("[Ljavax.management.MBeanNotificationInfo;") },
1194         new Object[] { "classname", "description", attArray, conArray, opArray, notArray }
1195      );
1196
1197      Object result = runTest(obj);
1198      assertEquals(obj.toString(), result.toString());
1199   }
1200
1201   public void testOpenMBeanOperationInfoSupport()
1202      throws Exception
1203   {
1204      if (SerializationSUITE.form < 11)
1205         return;
1206      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1207      Object elementType = clazz.getField("INTEGER").get(null);
1208
1209      Object parmInfo = instantiate(
1210         "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1211         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1212                       Object.class, Object[].class },
1213         new Object[] { "name", "description", elementType,
1214                        new Integer(12), new Integer[] {new Integer(12), new Integer(13) }}
1215      );
1216      Object array = Array.newInstance(parmInfo.getClass(), 1);
1217      Array.set(array, 0, parmInfo);
1218
1219      clazz = loadClass("javax.management.MBeanOperationInfo");
1220      Object impact = clazz.getField("INFO").get(null);
1221
1222      Object obj = instantiate(
1223         "javax.management.openmbean.OpenMBeanOperationInfoSupport",
1224         new Class[] { String.class, String.class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;"),
1225                       loadClass("javax.management.openmbean.OpenType"), int.class },
1226         new Object[] { "name", "description", array, elementType, impact }
1227      );
1228      Object result = runTest(obj);
1229      assertEquals(obj, result);
1230   }
1231
1232   public void testOpenMBeanParameterInfoSupportMinMax()
1233      throws Exception
1234   {
1235      if (SerializationSUITE.form < 11)
1236         return;
1237      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1238      Object elementType = clazz.getField("INTEGER").get(null);
1239
1240      Object obj = instantiate(
1241         "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1242         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1243                       Object.class, Comparable.class, Comparable.class },
1244         new Object[] { "name", "description", elementType,
1245                        new Integer(12), new Integer(11), new Integer(13) }
1246      );
1247      Object result = runTest(obj);
1248      assertEquals(obj, result);
1249   }
1250
1251   public void testOpenMBeanParameterInfoSupportLegal()
1252      throws Exception
1253   {
1254      if (SerializationSUITE.form < 11)
1255         return;
1256      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1257      Object elementType = clazz.getField("INTEGER").get(null);
1258
1259      Object obj = instantiate(
1260         "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1261         new Class[] { String.class, String.class, loadClass("javax.management.openmbean.OpenType"),
1262                       Object.class, Object[].class },
1263         new Object[] { "name", "description", elementType,
1264                         new Integer(12), new Integer[] {new Integer(12), new Integer(13) }}
1265      );
1266      Object result = runTest(obj);
1267      assertEquals(obj, result);
1268   }
1269
1270   public void testOperationsException()
1271      throws Exception
1272   {
1273      Object obj = instantiate(
1274         "javax.management.OperationsException",
1275         new Class[] { String.class },
1276         new Object[] { "message" }
1277      );
1278      Object result = runTest(obj);
1279      assertEquals(obj.toString(), result.toString());
1280   }
1281
1282   public void testReflectionException()
1283      throws Exception
1284   {
1285      Object obj = instantiate(
1286         "javax.management.ReflectionException",
1287         new Class[] { Exception.class, String.class },
1288         new Object[] { new Exception("Cause"), "message" }
1289      );
1290      Object result = runTest(obj);
1291      assertEquals(obj.toString(), result.toString());
1292   }
1293
1294   public void testRelationException()
1295      throws Exception
1296   {
1297      Object obj = instantiate(
1298         "javax.management.relation.RelationException",
1299         new Class[] { String.class },
1300         new Object[] { "message" }
1301      );
1302      Object result = runTest(obj);
1303      assertEquals(obj.toString(), result.toString());
1304   }
1305
1306   public void testRelationNotFoundException()
1307      throws Exception
1308   {
1309      Object obj = instantiate(
1310         "javax.management.relation.RelationNotFoundException",
1311         new Class[] { String.class },
1312         new Object[] { "message" }
1313      );
1314      Object result = runTest(obj);
1315      assertEquals(obj.toString(), result.toString());
1316   }
1317
1318   public void testRelationNotification()
1319      throws Exception
1320   {
1321      Object objectName = instantiate(
1322         "javax.management.ObjectName",
1323         new Class[] { String.class },
1324         new Object[] { "domain:x=y" }
1325      );
1326      Class clazz = loadClass("javax.management.relation.RelationNotification");
1327      String type = (String) clazz.getField("RELATION_BASIC_UPDATE").get(null);
1328      ArrayList newValue = new ArrayList();
1329      newValue.add(objectName);
1330      ArrayList oldValue = new ArrayList();
1331      oldValue.add(objectName);
1332      Object obj = instantiate(
1333         "javax.management.relation.RelationNotification",
1334         new Class[] { String.class, Object.class, Long.TYPE, Long.TYPE,
1335                       String.class, String.class, String.class,
1336                       objectName.getClass(), String.class, List.class, List.class },
1337         new Object[] { type, objectName, new Long(1), new Long(2),
1338                        "message", "relationId", "relationType", objectName,
1339                        "roleName", newValue, oldValue}
1340      );
1341      Object result = runTest(obj);
1342      assertEquals(obj.toString(), result.toString());
1343   }
1344
1345   public void testRelationServiceNotRegisteredException()
1346      throws Exception
1347   {
1348      Object obj = instantiate(
1349         "javax.management.relation.RelationServiceNotRegisteredException",
1350         new Class[] { String.class },
1351         new Object[] { "message" }
1352      );
1353      Object result = runTest(obj);
1354      assertEquals(obj.toString(), result.toString());
1355   }
1356
1357   public void testRelationTypeNotFoundException()
1358      throws Exception
1359   {
1360      Object obj = instantiate(
1361         "javax.management.relation.RelationTypeNotFoundException",
1362         new Class[] { String.class },
1363         new Object[] { "message" }
1364      );
1365      Object result = runTest(obj);
1366      assertEquals(obj.toString(), result.toString());
1367   }
1368
1369   /**
1370    * @todo equals test
1371    */

1372   public void testRelationTypeSupport()
1373      throws Exception
1374   {
1375      Object roleInfo = instantiate(
1376         "javax.management.relation.RoleInfo",
1377         new Class[] { String.class, String.class, Boolean.TYPE, Boolean.TYPE,
1378                       Integer.TYPE, Integer.TYPE, String.class },
1379         new Object[] { "name", "test.serialization.support.Trivial",
1380                        new Boolean(true), new Boolean(true), new Integer(10),
1381                        new Integer(20), "descritpion" }
1382      );
1383      Object array = Array.newInstance(roleInfo.getClass(), 1);
1384      Array.set(array, 0, roleInfo);
1385      Object obj = instantiate(
1386         "javax.management.relation.RelationTypeSupport",
1387         new Class[] { String.class, array.getClass() },
1388         new Object[] { "name", array }
1389      );
1390      Object result = runTest(obj);
1391   }
1392
1393   public void testRole()
1394      throws Exception
1395   {
1396      Object objectName = instantiate(
1397         "javax.management.ObjectName",
1398         new Class[] { String.class },
1399         new Object[] { "domain:x=y" }
1400      );
1401      ArrayList list = new ArrayList();
1402      list.add(objectName);
1403      Object obj = instantiate(
1404         "javax.management.relation.Role",
1405         new Class[] { String.class, List.class},
1406         new Object[] { "name", list }
1407      );
1408      Object result = runTest(obj);
1409      assertEquals(obj.toString(), result.toString());
1410   }
1411
1412   public void testRoleInfo()
1413      throws Exception
1414   {
1415      Object obj = instantiate(
1416         "javax.management.relation.RoleInfo",
1417         new Class[] { String.class, String.class, Boolean.TYPE, Boolean.TYPE,
1418                       Integer.TYPE, Integer.TYPE, String.class },
1419         new Object[] { "name", "test.serialization.support.Trivial",
1420                        new Boolean(true), new Boolean(true), new Integer(10),
1421                        new Integer(20), "descritpion" }
1422      );
1423      Object result = runTest(obj);
1424      assertEquals(obj.toString(), result.toString());
1425   }
1426
1427   public void testRoleInfoNotFoundException()
1428      throws Exception
1429   {
1430      Object obj = instantiate(
1431         "javax.management.relation.RoleInfoNotFoundException",
1432         new Class[] { String.class },
1433         new Object[] { "message" }
1434      );
1435      Object result = runTest(obj);
1436      assertEquals(obj.toString(), result.toString());
1437   }
1438
1439   public void testRoleList()
1440      throws Exception
1441   {
1442      Object objectName = instantiate(
1443         "javax.management.ObjectName",
1444         new Class[] { String.class },
1445         new Object[] { "domain:x=y" }
1446      );
1447      ArrayList list = new ArrayList();
1448      list.add(objectName);
1449      Object role = instantiate(
1450         "javax.management.relation.Role",
1451         new Class[] { String.class, List.class},
1452         new Object[] { "name", list }
1453      );
1454      list = new ArrayList();
1455      list.add(role);
1456      Object obj = instantiate(
1457         "javax.management.relation.RoleList",
1458         new Class[] { List.class},
1459         new Object[] { list }
1460      );
1461      Object result = runTest(obj);
1462      assertEquals(obj.toString(), result.toString());
1463   }
1464
1465   public void testRoleNotFoundException()
1466      throws Exception
1467   {
1468      Object obj = instantiate(
1469         "javax.management.relation.RoleNotFoundException",
1470         new Class[] { String.class },
1471         new Object[] { "message" }
1472      );
1473      Object result = runTest(obj);
1474      assertEquals(obj.toString(), result.toString());
1475   }
1476
1477   public void testRoleResult()
1478      throws Exception
1479   {
1480      Object objectName = instantiate(
1481         "javax.management.ObjectName",
1482         new Class[] { String.class },
1483         new Object[] { "domain:x=y" }
1484      );
1485      ArrayList list = new ArrayList();
1486      list.add(objectName);
1487
1488      Object resolved = instantiate(
1489         "javax.management.relation.Role",
1490         new Class[] { String.class, List.class},
1491         new Object[] { "name", list }
1492      );
1493      list = new ArrayList();
1494      list.add(resolved);
1495      Object resolvedList = instantiate(
1496         "javax.management.relation.RoleList",
1497         new Class[] { List.class },
1498         new Object[] { list }
1499      );
1500
1501      Class clazz = loadClass("javax.management.relation.RoleStatus");
1502      Integer status = new Integer(clazz.getField("ROLE_NOT_READABLE").getInt(null));
1503      Object unresolved = instantiate(
1504         "javax.management.relation.RoleUnresolved",
1505         new Class[] { String.class, List.class, Integer.TYPE},
1506         new Object[] { "name", list, status }
1507      );
1508      list = new ArrayList();
1509      list.add(unresolved);
1510      Object unresolvedList = instantiate(
1511         "javax.management.relation.RoleUnresolvedList",
1512         new Class[] { List.class },
1513         new Object[] { list }
1514      );
1515      Object obj = instantiate(
1516         "javax.management.relation.RoleResult",
1517         new Class[] { resolvedList.getClass(), unresolvedList.getClass() },
1518         new Object[] { resolvedList, unresolvedList }
1519      );
1520      Object result = runTest(obj);
1521      assertEquals(obj.toString(), result.toString());
1522   }
1523
1524   public void testRoleUnresolved()
1525      throws Exception
1526   {
1527      Object objectName = instantiate(
1528         "javax.management.ObjectName",
1529         new Class[] { String.class },
1530         new Object[] { "domain:x=y" }
1531      );
1532      ArrayList list = new ArrayList();
1533      list.add(objectName);
1534      Class clazz = loadClass("javax.management.relation.RoleStatus");
1535      Integer status = new Integer(clazz.getField("ROLE_NOT_READABLE").getInt(null));
1536      Object obj = instantiate(
1537         "javax.management.relation.RoleUnresolved",
1538         new Class[] { String.class, List.class, Integer.TYPE},
1539         new Object[] { "name", list, status }
1540      );
1541      Object result = runTest(obj);
1542      assertEquals(obj.toString(), result.toString());
1543   }
1544
1545   public void testRoleUnresolvedList()
1546      throws Exception
1547   {
1548      Object objectName = instantiate(
1549         "javax.management.ObjectName",
1550         new Class[] { String.class },
1551         new Object[] { "domain:x=y" }
1552      );
1553      ArrayList list = new ArrayList();
1554      list.add(objectName);
1555      Class clazz = loadClass("javax.management.relation.RoleStatus");
1556      Integer status = new Integer(clazz.getField("ROLE_NOT_READABLE").getInt(null));
1557      Object unresolved = instantiate(
1558         "javax.management.relation.RoleUnresolved",
1559         new Class[] { String.class, List.class, Integer.TYPE},
1560         new Object[] { "name", list, status }
1561      );
1562      list = new ArrayList();
1563      list.add(unresolved);
1564      Object obj = instantiate(
1565         "javax.management.relation.RoleUnresolvedList",
1566         new Class[] { List.class},
1567         new Object[] { list }
1568      );
1569      Object result = runTest(obj);
1570      assertEquals(obj.toString(), result.toString());
1571   }
1572
1573   public void testRuntimeErrorException()
1574      throws Exception
1575   {
1576      Object obj = instantiate(
1577         "javax.management.RuntimeErrorException",
1578         new Class[] { Error.class, String.class },
1579         new Object[] { new Error("Cause"), "message" }
1580      );
1581      Object result = runTest(obj);
1582      assertEquals(obj.toString(), result.toString());
1583   }
1584
1585   public void testRuntimeMBeanException()
1586      throws Exception
1587   {
1588      Object obj = instantiate(
1589         "javax.management.RuntimeMBeanException",
1590         new Class[] { RuntimeException.class, String.class },
1591         new Object[] { new RuntimeException("Cause"), "message" }
1592      );
1593      Object result = runTest(obj);
1594      assertEquals(obj.toString(), result.toString());
1595   }
1596
1597   public void testRuntimeOperationsException()
1598      throws Exception
1599   {
1600      Object obj = instantiate(
1601         "javax.management.RuntimeOperationsException",
1602         new Class[] { RuntimeException.class, String.class },
1603         new Object[] { new RuntimeException("Cause"), "message" }
1604      );
1605      Object result = runTest(obj);
1606      assertEquals(obj.toString(), result.toString());
1607   }
1608
1609   public void testServiceNotFoundException()
1610      throws Exception
1611   {
1612      Object obj = instantiate(
1613         "javax.management.ServiceNotFoundException",
1614         new Class[] { String.class },
1615         new Object[] { "message" }
1616      );
1617      Object result = runTest(obj);
1618      assertEquals(obj.toString(), result.toString());
1619   }
1620
1621   public void testSimpleType()
1622      throws Exception
1623   {
1624      if (SerializationSUITE.form < 11)
1625         return;
1626      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1627      Object obj = clazz.getField("BIGDECIMAL").get(null);
1628      Object result = runTest(obj);
1629      assertTrue("Simple types should resolve to the same object",
1630                 obj == result);
1631   }
1632
1633   public void testStringValueExp()
1634      throws Exception
1635   {
1636      Object obj = instantiate(
1637         "javax.management.StringValueExp",
1638         new Class[] { String.class },
1639         new Object[] { "attr" }
1640      );
1641      Object result = runTest(obj);
1642      assertEquals(obj.toString(), result.toString());
1643   }
1644
1645   public void testTabularDataSupport()
1646      throws Exception
1647   {
1648      if (SerializationSUITE.form < 11)
1649         return;
1650      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1651      Object openType = clazz.getField("STRING").get(null);
1652
1653      Class elementClass = loadClass("javax.management.openmbean.OpenType");
1654      Object array = Array.newInstance(elementClass, 2);
1655      Array.set(array, 0, openType);
1656      Array.set(array, 1, openType);
1657
1658      Object compositeType = instantiate(
1659         "javax.management.openmbean.CompositeType",
1660         new Class[] { String.class, String.class, String[].class, String[].class, array.getClass() },
1661         new Object[] { "typeName", "description", new String[] { "name1", "name2" },
1662            new String[] { "desc1", "desc2" }, array }
1663      );
1664
1665      Object tabularType = instantiate(
1666         "javax.management.openmbean.TabularType",
1667         new Class[] { String.class, String.class, compositeType.getClass(), String[].class },
1668         new Object[] { "typeName", "description", compositeType, new String[] { "name1" }}
1669      );
1670
1671      Object obj = instantiate(
1672         "javax.management.openmbean.TabularDataSupport",
1673         new Class[] { tabularType.getClass() },
1674         new Object[] { tabularType }
1675      );
1676      Object result = runTest(obj);
1677      assertEquals(obj, result);
1678   }
1679
1680   public void testTabularType()
1681      throws Exception
1682   {
1683      if (SerializationSUITE.form < 11)
1684         return;
1685      Class clazz = loadClass("javax.management.openmbean.SimpleType");
1686      Object openType = clazz.getField("STRING").get(null);
1687
1688      Class elementClass = loadClass("javax.management.openmbean.OpenType");
1689      Object array = Array.newInstance(elementClass, 2);
1690      Array.set(array, 0, openType);
1691      Array.set(array, 1, openType);
1692
1693      Object compositeType = instantiate(
1694         "javax.management.openmbean.CompositeType",
1695         new Class[] { String.class, String.class, String[].class, String[].class, array.getClass() },
1696         new Object[] { "typeName", "description", new String[] { "name1", "name2" },
1697            new String[] { "desc1", "desc2" }, array }
1698      );
1699
1700      Object obj = instantiate(
1701         "javax.management.openmbean.TabularType",
1702         new Class[] { String.class, String.class, compositeType.getClass(), String[].class },
1703         new Object[] { "typeName", "description", compositeType, new String[] { "name1" }}
1704      );
1705
1706      Object result = runTest(obj);
1707      assertEquals(obj, result);
1708   }
1709
1710   /**
1711    * @todo ?
1712    */

1713   public void testTimerAlarmClockNotification()
1714      throws Exception
1715   {
1716   }
1717
1718   public void testTimerNotification()
1719      throws Exception
1720   {
1721      Object timerName = instantiate(
1722         "javax.management.ObjectName",
1723         new Class[] { String.class },
1724         new Object[] { "timer:x=y" }
1725      );
1726      Object obj = instantiate(
1727         "javax.management.timer.TimerNotification",
1728         new Class[] { String.class, Object.class, Long.TYPE, Long.TYPE,
1729                       String.class, Integer.class, Object.class },
1730         new Object[] { "type", timerName, new Long(1), new Long(2),
1731                        "message", new Integer(1), "user data" }
1732      );
1733      Object result = runTest(obj);
1734      assertEquals(obj.toString(), result.toString());
1735   }
1736
1737   public void testXMLParseException()
1738      throws Exception
1739   {
1740      Object obj = instantiate(
1741         "javax.management.modelmbean.XMLParseException",
1742         new Class[] { Exception.class, String.class },
1743         new Object[] { new Exception("exception"), "message" }
1744      );
1745      Object result = runTest(obj);
1746      assertEquals(obj.toString(), result.toString());
1747   }
1748
1749   // Support -------------------------------------------------------
1750

1751   /**
1752    * Instantiate an object using JBossMX.
1753    */

1754   private Object instantiate(String className, Class[] sig, Object[] parms)
1755      throws Exception
1756   {
1757      Constructor cons = loadClass(className).getDeclaredConstructor(sig);
1758      return cons.newInstance(parms);
1759   }
1760
1761   /**
1762    * Load a class using JBossMX.
1763    */

1764   private Class loadClass(String className)
1765      throws Exception
1766   {
1767      return SerializationSUITE.jbossmx.loadClass(className);
1768   }
1769
1770   /**
1771    * Serialize from jbossmx to jmxri.
1772    * Serialize from jmxri to jbossmx.
1773    */

1774   private Object runTest(Object obj)
1775      throws Exception
1776   {
1777      ByteArrayOutputStream os = serializeJBoss(obj);
1778      Object intermediate = deserializeRI(os);
1779      os = serializeRI(intermediate);
1780      return deserializeJBoss(os);
1781   }
1782
1783   /**
1784    * Dummy method wrapper for debugging.
1785    */

1786   private ByteArrayOutputStream serializeJBoss(Object obj)
1787      throws Exception
1788   {
1789      return serialize(obj);
1790   }
1791
1792   /**
1793    * Dummy method wrapper for debugging.
1794    */

1795   private ByteArrayOutputStream serializeRI(Object obj)
1796      throws Exception
1797   {
1798      return serialize(obj);
1799   }
1800
1801   /**
1802    * Dummy method wrapper for debugging.
1803    */

1804   private Object deserializeJBoss(ByteArrayOutputStream os)
1805      throws Exception
1806   {
1807      return deserialize(SerializationSUITE.jbossmx, os);
1808   }
1809
1810   /**
1811    * Dummy method wrapper for debugging.
1812    */

1813   private Object deserializeRI(ByteArrayOutputStream os)
1814      throws Exception
1815   {
1816      return deserialize(SerializationSUITE.jmxri, os);
1817   }
1818
1819   /**
1820    * Serialize the object.
1821    */

1822   private ByteArrayOutputStream serialize(Object obj)
1823      throws Exception
1824   {
1825      ByteArrayOutputStream baos = new ByteArrayOutputStream();
1826      ObjectOutputStream oos = new ObjectOutputStream(baos);
1827      oos.writeObject(obj);
1828      return baos;
1829   }
1830    
1831   /**
1832    * Deserialize the object.
1833    */

1834   private Object deserialize(ClassLoader cl, ByteArrayOutputStream baos)
1835      throws Exception
1836   {
1837      ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
1838      ObjectInputStream ois = new MyObjectInputStream(cl, bais);
1839      return ois.readObject();
1840   }
1841
1842   /**
1843    * Custom inputstream to override classloading to the relevent
1844    * jmx implementation
1845    */

1846   public class MyObjectInputStream extends ObjectInputStream
1847   {
1848      ClassLoader cl;
1849      public MyObjectInputStream(ClassLoader cl, ByteArrayInputStream is)
1850         throws IOException
1851      {
1852         super(is);
1853         this.cl = cl;
1854      }
1855      protected Class resolveClass(java.io.ObjectStreamClass osc)
1856         throws IOException, ClassNotFoundException
1857      {
1858         return cl.loadClass(osc.getName());
1859      }
1860   }
1861}
1862
Popular Tags