1 22 package org.jboss.test.jmx.serialization; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.ByteArrayOutputStream ; 26 import java.io.IOException ; 27 import java.io.ObjectInputStream ; 28 import java.io.ObjectOutputStream ; 29 import java.lang.reflect.Array ; 30 import java.lang.reflect.Constructor ; 31 import java.lang.reflect.Method ; 32 import java.util.ArrayList ; 33 import java.util.List ; 34 35 import junit.framework.TestCase; 36 37 44 public class SerializeTestCase 45 extends TestCase 46 { 47 49 51 54 public SerializeTestCase(String s) 55 { 56 super(s); 57 } 58 59 public void testArrayType() 60 throws Exception 61 { 62 if (SerializationSUITE.form < 11) 63 return; 64 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 65 Object elementType = clazz.getField("BIGDECIMAL").get(null); 66 Object obj = instantiate( 67 "javax.management.openmbean.ArrayType", 68 new Class [] { Integer.TYPE, 69 loadClass("javax.management.openmbean.OpenType") }, 70 new Object [] { new Integer (3), elementType } 71 ); 72 Object result = runTest(obj); 73 assertEquals(obj, result); 74 } 75 76 public void testAttribute() 77 throws Exception 78 { 79 Object obj = instantiate( 80 "javax.management.Attribute", 81 new Class [] { String .class, Object .class }, 82 new Object [] { "name", "value" } 83 ); 84 Object result = runTest(obj); 85 assertEquals(obj, result); 86 } 87 88 public void testAttributeChangeNotification() 89 throws Exception 90 { 91 Object obj = instantiate( 92 "javax.management.AttributeChangeNotification", 93 new Class [] { Object .class, Long.TYPE, Long.TYPE, 94 String .class, String .class, String .class, 95 Object .class, Object .class }, 96 new Object [] { "source", new Long (1), new Long (2), "message", "name", 97 "type", "old", "new" } 98 ); 99 Object result = runTest(obj); 100 assertEquals(obj.toString(), result.toString()); 101 } 102 103 public void testAttributeChangeNotificationFilter() 104 throws Exception 105 { 106 Object obj = instantiate( 107 "javax.management.AttributeChangeNotificationFilter", 108 new Class [0], 109 new Object [0] 110 ); 111 Method method = obj.getClass().getMethod("enableAttribute", 112 new Class [] { String .class }); 113 method.invoke(obj, new Object [] { "attribute" }); 114 Object result = runTest(obj); 115 assertEquals(obj.toString(), result.toString()); 116 } 117 118 public void testAttributeList() 119 throws Exception 120 { 121 Object obj = instantiate( 122 "javax.management.AttributeList", 123 new Class [0], 124 new Object [0] 125 ); 126 Object attr = instantiate( 127 "javax.management.Attribute", 128 new Class [] { String .class, Object .class }, 129 new Object [] { "name", "value" } 130 ); 131 Method method = obj.getClass().getMethod("add", 132 new Class [] { attr.getClass() }); 133 method.invoke(obj, new Object [] { attr }); 134 Object result = runTest(obj); 135 assertEquals(obj.toString(), result.toString()); 136 } 137 138 public void testAttributeNotFoundException() 139 throws Exception 140 { 141 Object obj = instantiate( 142 "javax.management.AttributeNotFoundException", 143 new Class [] { String .class }, 144 new Object [] { "message" } 145 ); 146 Object result = runTest(obj); 147 assertEquals(obj.toString(), result.toString()); 148 } 149 150 public void testAttributeValueExp() 151 throws Exception 152 { 153 Object obj = instantiate( 154 "javax.management.AttributeValueExp", 155 new Class [] { String .class }, 156 new Object [] { "attr" } 157 ); 158 Object result = runTest(obj); 159 assertEquals(obj.toString(), result.toString()); 160 } 161 162 public void testBadAttributeValueExpException() 163 throws Exception 164 { 165 Object obj = instantiate( 166 "javax.management.BadAttributeValueExpException", 167 new Class [] { Object .class }, 168 new Object [] { "value" } 169 ); 170 Object result = runTest(obj); 171 assertEquals(obj.toString(), result.toString()); 172 } 173 174 public void testBadBinaryOpValueExpException() 175 throws Exception 176 { 177 Object exp = instantiate( 178 "javax.management.AttributeValueExp", 179 new Class [] { String .class }, 180 new Object [] { "attr" } 181 ); 182 183 Object obj = instantiate( 184 "javax.management.BadBinaryOpValueExpException", 185 new Class [] { loadClass("javax.management.ValueExp") }, 186 new Object [] { exp } 187 ); 188 Object result = runTest(obj); 189 assertEquals(obj.toString(), result.toString()); 190 } 191 192 public void testBadStringOperationException() 193 throws Exception 194 { 195 Object obj = instantiate( 196 "javax.management.BadStringOperationException", 197 new Class [] { String .class }, 198 new Object [] { "message" } 199 ); 200 Object result = runTest(obj); 201 assertEquals(obj.toString(), result.toString()); 202 } 203 204 public void testCompositeDataSupport() 205 throws Exception 206 { 207 if (SerializationSUITE.form < 11) 208 return; 209 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 210 Object openType = clazz.getField("STRING").get(null); 211 212 Class elementClass = loadClass("javax.management.openmbean.OpenType"); 213 Object array = Array.newInstance(elementClass, 2); 214 Array.set(array, 0, openType); 215 Array.set(array, 1, openType); 216 217 Object compositeType = instantiate( 218 "javax.management.openmbean.CompositeType", 219 new Class [] { String .class, String .class, String [].class, String [].class, array.getClass() }, 220 new Object [] { "typeName", "description", new String [] { "name1", "name2" }, 221 new String [] { "desc1", "desc2" }, array } 222 ); 223 Object obj = instantiate( 224 "javax.management.openmbean.CompositeDataSupport", 225 new Class [] { compositeType.getClass(), String [].class, Object [].class }, 226 new Object [] { compositeType, new String [] { "name1", "name2" }, 227 new Object [] { "itemValue1", "itemValue2" } } 228 ); 229 Object result = runTest(obj); 230 assertEquals(obj, result); 231 } 232 233 public void testCompositeType() 234 throws Exception 235 { 236 if (SerializationSUITE.form < 11) 237 return; 238 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 239 Object openType = clazz.getField("STRING").get(null); 240 241 Class elementClass = loadClass("javax.management.openmbean.OpenType"); 242 Object array = Array.newInstance(elementClass, 2); 243 Array.set(array, 0, openType); 244 Array.set(array, 1, openType); 245 246 Object obj = instantiate( 247 "javax.management.openmbean.CompositeType", 248 new Class [] { String .class, String .class, String [].class, String [].class, array.getClass() }, 249 new Object [] { "typeName", "description", new String [] { "name1", "name2" }, 250 new String [] { "desc1", "desc2" }, array } 251 ); 252 Object result = runTest(obj); 253 assertEquals(obj, result); 254 } 255 256 public void testDescriptorSupport() 257 throws Exception 258 { 259 Object obj = instantiate( 260 "javax.management.modelmbean.DescriptorSupport", 261 new Class [] { new String [0].getClass(), new Object [0].getClass() }, 262 new Object [] { new String [] { "name1", "name2"}, 263 new Object [] { "value1", "value2" } } 264 ); 265 runTest(obj); 266 } 267 268 public void testInstanceAlreadyExistsException() 269 throws Exception 270 { 271 Object obj = instantiate( 272 "javax.management.InstanceAlreadyExistsException", 273 new Class [] { String .class }, 274 new Object [] { "message" } 275 ); 276 Object result = runTest(obj); 277 assertEquals(obj.toString(), result.toString()); 278 } 279 280 public void testInstanceNotFoundException() 281 throws Exception 282 { 283 Object obj = instantiate( 284 "javax.management.InstanceNotFoundException", 285 new Class [] { String .class }, 286 new Object [] { "message" } 287 ); 288 Object result = runTest(obj); 289 assertEquals(obj.toString(), result.toString()); 290 } 291 292 public void testIntrospectionException() 293 throws Exception 294 { 295 Object obj = instantiate( 296 "javax.management.IntrospectionException", 297 new Class [] { String .class }, 298 new Object [] { "message" } 299 ); 300 Object result = runTest(obj); 301 assertEquals(obj.toString(), result.toString()); 302 } 303 304 public void testInvalidApplicationException() 305 throws Exception 306 { 307 Object obj = instantiate( 308 "javax.management.InvalidApplicationException", 309 new Class [] { Object .class }, 310 new Object [] { "value" } 311 ); 312 Object result = runTest(obj); 313 assertEquals(obj.toString(), result.toString()); 314 } 315 316 public void testInvalidAttributeValueException() 317 throws Exception 318 { 319 Object obj = instantiate( 320 "javax.management.InvalidAttributeValueException", 321 new Class [] { String .class }, 322 new Object [] { "message" } 323 ); 324 Object result = runTest(obj); 325 assertEquals(obj.toString(), result.toString()); 326 } 327 328 public void testInvalidKeyException() 329 throws Exception 330 { 331 if (SerializationSUITE.form < 11) 332 return; 333 Object obj = instantiate( 334 "javax.management.openmbean.InvalidKeyException", 335 new Class [] { String .class }, 336 new Object [] { "message" } 337 ); 338 Object result = runTest(obj); 339 assertEquals(obj.toString(), result.toString()); 340 } 341 342 public void testInvalidOpenTypeException() 343 throws Exception 344 { 345 if (SerializationSUITE.form < 11) 346 return; 347 Object obj = instantiate( 348 "javax.management.openmbean.InvalidOpenTypeException", 349 new Class [] { String .class }, 350 new Object [] { "message" } 351 ); 352 Object result = runTest(obj); 353 assertEquals(obj.toString(), result.toString()); 354 } 355 356 public void testInvalidRelationIdException() 357 throws Exception 358 { 359 Object obj = instantiate( 360 "javax.management.relation.InvalidRelationIdException", 361 new Class [] { String .class }, 362 new Object [] { "message" } 363 ); 364 Object result = runTest(obj); 365 assertEquals(obj.toString(), result.toString()); 366 } 367 368 public void testInvalidRelationServiceException() 369 throws Exception 370 { 371 Object obj = instantiate( 372 "javax.management.relation.InvalidRelationServiceException", 373 new Class [] { String .class }, 374 new Object [] { "message" } 375 ); 376 Object result = runTest(obj); 377 assertEquals(obj.toString(), result.toString()); 378 } 379 380 public void testInvalidRelationTypeException() 381 throws Exception 382 { 383 Object obj = instantiate( 384 "javax.management.relation.InvalidRelationTypeException", 385 new Class [] { String .class }, 386 new Object [] { "message" } 387 ); 388 Object result = runTest(obj); 389 assertEquals(obj.toString(), result.toString()); 390 } 391 392 public void testInvalidRoleInfoException() 393 throws Exception 394 { 395 Object obj = instantiate( 396 "javax.management.relation.InvalidRoleInfoException", 397 new Class [] { String .class }, 398 new Object [] { "message" } 399 ); 400 Object result = runTest(obj); 401 assertEquals(obj.toString(), result.toString()); 402 } 403 404 public void testInvalidRoleValueException() 405 throws Exception 406 { 407 Object obj = instantiate( 408 "javax.management.relation.InvalidRoleValueException", 409 new Class [] { String .class }, 410 new Object [] { "message" } 411 ); 412 Object result = runTest(obj); 413 assertEquals(obj.toString(), result.toString()); 414 } 415 416 public void testInvalidTargetObjectTypeException() 417 throws Exception 418 { 419 Object obj = instantiate( 420 "javax.management.modelmbean.InvalidTargetObjectTypeException", 421 new Class [] { Exception .class, String .class }, 422 new Object [] { new Exception ("exception"), "message" } 423 ); 424 Object result = runTest(obj); 425 assertEquals(obj.toString(), result.toString()); 426 } 427 428 public void testKeyAlreadyExistsException() 429 throws Exception 430 { 431 if (SerializationSUITE.form < 11) 432 return; 433 Object obj = instantiate( 434 "javax.management.openmbean.KeyAlreadyExistsException", 435 new Class [] { String .class }, 436 new Object [] { "message" } 437 ); 438 Object result = runTest(obj); 439 assertEquals(obj.toString(), result.toString()); 440 } 441 442 public void testJMException() 443 throws Exception 444 { 445 Object obj = instantiate( 446 "javax.management.JMException", 447 new Class [] { String .class }, 448 new Object [] { "message" } 449 ); 450 Object result = runTest(obj); 451 assertEquals(obj.toString(), result.toString()); 452 } 453 454 public void testJMRuntimeException() 455 throws Exception 456 { 457 Object obj = instantiate( 458 "javax.management.JMRuntimeException", 459 new Class [] { String .class }, 460 new Object [] { "message" } 461 ); 462 Object result = runTest(obj); 463 assertEquals(obj.toString(), result.toString()); 464 } 465 466 public void testListenerNotFoundException() 467 throws Exception 468 { 469 Object obj = instantiate( 470 "javax.management.ListenerNotFoundException", 471 new Class [] { String .class }, 472 new Object [] { "message" } 473 ); 474 Object result = runTest(obj); 475 assertEquals(obj.toString(), result.toString()); 476 } 477 478 public void testMalformedObjectNameException() 479 throws Exception 480 { 481 Object obj = instantiate( 482 "javax.management.MalformedObjectNameException", 483 new Class [] { String .class }, 484 new Object [] { "message" } 485 ); 486 Object result = runTest(obj); 487 assertEquals(obj.toString(), result.toString()); 488 } 489 490 public void testMBeanAttributeInfo() 491 throws Exception 492 { 493 Object obj = instantiate( 494 "javax.management.MBeanAttributeInfo", 495 new Class [] { String .class, String .class, String .class, 496 Boolean.TYPE, Boolean.TYPE, Boolean.TYPE }, 497 new Object [] { "name", "type", "description", new Boolean (true), 498 new Boolean (true), new Boolean (false)} 499 ); 500 try 501 { 502 Object result = runTest(obj); 503 assertEquals(obj.toString(), result.toString()); 504 } 505 catch (java.io.InvalidClassException e) 506 { 507 fail("FAILS IN RI 1.1: Wrong serialization for form 1.0"); 508 } 509 } 510 511 public void testMBeanConstructorInfo() 512 throws Exception 513 { 514 Object parm = instantiate( 515 "javax.management.MBeanParameterInfo", 516 new Class [] { String .class, String .class, String .class }, 517 new Object [] { "name", "type", "description" } 518 ); 519 Object array = Array.newInstance(parm.getClass(), 1); 520 Array.set(array, 0, parm); 521 Object obj = instantiate( 522 "javax.management.MBeanConstructorInfo", 523 new Class [] { String .class, String .class, array.getClass() }, 524 new Object [] { "name", "description", array } 525 ); 526 Object result = runTest(obj); 527 assertEquals(obj.toString(), result.toString()); 528 } 529 530 public void testMBeanException() 531 throws Exception 532 { 533 Object obj = instantiate( 534 "javax.management.MBeanException", 535 new Class [] { Exception .class, String .class }, 536 new Object [] { new Exception ("Cause"), "message" } 537 ); 538 Object result = runTest(obj); 539 assertEquals(obj.toString(), result.toString()); 540 } 541 542 public void testMBeanFeatureInfo() 543 throws Exception 544 { 545 Object obj = instantiate( 546 "javax.management.MBeanFeatureInfo", 547 new Class [] { String .class, String .class }, 548 new Object [] { "name", "description" } 549 ); 550 Object result = runTest(obj); 551 assertEquals(obj.toString(), result.toString()); 552 } 553 554 public void testMBeanInfo() 555 throws Exception 556 { 557 Object parm = instantiate( 558 "javax.management.MBeanParameterInfo", 559 new Class [] { String .class, String .class, String .class }, 560 new Object [] { "name", "type", "description" } 561 ); 562 Object parms = Array.newInstance(parm.getClass(), 1); 563 Array.set(parms, 0, parm); 564 565 Object att = instantiate( 566 "javax.management.MBeanAttributeInfo", 567 new Class [] { String .class, String .class, String .class, 568 Boolean.TYPE, Boolean.TYPE, Boolean.TYPE }, 569 new Object [] { "name", "type", "description", new Boolean (true), 570 new Boolean (true), new Boolean (false)} 571 ); 572 Object atts = Array.newInstance(att.getClass(), 1); 573 Array.set(atts, 0, att); 574 575 Object con = instantiate( 576 "javax.management.MBeanConstructorInfo", 577 new Class [] { String .class, String .class, parms.getClass() }, 578 new Object [] { "name", "description", parms } 579 ); 580 Object cons = Array.newInstance(con.getClass(), 1); 581 Array.set(cons, 0, con); 582 583 Class clazz = loadClass("javax.management.MBeanOperationInfo"); 584 Integer impact = new Integer (clazz.getField("ACTION").getInt(null)); 585 Object op = instantiate( 586 "javax.management.MBeanOperationInfo", 587 new Class [] { String .class, String .class, parms.getClass(), 588 String .class, Integer.TYPE }, 589 new Object [] { "name", "description", parms, "type", impact } 590 ); 591 Object ops = Array.newInstance(op.getClass(), 1); 592 Array.set(ops, 0, op); 593 594 String [] types = { "type1", "type2" }; 595 Object not = instantiate( 596 "javax.management.MBeanNotificationInfo", 597 new Class [] { types.getClass(), String .class, String .class }, 598 new Object [] { types, "name", "description" } 599 ); 600 Object nots = Array.newInstance(not.getClass(), 1); 601 Array.set(nots, 0, not); 602 603 Object obj = instantiate( 604 "javax.management.MBeanInfo", 605 new Class [] { String .class, String .class, atts.getClass(), 606 cons.getClass(), ops.getClass(), nots.getClass() }, 607 new Object [] { "className", "description", atts, cons, ops, nots } 608 ); 609 try 610 { 611 Object result = runTest(obj); 612 assertEquals(obj.toString(), result.toString()); 613 } 614 catch (java.io.InvalidClassException e) 615 { 616 fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 " + 617 "The real error is in MBeanAttributeInfo"); 618 } 619 } 620 621 public void testMBeanNotificationInfo() 622 throws Exception 623 { 624 String [] types = { "type1", "type2" }; 625 Object obj = instantiate( 626 "javax.management.MBeanNotificationInfo", 627 new Class [] { types.getClass(), String .class, String .class }, 628 new Object [] { types, "name", "description" } 629 ); 630 Object result = runTest(obj); 631 assertEquals(obj.toString(), result.toString()); 632 } 633 634 public void testMBeanOperationInfo() 635 throws Exception 636 { 637 Object parm = instantiate( 638 "javax.management.MBeanParameterInfo", 639 new Class [] { String .class, String .class, String .class }, 640 new Object [] { "name", "type", "description" } 641 ); 642 Object array = Array.newInstance(parm.getClass(), 1); 643 Array.set(array, 0, parm); 644 Class clazz = loadClass("javax.management.MBeanOperationInfo"); 645 Integer impact = new Integer (clazz.getField("ACTION").getInt(null)); 646 Object obj = instantiate( 647 "javax.management.MBeanOperationInfo", 648 new Class [] { String .class, String .class, array.getClass(), 649 String .class, Integer.TYPE }, 650 new Object [] { "name", "description", array, "type", impact } 651 ); 652 Object result = runTest(obj); 653 assertEquals(obj.toString(), result.toString()); 654 } 655 656 public void testMBeanParameterInfo() 657 throws Exception 658 { 659 Object obj = instantiate( 660 "javax.management.MBeanParameterInfo", 661 new Class [] { String .class, String .class, String .class }, 662 new Object [] { "name", "type", "description" } 663 ); 664 Object result = runTest(obj); 665 assertEquals(obj.toString(), result.toString()); 666 } 667 668 public void testMBeanRegistrationException() 669 throws Exception 670 { 671 Object obj = instantiate( 672 "javax.management.MBeanRegistrationException", 673 new Class [] { Exception .class, String .class }, 674 new Object [] { new Exception ("Cause"), "message" } 675 ); 676 Object result = runTest(obj); 677 assertEquals(obj.toString(), result.toString()); 678 } 679 680 public void testMBeanServerNotification() 681 throws Exception 682 { 683 Object objectName = instantiate( 684 "javax.management.ObjectName", 685 new Class [] { String .class }, 686 new Object [] { "domain:x=y" } 687 ); 688 689 Class clazz = loadClass("javax.management.MBeanServerNotification"); 690 String type = (String ) clazz.getField("REGISTRATION_NOTIFICATION").get(null); 691 692 Object obj = instantiate( 693 "javax.management.MBeanServerNotification", 694 new Class [] { String .class, Object .class, Long.TYPE, 695 objectName.getClass() }, 696 new Object [] { type, "source", new Long (1), objectName } 697 ); 698 Object result = runTest(obj); 699 assertEquals(obj.toString(), result.toString()); 700 } 701 702 public void testMBeanServerNotificationFilter() 703 throws Exception 704 { 705 Object objectName = instantiate( 706 "javax.management.ObjectName", 707 new Class [] { String .class }, 708 new Object [] { "domain:x=y" } 709 ); 710 Object obj = instantiate( 711 "javax.management.relation.MBeanServerNotificationFilter", 712 new Class [0], 713 new Object [0] 714 ); 715 Method method = obj.getClass().getMethod("enableType", 716 new Class [] { String .class }); 717 method.invoke(obj, new Object [] { "prefix" }); 718 method = obj.getClass().getMethod("enableObjectName", 719 new Class [] { objectName.getClass() }); 720 method.invoke(obj, new Object [] { objectName }); 721 Object result = runTest(obj); 722 assertEquals(obj.toString(), result.toString()); 723 } 724 725 public void testMBeanServerPermission() 726 throws Exception 727 { 728 if (SerializationSUITE.form < 11) 729 return; 730 Object obj = instantiate( 731 "javax.management.MBeanServerPermission", 732 new Class [] { String .class }, 733 new Object [] { "*" } 734 ); 735 Object result = runTest(obj); 736 assertEquals(obj.toString(), result.toString()); 737 } 738 739 public void testModelMBeanAttributeInfo() 740 throws Exception 741 { 742 Object obj = instantiate( 743 "javax.management.modelmbean.ModelMBeanAttributeInfo", 744 new Class [] { String .class, String .class, String .class, 745 Boolean.TYPE, Boolean.TYPE, Boolean.TYPE }, 746 new Object [] { "name", "type", "description", new Boolean (true), 747 new Boolean (true), new Boolean (false)} 748 ); 749 try 750 { 751 runTest(obj); 752 } 753 catch (java.io.InvalidClassException e) 754 { 755 fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 "); 756 } 757 } 758 759 762 public void testModelMBeanConstructorInfo() 763 throws Exception 764 { 765 Object parm = instantiate( 766 "javax.management.MBeanParameterInfo", 767 new Class [] { String .class, String .class, String .class }, 768 new Object [] { "name", "type", "description" } 769 ); 770 Object array = Array.newInstance(parm.getClass(), 1); 771 Array.set(array, 0, parm); 772 Object obj = instantiate( 773 "javax.management.modelmbean.ModelMBeanConstructorInfo", 774 new Class [] { String .class, String .class, array.getClass() }, 775 new Object [] { "name", "description", array } 776 ); 777 runTest(obj); 778 } 779 780 783 public void testModelMBeanInfoSupport() 784 throws Exception 785 { 786 Object parm = instantiate( 787 "javax.management.MBeanParameterInfo", 788 new Class [] { String .class, String .class, String .class }, 789 new Object [] { "name", "type", "description" } 790 ); 791 Object parms = Array.newInstance(parm.getClass(), 1); 792 Array.set(parms, 0, parm); 793 794 Object att = instantiate( 795 "javax.management.modelmbean.ModelMBeanAttributeInfo", 796 new Class [] { String .class, String .class, String .class, 797 Boolean.TYPE, Boolean.TYPE, Boolean.TYPE }, 798 new Object [] { "name", "type", "description", new Boolean (true), 799 new Boolean (true), new Boolean (false)} 800 ); 801 Object atts = Array.newInstance(att.getClass(), 1); 802 Array.set(atts, 0, att); 803 804 Object con = instantiate( 805 "javax.management.modelmbean.ModelMBeanConstructorInfo", 806 new Class [] { String .class, String .class, parms.getClass() }, 807 new Object [] { "name", "description", parms } 808 ); 809 Object cons = Array.newInstance(con.getClass(), 1); 810 Array.set(cons, 0, con); 811 812 Class clazz = loadClass("javax.management.modelmbean.ModelMBeanOperationInfo"); 813 Integer impact = new Integer (clazz.getField("ACTION").getInt(null)); 814 Object op = instantiate( 815 "javax.management.modelmbean.ModelMBeanOperationInfo", 816 new Class [] { String .class, String .class, parms.getClass(), 817 String .class, Integer.TYPE }, 818 new Object [] { "name", "description", parms, "type", impact } 819 ); 820 Object ops = Array.newInstance(op.getClass(), 1); 821 Array.set(ops, 0, op); 822 823 String [] types = { "type1", "type2" }; 824 Object not = instantiate( 825 "javax.management.modelmbean.ModelMBeanNotificationInfo", 826 new Class [] { types.getClass(), String .class, String .class }, 827 new Object [] { types, "name", "description" } 828 ); 829 Object nots = Array.newInstance(not.getClass(), 1); 830 Array.set(nots, 0, not); 831 832 Object obj = instantiate( 833 "javax.management.modelmbean.ModelMBeanInfoSupport", 834 new Class [] { String .class, String .class, atts.getClass(), 835 cons.getClass(), ops.getClass(), nots.getClass() }, 836 new Object [] { "className", "description", atts, cons, ops, nots } 837 ); 838 try 839 { 840 runTest(obj); 841 } 842 catch (java.io.InvalidClassException e) 843 { 844 fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 "); 845 } 846 } 847 848 851 public void testModelMBeanNotificationInfo() 852 throws Exception 853 { 854 String [] types = { "type1", "type2" }; 855 Object obj = instantiate( 856 "javax.management.modelmbean.ModelMBeanNotificationInfo", 857 new Class [] { types.getClass(), String .class, String .class }, 858 new Object [] { types, "name", "description" } 859 ); 860 try 861 { 862 runTest(obj); 863 } 864 catch (java.io.StreamCorruptedException e) 865 { 866 fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 "); 867 } 868 } 869 870 873 public void testModelMBeanOperationInfo() 874 throws Exception 875 { 876 Object parm = instantiate( 877 "javax.management.MBeanParameterInfo", 878 new Class [] { String .class, String .class, String .class }, 879 new Object [] { "name", "type", "description" } 880 ); 881 Object array = Array.newInstance(parm.getClass(), 1); 882 Array.set(array, 0, parm); 883 Class clazz = loadClass("javax.management.MBeanOperationInfo"); 884 Integer impact = new Integer (clazz.getField("ACTION").getInt(null)); 885 Object obj = instantiate( 886 "javax.management.modelmbean.ModelMBeanOperationInfo", 887 new Class [] { String .class, String .class, array.getClass(), 888 String .class, Integer.TYPE }, 889 new Object [] { "name", "description", array, "type", impact } 890 ); 891 try 892 { 893 runTest(obj); 894 } 895 catch (java.io.StreamCorruptedException e) 896 { 897 fail("FAILS IN RI 1.1: Wrong serialization for form 1.0 "); 898 } 899 } 900 901 905 public void testMonitorNotification() 906 throws Exception 907 { 908 931 } 932 933 public void testMonitorSettingException() 934 throws Exception 935 { 936 Object obj = instantiate( 937 "javax.management.monitor.MonitorSettingException", 938 new Class [] { String .class }, 939 new Object [] { "message" } 940 ); 941 Object result = runTest(obj); 942 assertEquals(obj.toString(), result.toString()); 943 } 944 945 public void testNotCompliantMBeanException() 946 throws Exception 947 { 948 Object obj = instantiate( 949 "javax.management.NotCompliantMBeanException", 950 new Class [] { String .class }, 951 new Object [] { "message" } 952 ); 953 Object result = runTest(obj); 954 assertEquals(obj.toString(), result.toString()); 955 } 956 957 public void testNotification() 958 throws Exception 959 { 960 Object objectName = instantiate( 961 "javax.management.ObjectName", 962 new Class [] { String .class }, 963 new Object [] { "domain:x=y" } 964 ); 965 Object obj = instantiate( 966 "javax.management.Notification", 967 new Class [] { String .class, Object .class, Long.TYPE, Long.TYPE, 968 String .class }, 969 new Object [] { "type", objectName, new Long (1), new Long (2), 970 "message" } 971 ); 972 Object result = runTest(obj); 973 assertEquals(obj.toString(), result.toString()); 974 } 975 976 979 public void testNotificationFilterSupport() 980 throws Exception 981 { 982 Object obj = instantiate( 983 "javax.management.NotificationFilterSupport", 984 new Class [0], 985 new Object [0] 986 ); 987 Method method = obj.getClass().getMethod("enableType", 988 new Class [] { String .class }); 989 method.invoke(obj, new Object [] { "prefix" }); 990 runTest(obj); 991 } 992 993 public void testObjectInstance() 994 throws Exception 995 { 996 Object objectName = instantiate( 997 "javax.management.ObjectName", 998 new Class [] { String .class }, 999 new Object [] { "domain:x=y" } 1000 ); 1001 Object obj = instantiate( 1002 "javax.management.ObjectInstance", 1003 new Class [] { objectName.getClass(), String .class }, 1004 new Object [] { objectName, "DummyClass" } 1005 ); 1006 Object result = runTest(obj); 1007 assertEquals(obj, result); 1008 } 1009 1010 public void testObjectName() 1011 throws Exception 1012 { 1013 Object obj = instantiate( 1014 "javax.management.ObjectName", 1015 new Class [] { String .class }, 1016 new Object [] { "domain:x=y" } 1017 ); 1018 Object result = runTest(obj); 1019 assertEquals(obj, result); 1020 } 1021 1022 public void testObjectNamePattern() 1023 throws Exception 1024 { 1025 Object obj = instantiate( 1026 "javax.management.ObjectName", 1027 new Class [] { String .class }, 1028 new Object [] { "domain*:x=y" } 1029 ); 1030 Object result = runTest(obj); 1031 assertEquals(obj, result); 1032 } 1033 1034 public void testObjectNamePropertyPattern() 1035 throws Exception 1036 { 1037 Object obj = instantiate( 1038 "javax.management.ObjectName", 1039 new Class [] { String .class }, 1040 new Object [] { "domain:x=y,*" } 1041 ); 1042 Object result = runTest(obj); 1043 assertEquals(obj, result); 1044 } 1045 1046 public void testObjectNameRawPropertyPattern() 1047 throws Exception 1048 { 1049 Object obj = instantiate( 1050 "javax.management.ObjectName", 1051 new Class [] { String .class }, 1052 new Object [] { "domain:*" } 1053 ); 1054 Object result = runTest(obj); 1055 assertEquals(obj, result); 1056 } 1057 1058 public void testOpenDataException() 1059 throws Exception 1060 { 1061 if (SerializationSUITE.form < 11) 1062 return; 1063 Object obj = instantiate( 1064 "javax.management.openmbean.OpenDataException", 1065 new Class [] { String .class }, 1066 new Object [] { "message" } 1067 ); 1068 Object result = runTest(obj); 1069 assertEquals(obj.toString(), result.toString()); 1070 } 1071 1072 public void testOpenMBeanAttributeInfoSupportMinMax() 1073 throws Exception 1074 { 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.OpenMBeanAttributeInfoSupport", 1082 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1083 boolean.class, boolean.class, boolean.class, Object .class, Comparable .class, Comparable .class }, 1084 new Object [] { "name", "description", elementType, new Boolean (true), new Boolean (true), new Boolean (false), 1085 new Integer (12), new Integer (11), new Integer (13) } 1086 ); 1087 Object result = runTest(obj); 1088 assertEquals(obj, result); 1089 } 1090 1091 public void testOpenMBeanAttributeInfoSupportLegal() 1092 throws Exception 1093 { 1094 if (SerializationSUITE.form < 11) 1095 return; 1096 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1097 Object elementType = clazz.getField("INTEGER").get(null); 1098 1099 Object obj = instantiate( 1100 "javax.management.openmbean.OpenMBeanAttributeInfoSupport", 1101 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1102 boolean.class, boolean.class, boolean.class, Object .class, Object [].class }, 1103 new Object [] { "name", "description", elementType, new Boolean (true), new Boolean (true), new Boolean (false), 1104 new Integer (12), new Integer [] { new Integer (12), new Integer (13) }} 1105 ); 1106 Object result = runTest(obj); 1107 assertEquals(obj, result); 1108 } 1109 1110 public void testOpenMBeanConstructorInfoSupport() 1111 throws Exception 1112 { 1113 if (SerializationSUITE.form < 11) 1114 return; 1115 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1116 Object elementType = clazz.getField("INTEGER").get(null); 1117 1118 Object parmInfo = instantiate( 1119 "javax.management.openmbean.OpenMBeanParameterInfoSupport", 1120 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1121 Object .class, Object [].class }, 1122 new Object [] { "name", "description", elementType, 1123 new Integer (12), new Integer [] {new Integer (12), new Integer (13) }} 1124 ); 1125 Object array = Array.newInstance(parmInfo.getClass(), 1); 1126 Array.set(array, 0, parmInfo); 1127 1128 Object obj = instantiate( 1129 "javax.management.openmbean.OpenMBeanConstructorInfoSupport", 1130 new Class [] { String .class, String .class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;")}, 1131 new Object [] { "name", "description", array } 1132 ); 1133 Object result = runTest(obj); 1134 assertEquals(obj, result); 1135 } 1136 1137 public void testOpenMBeanInfoSupport() 1138 throws Exception 1139 { 1140 if (SerializationSUITE.form < 11) 1141 return; 1142 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1143 Object elementType = clazz.getField("INTEGER").get(null); 1144 1145 Object parmInfo = instantiate( 1146 "javax.management.openmbean.OpenMBeanParameterInfoSupport", 1147 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1148 Object .class, Object [].class }, 1149 new Object [] { "name", "description", elementType, 1150 new Integer (12), new Integer [] {new Integer (12), new Integer (13) }} 1151 ); 1152 Object parmArray = Array.newInstance(parmInfo.getClass(), 1); 1153 Array.set(parmArray, 0, parmInfo); 1154 1155 Object attInfo = instantiate( 1156 "javax.management.openmbean.OpenMBeanAttributeInfoSupport", 1157 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1158 boolean.class, boolean.class, boolean.class, Object .class, Object [].class }, 1159 new Object [] { "name", "description", elementType, new Boolean (true), new Boolean (true), new Boolean (false), 1160 new Integer (12), new Integer [] { new Integer (12), new Integer (13) }} 1161 ); 1162 1163 Object conInfo = instantiate( 1164 "javax.management.openmbean.OpenMBeanConstructorInfoSupport", 1165 new Class [] { String .class, String .class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;")}, 1166 new Object [] { "name", "description", parmArray } 1167 ); 1168 1169 clazz = loadClass("javax.management.MBeanOperationInfo"); 1170 Object impact = clazz.getField("INFO").get(null); 1171 1172 Object opInfo = instantiate( 1173 "javax.management.openmbean.OpenMBeanOperationInfoSupport", 1174 new Class [] { String .class, String .class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;"), 1175 loadClass("javax.management.openmbean.OpenType"), int.class }, 1176 new Object [] { "name", "description", parmArray, elementType, impact } 1177 ); 1178 1179 String [] types = { "type1", "type2" }; 1180 Object notInfo = instantiate( 1181 "javax.management.MBeanNotificationInfo", 1182 new Class [] { types.getClass(), String .class, String .class }, 1183 new Object [] { types, "name", "description" } 1184 ); 1185 1186 Object attArray = Array.newInstance(attInfo.getClass(), 1); 1187 Array.set(attArray, 0, attInfo); 1188 1189 Object conArray = Array.newInstance(conInfo.getClass(), 1); 1190 Array.set(conArray, 0, conInfo); 1191 1192 Object opArray = Array.newInstance(opInfo.getClass(), 1); 1193 Array.set(opArray, 0, opInfo); 1194 1195 Object notArray = Array.newInstance(notInfo.getClass(), 1); 1196 Array.set(notArray, 0, notInfo); 1197 1198 Object obj = instantiate( 1199 "javax.management.openmbean.OpenMBeanInfoSupport", 1200 new Class [] { String .class, String .class, 1201 loadClass("[Ljavax.management.openmbean.OpenMBeanAttributeInfo;"), 1202 loadClass("[Ljavax.management.openmbean.OpenMBeanConstructorInfo;"), 1203 loadClass("[Ljavax.management.openmbean.OpenMBeanOperationInfo;"), 1204 loadClass("[Ljavax.management.MBeanNotificationInfo;") }, 1205 new Object [] { "classname", "description", attArray, conArray, opArray, notArray } 1206 ); 1207 1208 Object result = runTest(obj); 1209 assertEquals(obj.toString(), result.toString()); 1210 } 1211 1212 public void testOpenMBeanOperationInfoSupport() 1213 throws Exception 1214 { 1215 if (SerializationSUITE.form < 11) 1216 return; 1217 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1218 Object elementType = clazz.getField("INTEGER").get(null); 1219 1220 Object parmInfo = instantiate( 1221 "javax.management.openmbean.OpenMBeanParameterInfoSupport", 1222 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1223 Object .class, Object [].class }, 1224 new Object [] { "name", "description", elementType, 1225 new Integer (12), new Integer [] {new Integer (12), new Integer (13) }} 1226 ); 1227 Object array = Array.newInstance(parmInfo.getClass(), 1); 1228 Array.set(array, 0, parmInfo); 1229 1230 clazz = loadClass("javax.management.MBeanOperationInfo"); 1231 Object impact = clazz.getField("INFO").get(null); 1232 1233 Object obj = instantiate( 1234 "javax.management.openmbean.OpenMBeanOperationInfoSupport", 1235 new Class [] { String .class, String .class, loadClass("[Ljavax.management.openmbean.OpenMBeanParameterInfo;"), 1236 loadClass("javax.management.openmbean.OpenType"), int.class }, 1237 new Object [] { "name", "description", array, elementType, impact } 1238 ); 1239 Object result = runTest(obj); 1240 assertEquals(obj, result); 1241 } 1242 1243 public void testOpenMBeanParameterInfoSupportMinMax() 1244 throws Exception 1245 { 1246 if (SerializationSUITE.form < 11) 1247 return; 1248 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1249 Object elementType = clazz.getField("INTEGER").get(null); 1250 1251 Object obj = instantiate( 1252 "javax.management.openmbean.OpenMBeanParameterInfoSupport", 1253 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1254 Object .class, Comparable .class, Comparable .class }, 1255 new Object [] { "name", "description", elementType, 1256 new Integer (12), new Integer (11), new Integer (13) } 1257 ); 1258 Object result = runTest(obj); 1259 assertEquals(obj, result); 1260 } 1261 1262 public void testOpenMBeanParameterInfoSupportLegal() 1263 throws Exception 1264 { 1265 if (SerializationSUITE.form < 11) 1266 return; 1267 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1268 Object elementType = clazz.getField("INTEGER").get(null); 1269 1270 Object obj = instantiate( 1271 "javax.management.openmbean.OpenMBeanParameterInfoSupport", 1272 new Class [] { String .class, String .class, loadClass("javax.management.openmbean.OpenType"), 1273 Object .class, Object [].class }, 1274 new Object [] { "name", "description", elementType, 1275 new Integer (12), new Integer [] {new Integer (12), new Integer (13) }} 1276 ); 1277 Object result = runTest(obj); 1278 assertEquals(obj, result); 1279 } 1280 1281 public void testOperationsException() 1282 throws Exception 1283 { 1284 Object obj = instantiate( 1285 "javax.management.OperationsException", 1286 new Class [] { String .class }, 1287 new Object [] { "message" } 1288 ); 1289 Object result = runTest(obj); 1290 assertEquals(obj.toString(), result.toString()); 1291 } 1292 1293 public void testReflectionException() 1294 throws Exception 1295 { 1296 Object obj = instantiate( 1297 "javax.management.ReflectionException", 1298 new Class [] { Exception .class, String .class }, 1299 new Object [] { new Exception ("Cause"), "message" } 1300 ); 1301 Object result = runTest(obj); 1302 assertEquals(obj.toString(), result.toString()); 1303 } 1304 1305 public void testRelationException() 1306 throws Exception 1307 { 1308 Object obj = instantiate( 1309 "javax.management.relation.RelationException", 1310 new Class [] { String .class }, 1311 new Object [] { "message" } 1312 ); 1313 Object result = runTest(obj); 1314 assertEquals(obj.toString(), result.toString()); 1315 } 1316 1317 public void testRelationNotFoundException() 1318 throws Exception 1319 { 1320 Object obj = instantiate( 1321 "javax.management.relation.RelationNotFoundException", 1322 new Class [] { String .class }, 1323 new Object [] { "message" } 1324 ); 1325 Object result = runTest(obj); 1326 assertEquals(obj.toString(), result.toString()); 1327 } 1328 1329 public void testRelationNotification() 1330 throws Exception 1331 { 1332 Object objectName = instantiate( 1333 "javax.management.ObjectName", 1334 new Class [] { String .class }, 1335 new Object [] { "domain:x=y" } 1336 ); 1337 Class clazz = loadClass("javax.management.relation.RelationNotification"); 1338 String type = (String ) clazz.getField("RELATION_BASIC_UPDATE").get(null); 1339 ArrayList newValue = new ArrayList (); 1340 newValue.add(objectName); 1341 ArrayList oldValue = new ArrayList (); 1342 oldValue.add(objectName); 1343 Object obj = instantiate( 1344 "javax.management.relation.RelationNotification", 1345 new Class [] { String .class, Object .class, Long.TYPE, Long.TYPE, 1346 String .class, String .class, String .class, 1347 objectName.getClass(), String .class, List .class, List .class }, 1348 new Object [] { type, objectName, new Long (1), new Long (2), 1349 "message", "relationId", "relationType", objectName, 1350 "roleName", newValue, oldValue} 1351 ); 1352 Object result = runTest(obj); 1353 assertEquals(obj.toString(), result.toString()); 1354 } 1355 1356 public void testRelationServiceNotRegisteredException() 1357 throws Exception 1358 { 1359 Object obj = instantiate( 1360 "javax.management.relation.RelationServiceNotRegisteredException", 1361 new Class [] { String .class }, 1362 new Object [] { "message" } 1363 ); 1364 Object result = runTest(obj); 1365 assertEquals(obj.toString(), result.toString()); 1366 } 1367 1368 public void testRelationTypeNotFoundException() 1369 throws Exception 1370 { 1371 Object obj = instantiate( 1372 "javax.management.relation.RelationTypeNotFoundException", 1373 new Class [] { String .class }, 1374 new Object [] { "message" } 1375 ); 1376 Object result = runTest(obj); 1377 assertEquals(obj.toString(), result.toString()); 1378 } 1379 1380 1383 public void testRelationTypeSupport() 1384 throws Exception 1385 { 1386 Object roleInfo = instantiate( 1387 "javax.management.relation.RoleInfo", 1388 new Class [] { String .class, String .class, Boolean.TYPE, Boolean.TYPE, 1389 Integer.TYPE, Integer.TYPE, String .class }, 1390 new Object [] { "name", "test.serialization.support.Trivial", 1391 new Boolean (true), new Boolean (true), new Integer (10), 1392 new Integer (20), "descritpion" } 1393 ); 1394 Object array = Array.newInstance(roleInfo.getClass(), 1); 1395 Array.set(array, 0, roleInfo); 1396 Object obj = instantiate( 1397 "javax.management.relation.RelationTypeSupport", 1398 new Class [] { String .class, array.getClass() }, 1399 new Object [] { "name", array } 1400 ); 1401 runTest(obj); 1402 } 1403 1404 public void testRole() 1405 throws Exception 1406 { 1407 Object objectName = instantiate( 1408 "javax.management.ObjectName", 1409 new Class [] { String .class }, 1410 new Object [] { "domain:x=y" } 1411 ); 1412 ArrayList list = new ArrayList (); 1413 list.add(objectName); 1414 Object obj = instantiate( 1415 "javax.management.relation.Role", 1416 new Class [] { String .class, List .class}, 1417 new Object [] { "name", list } 1418 ); 1419 Object result = runTest(obj); 1420 assertEquals(obj.toString(), result.toString()); 1421 } 1422 1423 public void testRoleInfo() 1424 throws Exception 1425 { 1426 Object obj = instantiate( 1427 "javax.management.relation.RoleInfo", 1428 new Class [] { String .class, String .class, Boolean.TYPE, Boolean.TYPE, 1429 Integer.TYPE, Integer.TYPE, String .class }, 1430 new Object [] { "name", "test.serialization.support.Trivial", 1431 new Boolean (true), new Boolean (true), new Integer (10), 1432 new Integer (20), "descritpion" } 1433 ); 1434 Object result = runTest(obj); 1435 assertEquals(obj.toString(), result.toString()); 1436 } 1437 1438 public void testRoleInfoNotFoundException() 1439 throws Exception 1440 { 1441 Object obj = instantiate( 1442 "javax.management.relation.RoleInfoNotFoundException", 1443 new Class [] { String .class }, 1444 new Object [] { "message" } 1445 ); 1446 Object result = runTest(obj); 1447 assertEquals(obj.toString(), result.toString()); 1448 } 1449 1450 public void testRoleList() 1451 throws Exception 1452 { 1453 Object objectName = instantiate( 1454 "javax.management.ObjectName", 1455 new Class [] { String .class }, 1456 new Object [] { "domain:x=y" } 1457 ); 1458 ArrayList list = new ArrayList (); 1459 list.add(objectName); 1460 Object role = instantiate( 1461 "javax.management.relation.Role", 1462 new Class [] { String .class, List .class}, 1463 new Object [] { "name", list } 1464 ); 1465 list = new ArrayList (); 1466 list.add(role); 1467 Object obj = instantiate( 1468 "javax.management.relation.RoleList", 1469 new Class [] { List .class}, 1470 new Object [] { list } 1471 ); 1472 Object result = runTest(obj); 1473 assertEquals(obj.toString(), result.toString()); 1474 } 1475 1476 public void testRoleNotFoundException() 1477 throws Exception 1478 { 1479 Object obj = instantiate( 1480 "javax.management.relation.RoleNotFoundException", 1481 new Class [] { String .class }, 1482 new Object [] { "message" } 1483 ); 1484 Object result = runTest(obj); 1485 assertEquals(obj.toString(), result.toString()); 1486 } 1487 1488 public void testRoleResult() 1489 throws Exception 1490 { 1491 Object objectName = instantiate( 1492 "javax.management.ObjectName", 1493 new Class [] { String .class }, 1494 new Object [] { "domain:x=y" } 1495 ); 1496 ArrayList list = new ArrayList (); 1497 list.add(objectName); 1498 1499 Object resolved = instantiate( 1500 "javax.management.relation.Role", 1501 new Class [] { String .class, List .class}, 1502 new Object [] { "name", list } 1503 ); 1504 list = new ArrayList (); 1505 list.add(resolved); 1506 Object resolvedList = instantiate( 1507 "javax.management.relation.RoleList", 1508 new Class [] { List .class }, 1509 new Object [] { list } 1510 ); 1511 1512 Class clazz = loadClass("javax.management.relation.RoleStatus"); 1513 Integer status = new Integer (clazz.getField("ROLE_NOT_READABLE").getInt(null)); 1514 Object unresolved = instantiate( 1515 "javax.management.relation.RoleUnresolved", 1516 new Class [] { String .class, List .class, Integer.TYPE}, 1517 new Object [] { "name", list, status } 1518 ); 1519 list = new ArrayList (); 1520 list.add(unresolved); 1521 Object unresolvedList = instantiate( 1522 "javax.management.relation.RoleUnresolvedList", 1523 new Class [] { List .class }, 1524 new Object [] { list } 1525 ); 1526 Object obj = instantiate( 1527 "javax.management.relation.RoleResult", 1528 new Class [] { resolvedList.getClass(), unresolvedList.getClass() }, 1529 new Object [] { resolvedList, unresolvedList } 1530 ); 1531 Object result = runTest(obj); 1532 assertEquals(obj.toString(), result.toString()); 1533 } 1534 1535 public void testRoleUnresolved() 1536 throws Exception 1537 { 1538 Object objectName = instantiate( 1539 "javax.management.ObjectName", 1540 new Class [] { String .class }, 1541 new Object [] { "domain:x=y" } 1542 ); 1543 ArrayList list = new ArrayList (); 1544 list.add(objectName); 1545 Class clazz = loadClass("javax.management.relation.RoleStatus"); 1546 Integer status = new Integer (clazz.getField("ROLE_NOT_READABLE").getInt(null)); 1547 Object obj = instantiate( 1548 "javax.management.relation.RoleUnresolved", 1549 new Class [] { String .class, List .class, Integer.TYPE}, 1550 new Object [] { "name", list, status } 1551 ); 1552 Object result = runTest(obj); 1553 assertEquals(obj.toString(), result.toString()); 1554 } 1555 1556 public void testRoleUnresolvedList() 1557 throws Exception 1558 { 1559 Object objectName = instantiate( 1560 "javax.management.ObjectName", 1561 new Class [] { String .class }, 1562 new Object [] { "domain:x=y" } 1563 ); 1564 ArrayList list = new ArrayList (); 1565 list.add(objectName); 1566 Class clazz = loadClass("javax.management.relation.RoleStatus"); 1567 Integer status = new Integer (clazz.getField("ROLE_NOT_READABLE").getInt(null)); 1568 Object unresolved = instantiate( 1569 "javax.management.relation.RoleUnresolved", 1570 new Class [] { String .class, List .class, Integer.TYPE}, 1571 new Object [] { "name", list, status } 1572 ); 1573 list = new ArrayList (); 1574 list.add(unresolved); 1575 Object obj = instantiate( 1576 "javax.management.relation.RoleUnresolvedList", 1577 new Class [] { List .class}, 1578 new Object [] { list } 1579 ); 1580 Object result = runTest(obj); 1581 assertEquals(obj.toString(), result.toString()); 1582 } 1583 1584 public void testRuntimeErrorException() 1585 throws Exception 1586 { 1587 Object obj = instantiate( 1588 "javax.management.RuntimeErrorException", 1589 new Class [] { Error .class, String .class }, 1590 new Object [] { new Error ("Cause"), "message" } 1591 ); 1592 Object result = runTest(obj); 1593 assertEquals(obj.toString(), result.toString()); 1594 } 1595 1596 public void testRuntimeMBeanException() 1597 throws Exception 1598 { 1599 Object obj = instantiate( 1600 "javax.management.RuntimeMBeanException", 1601 new Class [] { RuntimeException .class, String .class }, 1602 new Object [] { new RuntimeException ("Cause"), "message" } 1603 ); 1604 Object result = runTest(obj); 1605 assertEquals(obj.toString(), result.toString()); 1606 } 1607 1608 public void testRuntimeOperationsException() 1609 throws Exception 1610 { 1611 Object obj = instantiate( 1612 "javax.management.RuntimeOperationsException", 1613 new Class [] { RuntimeException .class, String .class }, 1614 new Object [] { new RuntimeException ("Cause"), "message" } 1615 ); 1616 Object result = runTest(obj); 1617 assertEquals(obj.toString(), result.toString()); 1618 } 1619 1620 public void testServiceNotFoundException() 1621 throws Exception 1622 { 1623 Object obj = instantiate( 1624 "javax.management.ServiceNotFoundException", 1625 new Class [] { String .class }, 1626 new Object [] { "message" } 1627 ); 1628 Object result = runTest(obj); 1629 assertEquals(obj.toString(), result.toString()); 1630 } 1631 1632 public void testSimpleType() 1633 throws Exception 1634 { 1635 if (SerializationSUITE.form < 11) 1636 return; 1637 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1638 Object obj = clazz.getField("BIGDECIMAL").get(null); 1639 Object result = runTest(obj); 1640 assertTrue("Simple types should resolve to the same object", 1641 obj == result); 1642 } 1643 1644 public void testStringValueExp() 1645 throws Exception 1646 { 1647 Object obj = instantiate( 1648 "javax.management.StringValueExp", 1649 new Class [] { String .class }, 1650 new Object [] { "attr" } 1651 ); 1652 Object result = runTest(obj); 1653 assertEquals(obj.toString(), result.toString()); 1654 } 1655 1656 public void testTabularDataSupport() 1657 throws Exception 1658 { 1659 if (SerializationSUITE.form < 11) 1660 return; 1661 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1662 Object openType = clazz.getField("STRING").get(null); 1663 1664 Class elementClass = loadClass("javax.management.openmbean.OpenType"); 1665 Object array = Array.newInstance(elementClass, 2); 1666 Array.set(array, 0, openType); 1667 Array.set(array, 1, openType); 1668 1669 Object compositeType = instantiate( 1670 "javax.management.openmbean.CompositeType", 1671 new Class [] { String .class, String .class, String [].class, String [].class, array.getClass() }, 1672 new Object [] { "typeName", "description", new String [] { "name1", "name2" }, 1673 new String [] { "desc1", "desc2" }, array } 1674 ); 1675 1676 Object tabularType = instantiate( 1677 "javax.management.openmbean.TabularType", 1678 new Class [] { String .class, String .class, compositeType.getClass(), String [].class }, 1679 new Object [] { "typeName", "description", compositeType, new String [] { "name1" }} 1680 ); 1681 1682 Object obj = instantiate( 1683 "javax.management.openmbean.TabularDataSupport", 1684 new Class [] { tabularType.getClass() }, 1685 new Object [] { tabularType } 1686 ); 1687 Object result = runTest(obj); 1688 assertEquals(obj, result); 1689 } 1690 1691 public void testTabularType() 1692 throws Exception 1693 { 1694 if (SerializationSUITE.form < 11) 1695 return; 1696 Class clazz = loadClass("javax.management.openmbean.SimpleType"); 1697 Object openType = clazz.getField("STRING").get(null); 1698 1699 Class elementClass = loadClass("javax.management.openmbean.OpenType"); 1700 Object array = Array.newInstance(elementClass, 2); 1701 Array.set(array, 0, openType); 1702 Array.set(array, 1, openType); 1703 1704 Object compositeType = instantiate( 1705 "javax.management.openmbean.CompositeType", 1706 new Class [] { String .class, String .class, String [].class, String [].class, array.getClass() }, 1707 new Object [] { "typeName", "description", new String [] { "name1", "name2" }, 1708 new String [] { "desc1", "desc2" }, array } 1709 ); 1710 1711 Object obj = instantiate( 1712 "javax.management.openmbean.TabularType", 1713 new Class [] { String .class, String .class, compositeType.getClass(), String [].class }, 1714 new Object [] { "typeName", "description", compositeType, new String [] { "name1" }} 1715 ); 1716 1717 Object result = runTest(obj); 1718 assertEquals(obj, result); 1719 } 1720 1721 1724 public void testTimerAlarmClockNotification() 1725 throws Exception 1726 { 1727 } 1728 1729 public void testTimerNotification() 1730 throws Exception 1731 { 1732 Object timerName = instantiate( 1733 "javax.management.ObjectName", 1734 new Class [] { String .class }, 1735 new Object [] { "timer:x=y" } 1736 ); 1737 Object obj = instantiate( 1738 "javax.management.timer.TimerNotification", 1739 new Class [] { String .class, Object .class, Long.TYPE, Long.TYPE, 1740 String .class, Integer .class, Object .class }, 1741 new Object [] { "type", timerName, new Long (1), new Long (2), 1742 "message", new Integer (1), "user data" } 1743 ); 1744 Object result = runTest(obj); 1745 assertEquals(obj.toString(), result.toString()); 1746 } 1747 1748 public void testXMLParseException() 1749 throws Exception 1750 { 1751 Object obj = instantiate( 1752 "javax.management.modelmbean.XMLParseException", 1753 new Class [] { Exception .class, String .class }, 1754 new Object [] { new Exception ("exception"), "message" } 1755 ); 1756 Object result = runTest(obj); 1757 assertEquals(obj.toString(), result.toString()); 1758 } 1759 1760 1762 1765 private Object instantiate(String className, Class [] sig, Object [] parms) 1766 throws Exception 1767 { 1768 Constructor cons = loadClass(className).getDeclaredConstructor(sig); 1769 return cons.newInstance(parms); 1770 } 1771 1772 1775 private Class loadClass(String className) 1776 throws Exception 1777 { 1778 return SerializationSUITE.jbossmx.loadClass(className); 1779 } 1780 1781 1785 private Object runTest(Object obj) 1786 throws Exception 1787 { 1788 ByteArrayOutputStream os = serializeJBoss(obj); 1789 Object intermediate = deserializeRI(os); 1790 os = serializeRI(intermediate); 1791 return deserializeJBoss(os); 1792 } 1793 1794 1797 private ByteArrayOutputStream serializeJBoss(Object obj) 1798 throws Exception 1799 { 1800 return serialize(obj); 1801 } 1802 1803 1806 private ByteArrayOutputStream serializeRI(Object obj) 1807 throws Exception 1808 { 1809 return serialize(obj); 1810 } 1811 1812 1815 private Object deserializeJBoss(ByteArrayOutputStream os) 1816 throws Exception 1817 { 1818 return deserialize(SerializationSUITE.jbossmx, os); 1819 } 1820 1821 1824 private Object deserializeRI(ByteArrayOutputStream os) 1825 throws Exception 1826 { 1827 return deserialize(SerializationSUITE.jmxri, os); 1828 } 1829 1830 1833 private ByteArrayOutputStream serialize(Object obj) 1834 throws Exception 1835 { 1836 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 1837 ObjectOutputStream oos = new ObjectOutputStream (baos); 1838 oos.writeObject(obj); 1839 return baos; 1840 } 1841 1842 1845 private Object deserialize(ClassLoader cl, ByteArrayOutputStream baos) 1846 throws Exception 1847 { 1848 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 1849 ObjectInputStream ois = new MyObjectInputStream(cl, bais); 1850 return ois.readObject(); 1851 } 1852 1853 1857 public class MyObjectInputStream extends ObjectInputStream 1858 { 1859 ClassLoader cl; 1860 public MyObjectInputStream(ClassLoader cl, ByteArrayInputStream is) 1861 throws IOException 1862 { 1863 super(is); 1864 this.cl = cl; 1865 } 1866 protected Class resolveClass(java.io.ObjectStreamClass osc) 1867 throws IOException , ClassNotFoundException 1868 { 1869 return cl.loadClass(osc.getName()); 1870 } 1871 } 1872} 1873 | Popular Tags |