Source Code Cross Referenced for SerializeTestCase.java in  » EJB-Server-JBoss-4.2.1 » jmx » test » serialization » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server JBoss 4.2.1 » jmx » test.serialization 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * JBoss, Home of Professional Open Source.
0003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
0004:         * as indicated by the @author tags. See the copyright.txt file in the
0005:         * distribution for a full listing of individual contributors.
0006:         *
0007:         * This is free software; you can redistribute it and/or modify it
0008:         * under the terms of the GNU Lesser General Public License as
0009:         * published by the Free Software Foundation; either version 2.1 of
0010:         * the License, or (at your option) any later version.
0011:         *
0012:         * This software is distributed in the hope that it will be useful,
0013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015:         * Lesser General Public License for more details.
0016:         *
0017:         * You should have received a copy of the GNU Lesser General Public
0018:         * License along with this software; if not, write to the Free
0019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
0021:         */
0022:        package test.serialization;
0023:
0024:        import java.io.ByteArrayInputStream;
0025:        import java.io.ByteArrayOutputStream;
0026:        import java.io.IOException;
0027:        import java.io.ObjectInputStream;
0028:        import java.io.ObjectOutputStream;
0029:        import java.lang.reflect.Array;
0030:        import java.lang.reflect.Constructor;
0031:        import java.lang.reflect.Method;
0032:        import java.util.ArrayList;
0033:        import java.util.List;
0034:
0035:        import junit.framework.TestCase;
0036:
0037:        /**
0038:         * Tests serialization with the RI
0039:         *
0040:         * @todo Proper equality tests instead of toString()
0041:         *
0042:         * @author  <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
0043:         */
0044:        public class SerializeTestCase extends TestCase {
0045:            // Attributes ----------------------------------------------------------------
0046:
0047:            // Constructor ---------------------------------------------------------------
0048:
0049:            /**
0050:             * Construct the test
0051:             */
0052:            public SerializeTestCase(String s) {
0053:                super (s);
0054:            }
0055:
0056:            public void testArrayType() throws Exception {
0057:                if (SerializationSUITE.form < 11)
0058:                    return;
0059:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
0060:                Object elementType = clazz.getField("BIGDECIMAL").get(null);
0061:                Object obj = instantiate(
0062:                        "javax.management.openmbean.ArrayType",
0063:                        new Class[] {
0064:                                Integer.TYPE,
0065:                                loadClass("javax.management.openmbean.OpenType") },
0066:                        new Object[] { new Integer(3), elementType });
0067:                Object result = runTest(obj);
0068:                assertEquals(obj, result);
0069:            }
0070:
0071:            public void testAttribute() throws Exception {
0072:                Object obj = instantiate("javax.management.Attribute",
0073:                        new Class[] { String.class, Object.class },
0074:                        new Object[] { "name", "value" });
0075:                Object result = runTest(obj);
0076:                assertEquals(obj, result);
0077:            }
0078:
0079:            public void testAttributeChangeNotification() throws Exception {
0080:                Object obj = instantiate(
0081:                        "javax.management.AttributeChangeNotification",
0082:                        new Class[] { Object.class, Long.TYPE, Long.TYPE,
0083:                                String.class, String.class, String.class,
0084:                                Object.class, Object.class }, new Object[] {
0085:                                "source", new Long(1), new Long(2), "message",
0086:                                "name", "type", "old", "new" });
0087:                Object result = runTest(obj);
0088:                assertEquals(obj.toString(), result.toString());
0089:            }
0090:
0091:            public void testAttributeChangeNotificationFilter()
0092:                    throws Exception {
0093:                Object obj = instantiate(
0094:                        "javax.management.AttributeChangeNotificationFilter",
0095:                        new Class[0], new Object[0]);
0096:                Method method = obj.getClass().getMethod("enableAttribute",
0097:                        new Class[] { String.class });
0098:                method.invoke(obj, new Object[] { "attribute" });
0099:                Object result = runTest(obj);
0100:                assertEquals(obj.toString(), result.toString());
0101:            }
0102:
0103:            public void testAttributeList() throws Exception {
0104:                Object obj = instantiate("javax.management.AttributeList",
0105:                        new Class[0], new Object[0]);
0106:                Object attr = instantiate("javax.management.Attribute",
0107:                        new Class[] { String.class, Object.class },
0108:                        new Object[] { "name", "value" });
0109:                Method method = obj.getClass().getMethod("add",
0110:                        new Class[] { attr.getClass() });
0111:                method.invoke(obj, new Object[] { attr });
0112:                Object result = runTest(obj);
0113:                assertEquals(obj.toString(), result.toString());
0114:            }
0115:
0116:            public void testAttributeNotFoundException() throws Exception {
0117:                Object obj = instantiate(
0118:                        "javax.management.AttributeNotFoundException",
0119:                        new Class[] { String.class },
0120:                        new Object[] { "message" });
0121:                Object result = runTest(obj);
0122:                assertEquals(obj.toString(), result.toString());
0123:            }
0124:
0125:            public void testAttributeValueExp() throws Exception {
0126:                Object obj = instantiate("javax.management.AttributeValueExp",
0127:                        new Class[] { String.class }, new Object[] { "attr" });
0128:                Object result = runTest(obj);
0129:                assertEquals(obj.toString(), result.toString());
0130:            }
0131:
0132:            public void testBadAttributeValueExpException() throws Exception {
0133:                Object obj = instantiate(
0134:                        "javax.management.BadAttributeValueExpException",
0135:                        new Class[] { Object.class }, new Object[] { "value" });
0136:                Object result = runTest(obj);
0137:                assertEquals(obj.toString(), result.toString());
0138:            }
0139:
0140:            public void testBadBinaryOpValueExpException() throws Exception {
0141:                Object exp = instantiate("javax.management.AttributeValueExp",
0142:                        new Class[] { String.class }, new Object[] { "attr" });
0143:
0144:                Object obj = instantiate(
0145:                        "javax.management.BadBinaryOpValueExpException",
0146:                        new Class[] { loadClass("javax.management.ValueExp") },
0147:                        new Object[] { exp });
0148:                Object result = runTest(obj);
0149:                assertEquals(obj.toString(), result.toString());
0150:            }
0151:
0152:            public void testBadStringOperationException() throws Exception {
0153:                Object obj = instantiate(
0154:                        "javax.management.BadStringOperationException",
0155:                        new Class[] { String.class },
0156:                        new Object[] { "message" });
0157:                Object result = runTest(obj);
0158:                assertEquals(obj.toString(), result.toString());
0159:            }
0160:
0161:            public void testCompositeDataSupport() throws Exception {
0162:                if (SerializationSUITE.form < 11)
0163:                    return;
0164:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
0165:                Object openType = clazz.getField("STRING").get(null);
0166:
0167:                Class elementClass = loadClass("javax.management.openmbean.OpenType");
0168:                Object array = Array.newInstance(elementClass, 2);
0169:                Array.set(array, 0, openType);
0170:                Array.set(array, 1, openType);
0171:
0172:                Object compositeType = instantiate(
0173:                        "javax.management.openmbean.CompositeType",
0174:                        new Class[] { String.class, String.class,
0175:                                String[].class, String[].class,
0176:                                array.getClass() }, new Object[] { "typeName",
0177:                                "description",
0178:                                new String[] { "name1", "name2" },
0179:                                new String[] { "desc1", "desc2" }, array });
0180:                Object obj = instantiate(
0181:                        "javax.management.openmbean.CompositeDataSupport",
0182:                        new Class[] { compositeType.getClass(), String[].class,
0183:                                Object[].class }, new Object[] { compositeType,
0184:                                new String[] { "name1", "name2" },
0185:                                new Object[] { "itemValue1", "itemValue2" } });
0186:                Object result = runTest(obj);
0187:                assertEquals(obj, result);
0188:            }
0189:
0190:            public void testCompositeType() throws Exception {
0191:                if (SerializationSUITE.form < 11)
0192:                    return;
0193:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
0194:                Object openType = clazz.getField("STRING").get(null);
0195:
0196:                Class elementClass = loadClass("javax.management.openmbean.OpenType");
0197:                Object array = Array.newInstance(elementClass, 2);
0198:                Array.set(array, 0, openType);
0199:                Array.set(array, 1, openType);
0200:
0201:                Object obj = instantiate(
0202:                        "javax.management.openmbean.CompositeType",
0203:                        new Class[] { String.class, String.class,
0204:                                String[].class, String[].class,
0205:                                array.getClass() }, new Object[] { "typeName",
0206:                                "description",
0207:                                new String[] { "name1", "name2" },
0208:                                new String[] { "desc1", "desc2" }, array });
0209:                Object result = runTest(obj);
0210:                assertEquals(obj, result);
0211:            }
0212:
0213:            public void testDescriptorSupport() throws Exception {
0214:                Object obj = instantiate(
0215:                        "javax.management.modelmbean.DescriptorSupport",
0216:                        new Class[] { new String[0].getClass(),
0217:                                new Object[0].getClass() }, new Object[] {
0218:                                new String[] { "name1", "name2" },
0219:                                new Object[] { "value1", "value2" } });
0220:                Object result = runTest(obj);
0221:                assertEquals(obj.toString(), result.toString());
0222:            }
0223:
0224:            public void testInstanceAlreadyExistsException() throws Exception {
0225:                Object obj = instantiate(
0226:                        "javax.management.InstanceAlreadyExistsException",
0227:                        new Class[] { String.class },
0228:                        new Object[] { "message" });
0229:                Object result = runTest(obj);
0230:                assertEquals(obj.toString(), result.toString());
0231:            }
0232:
0233:            public void testInstanceNotFoundException() throws Exception {
0234:                Object obj = instantiate(
0235:                        "javax.management.InstanceNotFoundException",
0236:                        new Class[] { String.class },
0237:                        new Object[] { "message" });
0238:                Object result = runTest(obj);
0239:                assertEquals(obj.toString(), result.toString());
0240:            }
0241:
0242:            public void testIntrospectionException() throws Exception {
0243:                Object obj = instantiate(
0244:                        "javax.management.IntrospectionException",
0245:                        new Class[] { String.class },
0246:                        new Object[] { "message" });
0247:                Object result = runTest(obj);
0248:                assertEquals(obj.toString(), result.toString());
0249:            }
0250:
0251:            public void testInvalidApplicationException() throws Exception {
0252:                Object obj = instantiate(
0253:                        "javax.management.InvalidApplicationException",
0254:                        new Class[] { Object.class }, new Object[] { "value" });
0255:                Object result = runTest(obj);
0256:                assertEquals(obj.toString(), result.toString());
0257:            }
0258:
0259:            public void testInvalidAttributeValueException() throws Exception {
0260:                Object obj = instantiate(
0261:                        "javax.management.InvalidAttributeValueException",
0262:                        new Class[] { String.class },
0263:                        new Object[] { "message" });
0264:                Object result = runTest(obj);
0265:                assertEquals(obj.toString(), result.toString());
0266:            }
0267:
0268:            public void testInvalidKeyException() throws Exception {
0269:                if (SerializationSUITE.form < 11)
0270:                    return;
0271:                Object obj = instantiate(
0272:                        "javax.management.openmbean.InvalidKeyException",
0273:                        new Class[] { String.class },
0274:                        new Object[] { "message" });
0275:                Object result = runTest(obj);
0276:                assertEquals(obj.toString(), result.toString());
0277:            }
0278:
0279:            public void testInvalidOpenTypeException() throws Exception {
0280:                if (SerializationSUITE.form < 11)
0281:                    return;
0282:                Object obj = instantiate(
0283:                        "javax.management.openmbean.InvalidOpenTypeException",
0284:                        new Class[] { String.class },
0285:                        new Object[] { "message" });
0286:                Object result = runTest(obj);
0287:                assertEquals(obj.toString(), result.toString());
0288:            }
0289:
0290:            public void testInvalidRelationIdException() throws Exception {
0291:                Object obj = instantiate(
0292:                        "javax.management.relation.InvalidRelationIdException",
0293:                        new Class[] { String.class },
0294:                        new Object[] { "message" });
0295:                Object result = runTest(obj);
0296:                assertEquals(obj.toString(), result.toString());
0297:            }
0298:
0299:            public void testInvalidRelationServiceException() throws Exception {
0300:                Object obj = instantiate(
0301:                        "javax.management.relation.InvalidRelationServiceException",
0302:                        new Class[] { String.class },
0303:                        new Object[] { "message" });
0304:                Object result = runTest(obj);
0305:                assertEquals(obj.toString(), result.toString());
0306:            }
0307:
0308:            public void testInvalidRelationTypeException() throws Exception {
0309:                Object obj = instantiate(
0310:                        "javax.management.relation.InvalidRelationTypeException",
0311:                        new Class[] { String.class },
0312:                        new Object[] { "message" });
0313:                Object result = runTest(obj);
0314:                assertEquals(obj.toString(), result.toString());
0315:            }
0316:
0317:            public void testInvalidRoleInfoException() throws Exception {
0318:                Object obj = instantiate(
0319:                        "javax.management.relation.InvalidRoleInfoException",
0320:                        new Class[] { String.class },
0321:                        new Object[] { "message" });
0322:                Object result = runTest(obj);
0323:                assertEquals(obj.toString(), result.toString());
0324:            }
0325:
0326:            public void testInvalidRoleValueException() throws Exception {
0327:                Object obj = instantiate(
0328:                        "javax.management.relation.InvalidRoleValueException",
0329:                        new Class[] { String.class },
0330:                        new Object[] { "message" });
0331:                Object result = runTest(obj);
0332:                assertEquals(obj.toString(), result.toString());
0333:            }
0334:
0335:            public void testInvalidTargetObjectTypeException() throws Exception {
0336:                Object obj = instantiate(
0337:                        "javax.management.modelmbean.InvalidTargetObjectTypeException",
0338:                        new Class[] { Exception.class, String.class },
0339:                        new Object[] { new Exception("exception"), "message" });
0340:                Object result = runTest(obj);
0341:                assertEquals(obj.toString(), result.toString());
0342:            }
0343:
0344:            public void testKeyAlreadyExistsException() throws Exception {
0345:                if (SerializationSUITE.form < 11)
0346:                    return;
0347:                Object obj = instantiate(
0348:                        "javax.management.openmbean.KeyAlreadyExistsException",
0349:                        new Class[] { String.class },
0350:                        new Object[] { "message" });
0351:                Object result = runTest(obj);
0352:                assertEquals(obj.toString(), result.toString());
0353:            }
0354:
0355:            public void testJMException() throws Exception {
0356:                Object obj = instantiate("javax.management.JMException",
0357:                        new Class[] { String.class },
0358:                        new Object[] { "message" });
0359:                Object result = runTest(obj);
0360:                assertEquals(obj.toString(), result.toString());
0361:            }
0362:
0363:            public void testJMRuntimeException() throws Exception {
0364:                Object obj = instantiate("javax.management.JMRuntimeException",
0365:                        new Class[] { String.class },
0366:                        new Object[] { "message" });
0367:                Object result = runTest(obj);
0368:                assertEquals(obj.toString(), result.toString());
0369:            }
0370:
0371:            public void testListenerNotFoundException() throws Exception {
0372:                Object obj = instantiate(
0373:                        "javax.management.ListenerNotFoundException",
0374:                        new Class[] { String.class },
0375:                        new Object[] { "message" });
0376:                Object result = runTest(obj);
0377:                assertEquals(obj.toString(), result.toString());
0378:            }
0379:
0380:            public void testMalformedObjectNameException() throws Exception {
0381:                Object obj = instantiate(
0382:                        "javax.management.MalformedObjectNameException",
0383:                        new Class[] { String.class },
0384:                        new Object[] { "message" });
0385:                Object result = runTest(obj);
0386:                assertEquals(obj.toString(), result.toString());
0387:            }
0388:
0389:            public void testMBeanAttributeInfo() throws Exception {
0390:                Object obj = instantiate("javax.management.MBeanAttributeInfo",
0391:                        new Class[] { String.class, String.class, String.class,
0392:                                Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
0393:                        new Object[] { "name", "type", "description",
0394:                                new Boolean(true), new Boolean(true),
0395:                                new Boolean(false) });
0396:                try {
0397:                    Object result = runTest(obj);
0398:                    assertEquals(obj.toString(), result.toString());
0399:                } catch (java.io.InvalidClassException e) {
0400:                    fail("FAILS IN RI 1.1: Wrong serialization for form 1.0");
0401:                }
0402:            }
0403:
0404:            public void testMBeanConstructorInfo() throws Exception {
0405:                Object parm = instantiate(
0406:                        "javax.management.MBeanParameterInfo", new Class[] {
0407:                                String.class, String.class, String.class },
0408:                        new Object[] { "name", "type", "description" });
0409:                Object array = Array.newInstance(parm.getClass(), 1);
0410:                Array.set(array, 0, parm);
0411:                Object obj = instantiate(
0412:                        "javax.management.MBeanConstructorInfo", new Class[] {
0413:                                String.class, String.class, array.getClass() },
0414:                        new Object[] { "name", "description", array });
0415:                Object result = runTest(obj);
0416:                assertEquals(obj.toString(), result.toString());
0417:            }
0418:
0419:            public void testMBeanException() throws Exception {
0420:                Object obj = instantiate("javax.management.MBeanException",
0421:                        new Class[] { Exception.class, String.class },
0422:                        new Object[] { new Exception("Cause"), "message" });
0423:                Object result = runTest(obj);
0424:                assertEquals(obj.toString(), result.toString());
0425:            }
0426:
0427:            public void testMBeanFeatureInfo() throws Exception {
0428:                Object obj = instantiate("javax.management.MBeanFeatureInfo",
0429:                        new Class[] { String.class, String.class },
0430:                        new Object[] { "name", "description" });
0431:                Object result = runTest(obj);
0432:                assertEquals(obj.toString(), result.toString());
0433:            }
0434:
0435:            public void testMBeanInfo() throws Exception {
0436:                Object parm = instantiate(
0437:                        "javax.management.MBeanParameterInfo", new Class[] {
0438:                                String.class, String.class, String.class },
0439:                        new Object[] { "name", "type", "description" });
0440:                Object parms = Array.newInstance(parm.getClass(), 1);
0441:                Array.set(parms, 0, parm);
0442:
0443:                Object att = instantiate("javax.management.MBeanAttributeInfo",
0444:                        new Class[] { String.class, String.class, String.class,
0445:                                Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
0446:                        new Object[] { "name", "type", "description",
0447:                                new Boolean(true), new Boolean(true),
0448:                                new Boolean(false) });
0449:                Object atts = Array.newInstance(att.getClass(), 1);
0450:                Array.set(atts, 0, att);
0451:
0452:                Object con = instantiate(
0453:                        "javax.management.MBeanConstructorInfo", new Class[] {
0454:                                String.class, String.class, parms.getClass() },
0455:                        new Object[] { "name", "description", parms });
0456:                Object cons = Array.newInstance(con.getClass(), 1);
0457:                Array.set(cons, 0, con);
0458:
0459:                Class clazz = loadClass("javax.management.MBeanOperationInfo");
0460:                Integer impact = new Integer(clazz.getField("ACTION").getInt(
0461:                        null));
0462:                Object op = instantiate("javax.management.MBeanOperationInfo",
0463:                        new Class[] { String.class, String.class,
0464:                                parms.getClass(), String.class, Integer.TYPE },
0465:                        new Object[] { "name", "description", parms, "type",
0466:                                impact });
0467:                Object ops = Array.newInstance(op.getClass(), 1);
0468:                Array.set(ops, 0, op);
0469:
0470:                String[] types = { "type1", "type2" };
0471:                Object not = instantiate(
0472:                        "javax.management.MBeanNotificationInfo", new Class[] {
0473:                                types.getClass(), String.class, String.class },
0474:                        new Object[] { types, "name", "description" });
0475:                Object nots = Array.newInstance(not.getClass(), 1);
0476:                Array.set(nots, 0, not);
0477:
0478:                Object obj = instantiate("javax.management.MBeanInfo",
0479:                        new Class[] { String.class, String.class,
0480:                                atts.getClass(), cons.getClass(),
0481:                                ops.getClass(), nots.getClass() },
0482:                        new Object[] { "className", "description", atts, cons,
0483:                                ops, nots });
0484:                try {
0485:                    Object result = runTest(obj);
0486:                    assertEquals(obj.toString(), result.toString());
0487:                } catch (java.io.InvalidClassException e) {
0488:                    fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 "
0489:                            + "The real error is in MBeanAttributeInfo");
0490:                }
0491:            }
0492:
0493:            public void testMBeanNotificationInfo() throws Exception {
0494:                String[] types = { "type1", "type2" };
0495:                Object obj = instantiate(
0496:                        "javax.management.MBeanNotificationInfo", new Class[] {
0497:                                types.getClass(), String.class, String.class },
0498:                        new Object[] { types, "name", "description" });
0499:                Object result = runTest(obj);
0500:                assertEquals(obj.toString(), result.toString());
0501:            }
0502:
0503:            public void testMBeanOperationInfo() throws Exception {
0504:                Object parm = instantiate(
0505:                        "javax.management.MBeanParameterInfo", new Class[] {
0506:                                String.class, String.class, String.class },
0507:                        new Object[] { "name", "type", "description" });
0508:                Object array = Array.newInstance(parm.getClass(), 1);
0509:                Array.set(array, 0, parm);
0510:                Class clazz = loadClass("javax.management.MBeanOperationInfo");
0511:                Integer impact = new Integer(clazz.getField("ACTION").getInt(
0512:                        null));
0513:                Object obj = instantiate("javax.management.MBeanOperationInfo",
0514:                        new Class[] { String.class, String.class,
0515:                                array.getClass(), String.class, Integer.TYPE },
0516:                        new Object[] { "name", "description", array, "type",
0517:                                impact });
0518:                Object result = runTest(obj);
0519:                assertEquals(obj.toString(), result.toString());
0520:            }
0521:
0522:            public void testMBeanParameterInfo() throws Exception {
0523:                Object obj = instantiate(
0524:                        "javax.management.MBeanParameterInfo",
0525:                        new Class[] { String.class, String.class, String.class },
0526:                        new Object[] { "name", "type", "description" });
0527:                Object result = runTest(obj);
0528:                assertEquals(obj.toString(), result.toString());
0529:            }
0530:
0531:            public void testMBeanRegistrationException() throws Exception {
0532:                Object obj = instantiate(
0533:                        "javax.management.MBeanRegistrationException",
0534:                        new Class[] { Exception.class, String.class },
0535:                        new Object[] { new Exception("Cause"), "message" });
0536:                Object result = runTest(obj);
0537:                assertEquals(obj.toString(), result.toString());
0538:            }
0539:
0540:            public void testMBeanServerNotification() throws Exception {
0541:                Object objectName = instantiate("javax.management.ObjectName",
0542:                        new Class[] { String.class },
0543:                        new Object[] { "domain:x=y" });
0544:
0545:                Class clazz = loadClass("javax.management.MBeanServerNotification");
0546:                String type = (String) clazz.getField(
0547:                        "REGISTRATION_NOTIFICATION").get(null);
0548:
0549:                Object obj = instantiate(
0550:                        "javax.management.MBeanServerNotification",
0551:                        new Class[] { String.class, Object.class, Long.TYPE,
0552:                                objectName.getClass() }, new Object[] { type,
0553:                                "source", new Long(1), objectName });
0554:                Object result = runTest(obj);
0555:                assertEquals(obj.toString(), result.toString());
0556:            }
0557:
0558:            public void testMBeanServerNotificationFilter() throws Exception {
0559:                Object objectName = instantiate("javax.management.ObjectName",
0560:                        new Class[] { String.class },
0561:                        new Object[] { "domain:x=y" });
0562:                Object obj = instantiate(
0563:                        "javax.management.relation.MBeanServerNotificationFilter",
0564:                        new Class[0], new Object[0]);
0565:                Method method = obj.getClass().getMethod("enableType",
0566:                        new Class[] { String.class });
0567:                method.invoke(obj, new Object[] { "prefix" });
0568:                method = obj.getClass().getMethod("enableObjectName",
0569:                        new Class[] { objectName.getClass() });
0570:                method.invoke(obj, new Object[] { objectName });
0571:                Object result = runTest(obj);
0572:                assertEquals(obj.toString(), result.toString());
0573:            }
0574:
0575:            public void testMBeanServerPermission() throws Exception {
0576:                if (SerializationSUITE.form < 11)
0577:                    return;
0578:                Object obj = instantiate(
0579:                        "javax.management.MBeanServerPermission",
0580:                        new Class[] { String.class }, new Object[] { "*" });
0581:                Object result = runTest(obj);
0582:                assertEquals(obj.toString(), result.toString());
0583:            }
0584:
0585:            public void testModelMBeanAttributeInfo() throws Exception {
0586:                Object obj = instantiate(
0587:                        "javax.management.modelmbean.ModelMBeanAttributeInfo",
0588:                        new Class[] { String.class, String.class, String.class,
0589:                                Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
0590:                        new Object[] { "name", "type", "description",
0591:                                new Boolean(true), new Boolean(true),
0592:                                new Boolean(false) });
0593:                try {
0594:                    Object result = runTest(obj);
0595:                    assertEquals(obj.toString(), result.toString());
0596:                } catch (java.io.InvalidClassException e) {
0597:                    fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
0598:                }
0599:            }
0600:
0601:            /**
0602:             * @todo equals test
0603:             */
0604:            public void testModelMBeanConstructorInfo() throws Exception {
0605:                Object parm = instantiate(
0606:                        "javax.management.MBeanParameterInfo", new Class[] {
0607:                                String.class, String.class, String.class },
0608:                        new Object[] { "name", "type", "description" });
0609:                Object array = Array.newInstance(parm.getClass(), 1);
0610:                Array.set(array, 0, parm);
0611:                Object obj = instantiate(
0612:                        "javax.management.modelmbean.ModelMBeanConstructorInfo",
0613:                        new Class[] { String.class, String.class,
0614:                                array.getClass() }, new Object[] { "name",
0615:                                "description", array });
0616:                Object result = runTest(obj);
0617:            }
0618:
0619:            /**
0620:             * @todo equals test
0621:             */
0622:            public void testModelMBeanInfoSupport() throws Exception {
0623:                Object parm = instantiate(
0624:                        "javax.management.MBeanParameterInfo", new Class[] {
0625:                                String.class, String.class, String.class },
0626:                        new Object[] { "name", "type", "description" });
0627:                Object parms = Array.newInstance(parm.getClass(), 1);
0628:                Array.set(parms, 0, parm);
0629:
0630:                Object att = instantiate(
0631:                        "javax.management.modelmbean.ModelMBeanAttributeInfo",
0632:                        new Class[] { String.class, String.class, String.class,
0633:                                Boolean.TYPE, Boolean.TYPE, Boolean.TYPE },
0634:                        new Object[] { "name", "type", "description",
0635:                                new Boolean(true), new Boolean(true),
0636:                                new Boolean(false) });
0637:                Object atts = Array.newInstance(att.getClass(), 1);
0638:                Array.set(atts, 0, att);
0639:
0640:                Object con = instantiate(
0641:                        "javax.management.modelmbean.ModelMBeanConstructorInfo",
0642:                        new Class[] { String.class, String.class,
0643:                                parms.getClass() }, new Object[] { "name",
0644:                                "description", parms });
0645:                Object cons = Array.newInstance(con.getClass(), 1);
0646:                Array.set(cons, 0, con);
0647:
0648:                Class clazz = loadClass("javax.management.modelmbean.ModelMBeanOperationInfo");
0649:                Integer impact = new Integer(clazz.getField("ACTION").getInt(
0650:                        null));
0651:                Object op = instantiate(
0652:                        "javax.management.modelmbean.ModelMBeanOperationInfo",
0653:                        new Class[] { String.class, String.class,
0654:                                parms.getClass(), String.class, Integer.TYPE },
0655:                        new Object[] { "name", "description", parms, "type",
0656:                                impact });
0657:                Object ops = Array.newInstance(op.getClass(), 1);
0658:                Array.set(ops, 0, op);
0659:
0660:                String[] types = { "type1", "type2" };
0661:                Object not = instantiate(
0662:                        "javax.management.modelmbean.ModelMBeanNotificationInfo",
0663:                        new Class[] { types.getClass(), String.class,
0664:                                String.class }, new Object[] { types, "name",
0665:                                "description" });
0666:                Object nots = Array.newInstance(not.getClass(), 1);
0667:                Array.set(nots, 0, not);
0668:
0669:                Object obj = instantiate(
0670:                        "javax.management.modelmbean.ModelMBeanInfoSupport",
0671:                        new Class[] { String.class, String.class,
0672:                                atts.getClass(), cons.getClass(),
0673:                                ops.getClass(), nots.getClass() },
0674:                        new Object[] { "className", "description", atts, cons,
0675:                                ops, nots });
0676:                try {
0677:                    Object result = runTest(obj);
0678:                } catch (java.io.InvalidClassException e) {
0679:                    fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
0680:                }
0681:            }
0682:
0683:            /**
0684:             * @todo equals test
0685:             */
0686:            public void testModelMBeanNotificationInfo() throws Exception {
0687:                String[] types = { "type1", "type2" };
0688:                Object obj = instantiate(
0689:                        "javax.management.modelmbean.ModelMBeanNotificationInfo",
0690:                        new Class[] { types.getClass(), String.class,
0691:                                String.class }, new Object[] { types, "name",
0692:                                "description" });
0693:                try {
0694:                    Object result = runTest(obj);
0695:                } catch (java.io.StreamCorruptedException e) {
0696:                    fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
0697:                }
0698:            }
0699:
0700:            /**
0701:             * @todo equals test
0702:             */
0703:            public void testModelMBeanOperationInfo() throws Exception {
0704:                Object parm = instantiate(
0705:                        "javax.management.MBeanParameterInfo", new Class[] {
0706:                                String.class, String.class, String.class },
0707:                        new Object[] { "name", "type", "description" });
0708:                Object array = Array.newInstance(parm.getClass(), 1);
0709:                Array.set(array, 0, parm);
0710:                Class clazz = loadClass("javax.management.MBeanOperationInfo");
0711:                Integer impact = new Integer(clazz.getField("ACTION").getInt(
0712:                        null));
0713:                Object obj = instantiate(
0714:                        "javax.management.modelmbean.ModelMBeanOperationInfo",
0715:                        new Class[] { String.class, String.class,
0716:                                array.getClass(), String.class, Integer.TYPE },
0717:                        new Object[] { "name", "description", array, "type",
0718:                                impact });
0719:                try {
0720:                    Object result = runTest(obj);
0721:                    assertEquals(obj.toString(), result.toString());
0722:                } catch (java.io.StreamCorruptedException e) {
0723:                    fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 ");
0724:                }
0725:            }
0726:
0727:            /**
0728:             * @todo the constructor is package private
0729:             * Actually tested by temporarily making the constructor public
0730:             */
0731:            public void testMonitorNotification() throws Exception {
0732:                /*****
0733:                 Object monitorName = instantiate(
0734:                 "javax.management.ObjectName",
0735:                 new Class[] { String.class },
0736:                 new Object[] { "monitor:x=y" }
0737:                 );
0738:                 Object objectName = instantiate(
0739:                 "javax.management.ObjectName",
0740:                 new Class[] { String.class },
0741:                 new Object[] { "domain:x=y" }
0742:                 );
0743:                 Object obj = instantiate(
0744:                 "javax.management.monitor.MonitorNotification",
0745:                 new Class[] { String.class, Object.class, Long.TYPE, Long.TYPE,
0746:                 String.class, Object.class, String.class, 
0747:                 objectName.getClass(), Object.class },
0748:                 new Object[] { "type", monitorName, new Long(1), new Long(2),
0749:                 "message", "derivedGauge", "attribute", objectName,
0750:                 "trigger"}
0751:                 );
0752:                 Object result = runTest(obj);
0753:                 assertEquals(obj.toString(), result.toString());
0754:                 *****/
0755:            }
0756:
0757:            public void testMonitorSettingException() throws Exception {
0758:                Object obj = instantiate(
0759:                        "javax.management.monitor.MonitorSettingException",
0760:                        new Class[] { String.class },
0761:                        new Object[] { "message" });
0762:                Object result = runTest(obj);
0763:                assertEquals(obj.toString(), result.toString());
0764:            }
0765:
0766:            public void testNotCompliantMBeanException() throws Exception {
0767:                Object obj = instantiate(
0768:                        "javax.management.NotCompliantMBeanException",
0769:                        new Class[] { String.class },
0770:                        new Object[] { "message" });
0771:                Object result = runTest(obj);
0772:                assertEquals(obj.toString(), result.toString());
0773:            }
0774:
0775:            public void testNotification() throws Exception {
0776:                Object objectName = instantiate("javax.management.ObjectName",
0777:                        new Class[] { String.class },
0778:                        new Object[] { "domain:x=y" });
0779:                Object obj = instantiate("javax.management.Notification",
0780:                        new Class[] { String.class, Object.class, Long.TYPE,
0781:                                Long.TYPE, String.class }, new Object[] {
0782:                                "type", objectName, new Long(1), new Long(2),
0783:                                "message" });
0784:                Object result = runTest(obj);
0785:                assertEquals(obj.toString(), result.toString());
0786:            }
0787:
0788:            /**
0789:             * @todo equals tests
0790:             */
0791:            public void testNotificationFilterSupport() throws Exception {
0792:                Object obj = instantiate(
0793:                        "javax.management.NotificationFilterSupport",
0794:                        new Class[0], new Object[0]);
0795:                Method method = obj.getClass().getMethod("enableType",
0796:                        new Class[] { String.class });
0797:                method.invoke(obj, new Object[] { "prefix" });
0798:                Object result = runTest(obj);
0799:            }
0800:
0801:            public void testObjectInstance() throws Exception {
0802:                Object objectName = instantiate("javax.management.ObjectName",
0803:                        new Class[] { String.class },
0804:                        new Object[] { "domain:x=y" });
0805:                Object obj = instantiate("javax.management.ObjectInstance",
0806:                        new Class[] { objectName.getClass(), String.class },
0807:                        new Object[] { objectName, "DummyClass" });
0808:                Object result = runTest(obj);
0809:                assertEquals(obj, result);
0810:            }
0811:
0812:            public void testObjectName() throws Exception {
0813:                Object obj = instantiate("javax.management.ObjectName",
0814:                        new Class[] { String.class },
0815:                        new Object[] { "domain:x=y" });
0816:                Object result = runTest(obj);
0817:                assertEquals(obj, result);
0818:            }
0819:
0820:            public void testObjectNamePattern() throws Exception {
0821:                Object obj = instantiate("javax.management.ObjectName",
0822:                        new Class[] { String.class },
0823:                        new Object[] { "domain*:x=y" });
0824:                Object result = runTest(obj);
0825:                assertEquals(obj, result);
0826:            }
0827:
0828:            public void testObjectNamePropertyPattern() throws Exception {
0829:                Object obj = instantiate("javax.management.ObjectName",
0830:                        new Class[] { String.class },
0831:                        new Object[] { "domain:x=y,*" });
0832:                Object result = runTest(obj);
0833:                assertEquals(obj, result);
0834:            }
0835:
0836:            public void testObjectNameRawPropertyPattern() throws Exception {
0837:                Object obj = instantiate("javax.management.ObjectName",
0838:                        new Class[] { String.class },
0839:                        new Object[] { "domain:*" });
0840:                Object result = runTest(obj);
0841:                assertEquals(obj, result);
0842:            }
0843:
0844:            public void testOpenDataException() throws Exception {
0845:                if (SerializationSUITE.form < 11)
0846:                    return;
0847:                Object obj = instantiate(
0848:                        "javax.management.openmbean.OpenDataException",
0849:                        new Class[] { String.class },
0850:                        new Object[] { "message" });
0851:                Object result = runTest(obj);
0852:                assertEquals(obj.toString(), result.toString());
0853:            }
0854:
0855:            public void testOpenMBeanAttributeInfoSupportMinMax()
0856:                    throws Exception {
0857:                if (SerializationSUITE.form < 11)
0858:                    return;
0859:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
0860:                Object elementType = clazz.getField("INTEGER").get(null);
0861:
0862:                Object obj = instantiate(
0863:                        "javax.management.openmbean.OpenMBeanAttributeInfoSupport",
0864:                        new Class[] {
0865:                                String.class,
0866:                                String.class,
0867:                                loadClass("javax.management.openmbean.OpenType"),
0868:                                boolean.class, boolean.class, boolean.class,
0869:                                Object.class, Comparable.class,
0870:                                Comparable.class }, new Object[] { "name",
0871:                                "description", elementType, new Boolean(true),
0872:                                new Boolean(true), new Boolean(false),
0873:                                new Integer(12), new Integer(11),
0874:                                new Integer(13) });
0875:                Object result = runTest(obj);
0876:                assertEquals(obj, result);
0877:            }
0878:
0879:            public void testOpenMBeanAttributeInfoSupportLegal()
0880:                    throws Exception {
0881:                if (SerializationSUITE.form < 11)
0882:                    return;
0883:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
0884:                Object elementType = clazz.getField("INTEGER").get(null);
0885:
0886:                Object obj = instantiate(
0887:                        "javax.management.openmbean.OpenMBeanAttributeInfoSupport",
0888:                        new Class[] {
0889:                                String.class,
0890:                                String.class,
0891:                                loadClass("javax.management.openmbean.OpenType"),
0892:                                boolean.class, boolean.class, boolean.class,
0893:                                Object.class, Object[].class }, new Object[] {
0894:                                "name",
0895:                                "description",
0896:                                elementType,
0897:                                new Boolean(true),
0898:                                new Boolean(true),
0899:                                new Boolean(false),
0900:                                new Integer(12),
0901:                                new Integer[] { new Integer(12),
0902:                                        new Integer(13) } });
0903:                Object result = runTest(obj);
0904:                assertEquals(obj, result);
0905:            }
0906:
0907:            public void testOpenMBeanConstructorInfoSupport() throws Exception {
0908:                if (SerializationSUITE.form < 11)
0909:                    return;
0910:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
0911:                Object elementType = clazz.getField("INTEGER").get(null);
0912:
0913:                Object parmInfo = instantiate(
0914:                        "javax.management.openmbean.OpenMBeanParameterInfoSupport",
0915:                        new Class[] {
0916:                                String.class,
0917:                                String.class,
0918:                                loadClass("javax.management.openmbean.OpenType"),
0919:                                Object.class, Object[].class }, new Object[] {
0920:                                "name",
0921:                                "description",
0922:                                elementType,
0923:                                new Integer(12),
0924:                                new Integer[] { new Integer(12),
0925:                                        new Integer(13) } });
0926:                Object array = Array.newInstance(parmInfo.getClass(), 1);
0927:                Array.set(array, 0, parmInfo);
0928:
0929:                Object obj = instantiate(
0930:                        "javax.management.openmbean.OpenMBeanConstructorInfoSupport",
0931:                        new Class[] {
0932:                                String.class,
0933:                                String.class,
0934:                                loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;") },
0935:                        new Object[] { "name", "description", array });
0936:                Object result = runTest(obj);
0937:                assertEquals(obj, result);
0938:            }
0939:
0940:            public void testOpenMBeanInfoSupport() throws Exception {
0941:                if (SerializationSUITE.form < 11)
0942:                    return;
0943:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
0944:                Object elementType = clazz.getField("INTEGER").get(null);
0945:
0946:                Object parmInfo = instantiate(
0947:                        "javax.management.openmbean.OpenMBeanParameterInfoSupport",
0948:                        new Class[] {
0949:                                String.class,
0950:                                String.class,
0951:                                loadClass("javax.management.openmbean.OpenType"),
0952:                                Object.class, Object[].class }, new Object[] {
0953:                                "name",
0954:                                "description",
0955:                                elementType,
0956:                                new Integer(12),
0957:                                new Integer[] { new Integer(12),
0958:                                        new Integer(13) } });
0959:                Object parmArray = Array.newInstance(parmInfo.getClass(), 1);
0960:                Array.set(parmArray, 0, parmInfo);
0961:
0962:                Object attInfo = instantiate(
0963:                        "javax.management.openmbean.OpenMBeanAttributeInfoSupport",
0964:                        new Class[] {
0965:                                String.class,
0966:                                String.class,
0967:                                loadClass("javax.management.openmbean.OpenType"),
0968:                                boolean.class, boolean.class, boolean.class,
0969:                                Object.class, Object[].class }, new Object[] {
0970:                                "name",
0971:                                "description",
0972:                                elementType,
0973:                                new Boolean(true),
0974:                                new Boolean(true),
0975:                                new Boolean(false),
0976:                                new Integer(12),
0977:                                new Integer[] { new Integer(12),
0978:                                        new Integer(13) } });
0979:
0980:                Object conInfo = instantiate(
0981:                        "javax.management.openmbean.OpenMBeanConstructorInfoSupport",
0982:                        new Class[] {
0983:                                String.class,
0984:                                String.class,
0985:                                loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;") },
0986:                        new Object[] { "name", "description", parmArray });
0987:
0988:                clazz = loadClass("javax.management.MBeanOperationInfo");
0989:                Object impact = clazz.getField("INFO").get(null);
0990:
0991:                Object opInfo = instantiate(
0992:                        "javax.management.openmbean.OpenMBeanOperationInfoSupport",
0993:                        new Class[] {
0994:                                String.class,
0995:                                String.class,
0996:                                loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;"),
0997:                                loadClass("javax.management.openmbean.OpenType"),
0998:                                int.class }, new Object[] { "name",
0999:                                "description", parmArray, elementType, impact });
1000:
1001:                String[] types = { "type1", "type2" };
1002:                Object notInfo = instantiate(
1003:                        "javax.management.MBeanNotificationInfo", new Class[] {
1004:                                types.getClass(), String.class, String.class },
1005:                        new Object[] { types, "name", "description" });
1006:
1007:                Object attArray = Array.newInstance(attInfo.getClass(), 1);
1008:                Array.set(attArray, 0, attInfo);
1009:
1010:                Object conArray = Array.newInstance(conInfo.getClass(), 1);
1011:                Array.set(conArray, 0, conInfo);
1012:
1013:                Object opArray = Array.newInstance(opInfo.getClass(), 1);
1014:                Array.set(opArray, 0, opInfo);
1015:
1016:                Object notArray = Array.newInstance(notInfo.getClass(), 1);
1017:                Array.set(notArray, 0, notInfo);
1018:
1019:                Object obj = instantiate(
1020:                        "javax.management.openmbean.OpenMBeanInfoSupport",
1021:                        new Class[] {
1022:                                String.class,
1023:                                String.class,
1024:                                loadClass("[Ljavax.management.openmbean.OpenMBeanAttributeInfo;"),
1025:                                loadClass("[Ljavax.management.openmbean.OpenMBeanConstructorInfo;"),
1026:                                loadClass("[Ljavax.management.openmbean.OpenMBeanOperationInfo;"),
1027:                                loadClass("[Ljavax.management.MBeanNotificationInfo;") },
1028:                        new Object[] { "classname", "description", attArray,
1029:                                conArray, opArray, notArray });
1030:
1031:                Object result = runTest(obj);
1032:                assertEquals(obj.toString(), result.toString());
1033:            }
1034:
1035:            public void testOpenMBeanOperationInfoSupport() throws Exception {
1036:                if (SerializationSUITE.form < 11)
1037:                    return;
1038:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
1039:                Object elementType = clazz.getField("INTEGER").get(null);
1040:
1041:                Object parmInfo = instantiate(
1042:                        "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1043:                        new Class[] {
1044:                                String.class,
1045:                                String.class,
1046:                                loadClass("javax.management.openmbean.OpenType"),
1047:                                Object.class, Object[].class }, new Object[] {
1048:                                "name",
1049:                                "description",
1050:                                elementType,
1051:                                new Integer(12),
1052:                                new Integer[] { new Integer(12),
1053:                                        new Integer(13) } });
1054:                Object array = Array.newInstance(parmInfo.getClass(), 1);
1055:                Array.set(array, 0, parmInfo);
1056:
1057:                clazz = loadClass("javax.management.MBeanOperationInfo");
1058:                Object impact = clazz.getField("INFO").get(null);
1059:
1060:                Object obj = instantiate(
1061:                        "javax.management.openmbean.OpenMBeanOperationInfoSupport",
1062:                        new Class[] {
1063:                                String.class,
1064:                                String.class,
1065:                                loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;"),
1066:                                loadClass("javax.management.openmbean.OpenType"),
1067:                                int.class }, new Object[] { "name",
1068:                                "description", array, elementType, impact });
1069:                Object result = runTest(obj);
1070:                assertEquals(obj, result);
1071:            }
1072:
1073:            public void testOpenMBeanParameterInfoSupportMinMax()
1074:                    throws Exception {
1075:                if (SerializationSUITE.form < 11)
1076:                    return;
1077:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
1078:                Object elementType = clazz.getField("INTEGER").get(null);
1079:
1080:                Object obj = instantiate(
1081:                        "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1082:                        new Class[] {
1083:                                String.class,
1084:                                String.class,
1085:                                loadClass("javax.management.openmbean.OpenType"),
1086:                                Object.class, Comparable.class,
1087:                                Comparable.class }, new Object[] { "name",
1088:                                "description", elementType, new Integer(12),
1089:                                new Integer(11), new Integer(13) });
1090:                Object result = runTest(obj);
1091:                assertEquals(obj, result);
1092:            }
1093:
1094:            public void testOpenMBeanParameterInfoSupportLegal()
1095:                    throws Exception {
1096:                if (SerializationSUITE.form < 11)
1097:                    return;
1098:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
1099:                Object elementType = clazz.getField("INTEGER").get(null);
1100:
1101:                Object obj = instantiate(
1102:                        "javax.management.openmbean.OpenMBeanParameterInfoSupport",
1103:                        new Class[] {
1104:                                String.class,
1105:                                String.class,
1106:                                loadClass("javax.management.openmbean.OpenType"),
1107:                                Object.class, Object[].class }, new Object[] {
1108:                                "name",
1109:                                "description",
1110:                                elementType,
1111:                                new Integer(12),
1112:                                new Integer[] { new Integer(12),
1113:                                        new Integer(13) } });
1114:                Object result = runTest(obj);
1115:                assertEquals(obj, result);
1116:            }
1117:
1118:            public void testOperationsException() throws Exception {
1119:                Object obj = instantiate(
1120:                        "javax.management.OperationsException",
1121:                        new Class[] { String.class },
1122:                        new Object[] { "message" });
1123:                Object result = runTest(obj);
1124:                assertEquals(obj.toString(), result.toString());
1125:            }
1126:
1127:            public void testReflectionException() throws Exception {
1128:                Object obj = instantiate(
1129:                        "javax.management.ReflectionException", new Class[] {
1130:                                Exception.class, String.class }, new Object[] {
1131:                                new Exception("Cause"), "message" });
1132:                Object result = runTest(obj);
1133:                assertEquals(obj.toString(), result.toString());
1134:            }
1135:
1136:            public void testRelationException() throws Exception {
1137:                Object obj = instantiate(
1138:                        "javax.management.relation.RelationException",
1139:                        new Class[] { String.class },
1140:                        new Object[] { "message" });
1141:                Object result = runTest(obj);
1142:                assertEquals(obj.toString(), result.toString());
1143:            }
1144:
1145:            public void testRelationNotFoundException() throws Exception {
1146:                Object obj = instantiate(
1147:                        "javax.management.relation.RelationNotFoundException",
1148:                        new Class[] { String.class },
1149:                        new Object[] { "message" });
1150:                Object result = runTest(obj);
1151:                assertEquals(obj.toString(), result.toString());
1152:            }
1153:
1154:            public void testRelationNotification() throws Exception {
1155:                Object objectName = instantiate("javax.management.ObjectName",
1156:                        new Class[] { String.class },
1157:                        new Object[] { "domain:x=y" });
1158:                Class clazz = loadClass("javax.management.relation.RelationNotification");
1159:                String type = (String) clazz.getField("RELATION_BASIC_UPDATE")
1160:                        .get(null);
1161:                ArrayList newValue = new ArrayList();
1162:                newValue.add(objectName);
1163:                ArrayList oldValue = new ArrayList();
1164:                oldValue.add(objectName);
1165:                Object obj = instantiate(
1166:                        "javax.management.relation.RelationNotification",
1167:                        new Class[] { String.class, Object.class, Long.TYPE,
1168:                                Long.TYPE, String.class, String.class,
1169:                                String.class, objectName.getClass(),
1170:                                String.class, List.class, List.class },
1171:                        new Object[] { type, objectName, new Long(1),
1172:                                new Long(2), "message", "relationId",
1173:                                "relationType", objectName, "roleName",
1174:                                newValue, oldValue });
1175:                Object result = runTest(obj);
1176:                assertEquals(obj.toString(), result.toString());
1177:            }
1178:
1179:            public void testRelationServiceNotRegisteredException()
1180:                    throws Exception {
1181:                Object obj = instantiate(
1182:                        "javax.management.relation.RelationServiceNotRegisteredException",
1183:                        new Class[] { String.class },
1184:                        new Object[] { "message" });
1185:                Object result = runTest(obj);
1186:                assertEquals(obj.toString(), result.toString());
1187:            }
1188:
1189:            public void testRelationTypeNotFoundException() throws Exception {
1190:                Object obj = instantiate(
1191:                        "javax.management.relation.RelationTypeNotFoundException",
1192:                        new Class[] { String.class },
1193:                        new Object[] { "message" });
1194:                Object result = runTest(obj);
1195:                assertEquals(obj.toString(), result.toString());
1196:            }
1197:
1198:            /**
1199:             * @todo equals test
1200:             */
1201:            public void testRelationTypeSupport() throws Exception {
1202:                Object roleInfo = instantiate(
1203:                        "javax.management.relation.RoleInfo",
1204:                        new Class[] { String.class, String.class, Boolean.TYPE,
1205:                                Boolean.TYPE, Integer.TYPE, Integer.TYPE,
1206:                                String.class },
1207:                        new Object[] { "name",
1208:                                "test.serialization.support.Trivial",
1209:                                new Boolean(true), new Boolean(true),
1210:                                new Integer(10), new Integer(20), "descritpion" });
1211:                Object array = Array.newInstance(roleInfo.getClass(), 1);
1212:                Array.set(array, 0, roleInfo);
1213:                Object obj = instantiate(
1214:                        "javax.management.relation.RelationTypeSupport",
1215:                        new Class[] { String.class, array.getClass() },
1216:                        new Object[] { "name", array });
1217:                Object result = runTest(obj);
1218:            }
1219:
1220:            public void testRole() throws Exception {
1221:                Object objectName = instantiate("javax.management.ObjectName",
1222:                        new Class[] { String.class },
1223:                        new Object[] { "domain:x=y" });
1224:                ArrayList list = new ArrayList();
1225:                list.add(objectName);
1226:                Object obj = instantiate("javax.management.relation.Role",
1227:                        new Class[] { String.class, List.class }, new Object[] {
1228:                                "name", list });
1229:                Object result = runTest(obj);
1230:                assertEquals(obj.toString(), result.toString());
1231:            }
1232:
1233:            public void testRoleInfo() throws Exception {
1234:                Object obj = instantiate(
1235:                        "javax.management.relation.RoleInfo",
1236:                        new Class[] { String.class, String.class, Boolean.TYPE,
1237:                                Boolean.TYPE, Integer.TYPE, Integer.TYPE,
1238:                                String.class },
1239:                        new Object[] { "name",
1240:                                "test.serialization.support.Trivial",
1241:                                new Boolean(true), new Boolean(true),
1242:                                new Integer(10), new Integer(20), "descritpion" });
1243:                Object result = runTest(obj);
1244:                assertEquals(obj.toString(), result.toString());
1245:            }
1246:
1247:            public void testRoleInfoNotFoundException() throws Exception {
1248:                Object obj = instantiate(
1249:                        "javax.management.relation.RoleInfoNotFoundException",
1250:                        new Class[] { String.class },
1251:                        new Object[] { "message" });
1252:                Object result = runTest(obj);
1253:                assertEquals(obj.toString(), result.toString());
1254:            }
1255:
1256:            public void testRoleList() throws Exception {
1257:                Object objectName = instantiate("javax.management.ObjectName",
1258:                        new Class[] { String.class },
1259:                        new Object[] { "domain:x=y" });
1260:                ArrayList list = new ArrayList();
1261:                list.add(objectName);
1262:                Object role = instantiate("javax.management.relation.Role",
1263:                        new Class[] { String.class, List.class }, new Object[] {
1264:                                "name", list });
1265:                list = new ArrayList();
1266:                list.add(role);
1267:                Object obj = instantiate("javax.management.relation.RoleList",
1268:                        new Class[] { List.class }, new Object[] { list });
1269:                Object result = runTest(obj);
1270:                assertEquals(obj.toString(), result.toString());
1271:            }
1272:
1273:            public void testRoleNotFoundException() throws Exception {
1274:                Object obj = instantiate(
1275:                        "javax.management.relation.RoleNotFoundException",
1276:                        new Class[] { String.class },
1277:                        new Object[] { "message" });
1278:                Object result = runTest(obj);
1279:                assertEquals(obj.toString(), result.toString());
1280:            }
1281:
1282:            public void testRoleResult() throws Exception {
1283:                Object objectName = instantiate("javax.management.ObjectName",
1284:                        new Class[] { String.class },
1285:                        new Object[] { "domain:x=y" });
1286:                ArrayList list = new ArrayList();
1287:                list.add(objectName);
1288:
1289:                Object resolved = instantiate("javax.management.relation.Role",
1290:                        new Class[] { String.class, List.class }, new Object[] {
1291:                                "name", list });
1292:                list = new ArrayList();
1293:                list.add(resolved);
1294:                Object resolvedList = instantiate(
1295:                        "javax.management.relation.RoleList",
1296:                        new Class[] { List.class }, new Object[] { list });
1297:
1298:                Class clazz = loadClass("javax.management.relation.RoleStatus");
1299:                Integer status = new Integer(clazz
1300:                        .getField("ROLE_NOT_READABLE").getInt(null));
1301:                Object unresolved = instantiate(
1302:                        "javax.management.relation.RoleUnresolved",
1303:                        new Class[] { String.class, List.class, Integer.TYPE },
1304:                        new Object[] { "name", list, status });
1305:                list = new ArrayList();
1306:                list.add(unresolved);
1307:                Object unresolvedList = instantiate(
1308:                        "javax.management.relation.RoleUnresolvedList",
1309:                        new Class[] { List.class }, new Object[] { list });
1310:                Object obj = instantiate(
1311:                        "javax.management.relation.RoleResult", new Class[] {
1312:                                resolvedList.getClass(),
1313:                                unresolvedList.getClass() }, new Object[] {
1314:                                resolvedList, unresolvedList });
1315:                Object result = runTest(obj);
1316:                assertEquals(obj.toString(), result.toString());
1317:            }
1318:
1319:            public void testRoleUnresolved() throws Exception {
1320:                Object objectName = instantiate("javax.management.ObjectName",
1321:                        new Class[] { String.class },
1322:                        new Object[] { "domain:x=y" });
1323:                ArrayList list = new ArrayList();
1324:                list.add(objectName);
1325:                Class clazz = loadClass("javax.management.relation.RoleStatus");
1326:                Integer status = new Integer(clazz
1327:                        .getField("ROLE_NOT_READABLE").getInt(null));
1328:                Object obj = instantiate(
1329:                        "javax.management.relation.RoleUnresolved",
1330:                        new Class[] { String.class, List.class, Integer.TYPE },
1331:                        new Object[] { "name", list, status });
1332:                Object result = runTest(obj);
1333:                assertEquals(obj.toString(), result.toString());
1334:            }
1335:
1336:            public void testRoleUnresolvedList() throws Exception {
1337:                Object objectName = instantiate("javax.management.ObjectName",
1338:                        new Class[] { String.class },
1339:                        new Object[] { "domain:x=y" });
1340:                ArrayList list = new ArrayList();
1341:                list.add(objectName);
1342:                Class clazz = loadClass("javax.management.relation.RoleStatus");
1343:                Integer status = new Integer(clazz
1344:                        .getField("ROLE_NOT_READABLE").getInt(null));
1345:                Object unresolved = instantiate(
1346:                        "javax.management.relation.RoleUnresolved",
1347:                        new Class[] { String.class, List.class, Integer.TYPE },
1348:                        new Object[] { "name", list, status });
1349:                list = new ArrayList();
1350:                list.add(unresolved);
1351:                Object obj = instantiate(
1352:                        "javax.management.relation.RoleUnresolvedList",
1353:                        new Class[] { List.class }, new Object[] { list });
1354:                Object result = runTest(obj);
1355:                assertEquals(obj.toString(), result.toString());
1356:            }
1357:
1358:            public void testRuntimeErrorException() throws Exception {
1359:                Object obj = instantiate(
1360:                        "javax.management.RuntimeErrorException", new Class[] {
1361:                                Error.class, String.class }, new Object[] {
1362:                                new Error("Cause"), "message" });
1363:                Object result = runTest(obj);
1364:                assertEquals(obj.toString(), result.toString());
1365:            }
1366:
1367:            public void testRuntimeMBeanException() throws Exception {
1368:                Object obj = instantiate(
1369:                        "javax.management.RuntimeMBeanException",
1370:                        new Class[] { RuntimeException.class, String.class },
1371:                        new Object[] { new RuntimeException("Cause"), "message" });
1372:                Object result = runTest(obj);
1373:                assertEquals(obj.toString(), result.toString());
1374:            }
1375:
1376:            public void testRuntimeOperationsException() throws Exception {
1377:                Object obj = instantiate(
1378:                        "javax.management.RuntimeOperationsException",
1379:                        new Class[] { RuntimeException.class, String.class },
1380:                        new Object[] { new RuntimeException("Cause"), "message" });
1381:                Object result = runTest(obj);
1382:                assertEquals(obj.toString(), result.toString());
1383:            }
1384:
1385:            public void testServiceNotFoundException() throws Exception {
1386:                Object obj = instantiate(
1387:                        "javax.management.ServiceNotFoundException",
1388:                        new Class[] { String.class },
1389:                        new Object[] { "message" });
1390:                Object result = runTest(obj);
1391:                assertEquals(obj.toString(), result.toString());
1392:            }
1393:
1394:            public void testSimpleType() throws Exception {
1395:                if (SerializationSUITE.form < 11)
1396:                    return;
1397:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
1398:                Object obj = clazz.getField("BIGDECIMAL").get(null);
1399:                Object result = runTest(obj);
1400:                assertTrue("Simple types should resolve to the same object",
1401:                        obj == result);
1402:            }
1403:
1404:            public void testStringValueExp() throws Exception {
1405:                Object obj = instantiate("javax.management.StringValueExp",
1406:                        new Class[] { String.class }, new Object[] { "attr" });
1407:                Object result = runTest(obj);
1408:                assertEquals(obj.toString(), result.toString());
1409:            }
1410:
1411:            public void testTabularDataSupport() throws Exception {
1412:                if (SerializationSUITE.form < 11)
1413:                    return;
1414:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
1415:                Object openType = clazz.getField("STRING").get(null);
1416:
1417:                Class elementClass = loadClass("javax.management.openmbean.OpenType");
1418:                Object array = Array.newInstance(elementClass, 2);
1419:                Array.set(array, 0, openType);
1420:                Array.set(array, 1, openType);
1421:
1422:                Object compositeType = instantiate(
1423:                        "javax.management.openmbean.CompositeType",
1424:                        new Class[] { String.class, String.class,
1425:                                String[].class, String[].class,
1426:                                array.getClass() }, new Object[] { "typeName",
1427:                                "description",
1428:                                new String[] { "name1", "name2" },
1429:                                new String[] { "desc1", "desc2" }, array });
1430:
1431:                Object tabularType = instantiate(
1432:                        "javax.management.openmbean.TabularType", new Class[] {
1433:                                String.class, String.class,
1434:                                compositeType.getClass(), String[].class },
1435:                        new Object[] { "typeName", "description",
1436:                                compositeType, new String[] { "name1" } });
1437:
1438:                Object obj = instantiate(
1439:                        "javax.management.openmbean.TabularDataSupport",
1440:                        new Class[] { tabularType.getClass() },
1441:                        new Object[] { tabularType });
1442:                Object result = runTest(obj);
1443:                assertEquals(obj, result);
1444:            }
1445:
1446:            public void testTabularType() throws Exception {
1447:                if (SerializationSUITE.form < 11)
1448:                    return;
1449:                Class clazz = loadClass("javax.management.openmbean.SimpleType");
1450:                Object openType = clazz.getField("STRING").get(null);
1451:
1452:                Class elementClass = loadClass("javax.management.openmbean.OpenType");
1453:                Object array = Array.newInstance(elementClass, 2);
1454:                Array.set(array, 0, openType);
1455:                Array.set(array, 1, openType);
1456:
1457:                Object compositeType = instantiate(
1458:                        "javax.management.openmbean.CompositeType",
1459:                        new Class[] { String.class, String.class,
1460:                                String[].class, String[].class,
1461:                                array.getClass() }, new Object[] { "typeName",
1462:                                "description",
1463:                                new String[] { "name1", "name2" },
1464:                                new String[] { "desc1", "desc2" }, array });
1465:
1466:                Object obj = instantiate(
1467:                        "javax.management.openmbean.TabularType", new Class[] {
1468:                                String.class, String.class,
1469:                                compositeType.getClass(), String[].class },
1470:                        new Object[] { "typeName", "description",
1471:                                compositeType, new String[] { "name1" } });
1472:
1473:                Object result = runTest(obj);
1474:                assertEquals(obj, result);
1475:            }
1476:
1477:            /**
1478:             * @todo ?
1479:             */
1480:            public void testTimerAlarmClockNotification() throws Exception {
1481:            }
1482:
1483:            public void testTimerNotification() throws Exception {
1484:                Object timerName = instantiate("javax.management.ObjectName",
1485:                        new Class[] { String.class },
1486:                        new Object[] { "timer:x=y" });
1487:                Object obj = instantiate(
1488:                        "javax.management.timer.TimerNotification",
1489:                        new Class[] { String.class, Object.class, Long.TYPE,
1490:                                Long.TYPE, String.class, Integer.class,
1491:                                Object.class }, new Object[] { "type",
1492:                                timerName, new Long(1), new Long(2), "message",
1493:                                new Integer(1), "user data" });
1494:                Object result = runTest(obj);
1495:                assertEquals(obj.toString(), result.toString());
1496:            }
1497:
1498:            public void testXMLParseException() throws Exception {
1499:                Object obj = instantiate(
1500:                        "javax.management.modelmbean.XMLParseException",
1501:                        new Class[] { Exception.class, String.class },
1502:                        new Object[] { new Exception("exception"), "message" });
1503:                Object result = runTest(obj);
1504:                assertEquals(obj.toString(), result.toString());
1505:            }
1506:
1507:            // Support -------------------------------------------------------
1508:
1509:            /**
1510:             * Instantiate an object using JBossMX.
1511:             */
1512:            private Object instantiate(String className, Class[] sig,
1513:                    Object[] parms) throws Exception {
1514:                Constructor cons = loadClass(className).getDeclaredConstructor(
1515:                        sig);
1516:                return cons.newInstance(parms);
1517:            }
1518:
1519:            /**
1520:             * Load a class using JBossMX.
1521:             */
1522:            private Class loadClass(String className) throws Exception {
1523:                return SerializationSUITE.jbossmx.loadClass(className);
1524:            }
1525:
1526:            /**
1527:             * Serialize from jbossmx to jmxri.
1528:             * Serialize from jmxri to jbossmx.
1529:             */
1530:            private Object runTest(Object obj) throws Exception {
1531:                ByteArrayOutputStream os = serializeJBoss(obj);
1532:                Object intermediate = deserializeRI(os);
1533:                os = serializeRI(intermediate);
1534:                return deserializeJBoss(os);
1535:            }
1536:
1537:            /**
1538:             * Dummy method wrapper for debugging.
1539:             */
1540:            private ByteArrayOutputStream serializeJBoss(Object obj)
1541:                    throws Exception {
1542:                return serialize(obj);
1543:            }
1544:
1545:            /**
1546:             * Dummy method wrapper for debugging.
1547:             */
1548:            private ByteArrayOutputStream serializeRI(Object obj)
1549:                    throws Exception {
1550:                return serialize(obj);
1551:            }
1552:
1553:            /**
1554:             * Dummy method wrapper for debugging.
1555:             */
1556:            private Object deserializeJBoss(ByteArrayOutputStream os)
1557:                    throws Exception {
1558:                return deserialize(SerializationSUITE.jbossmx, os);
1559:            }
1560:
1561:            /**
1562:             * Dummy method wrapper for debugging.
1563:             */
1564:            private Object deserializeRI(ByteArrayOutputStream os)
1565:                    throws Exception {
1566:                return deserialize(SerializationSUITE.jmxri, os);
1567:            }
1568:
1569:            /**
1570:             * Serialize the object.
1571:             */
1572:            private ByteArrayOutputStream serialize(Object obj)
1573:                    throws Exception {
1574:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
1575:                ObjectOutputStream oos = new ObjectOutputStream(baos);
1576:                oos.writeObject(obj);
1577:                return baos;
1578:            }
1579:
1580:            /**
1581:             * Deserialize the object.
1582:             */
1583:            private Object deserialize(ClassLoader cl,
1584:                    ByteArrayOutputStream baos) throws Exception {
1585:                ByteArrayInputStream bais = new ByteArrayInputStream(baos
1586:                        .toByteArray());
1587:                ObjectInputStream ois = new MyObjectInputStream(cl, bais);
1588:                return ois.readObject();
1589:            }
1590:
1591:            /**
1592:             * Custom inputstream to override classloading to the relevent
1593:             * jmx implementation
1594:             */
1595:            public class MyObjectInputStream extends ObjectInputStream {
1596:                ClassLoader cl;
1597:
1598:                public MyObjectInputStream(ClassLoader cl,
1599:                        ByteArrayInputStream is) throws IOException {
1600:                    super (is);
1601:                    this .cl = cl;
1602:                }
1603:
1604:                protected Class resolveClass(java.io.ObjectStreamClass osc)
1605:                        throws IOException, ClassNotFoundException {
1606:                    return cl.loadClass(osc.getName());
1607:                }
1608:            }
1609:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.