1 22 package org.jboss.test.jmx.compliance.relation; 23 24 import java.util.ArrayList ; 25 import java.util.HashMap ; 26 import java.util.HashSet ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.Map ; 30 31 import javax.management.MBeanServer ; 32 import javax.management.MBeanServerFactory ; 33 import javax.management.Notification ; 34 import javax.management.NotificationListener ; 35 import javax.management.ObjectName ; 36 import javax.management.relation.RelationNotification ; 37 import javax.management.relation.RelationService ; 38 import javax.management.relation.RelationSupport ; 39 import javax.management.relation.Role ; 40 import javax.management.relation.RoleInfo ; 41 import javax.management.relation.RoleList ; 42 import javax.management.relation.RoleResult ; 43 import javax.management.relation.RoleUnresolved ; 44 import javax.management.relation.RoleUnresolvedList ; 45 46 import junit.framework.TestCase; 47 48 import org.jboss.test.jmx.compliance.relation.support.Trivial; 49 50 55 public class RelationSupportTestCase 56 extends TestCase 57 { 58 59 61 63 HashMap services = new HashMap (); 64 65 RoleList rolesA; 66 HashMap roleInfosA = new HashMap (); 67 RoleList rolesB; 68 HashMap roleInfosB = new HashMap (); 69 Role roleC1; 70 Role roleC2; 71 RoleList rolesC; 72 HashMap roleInfosC = new HashMap (); 73 Role roleCX1; 74 Role roleCX2; 75 RoleList rolesCX; 76 HashMap roleInfosCX = new HashMap (); 77 78 80 83 public RelationSupportTestCase(String s) 84 { 85 super(s); 86 } 87 88 90 93 public void testDelegateConstructor() 94 { 95 MBeanServer server = createMBeanServer(); 96 ObjectName service = createRelationService("test:type=service", null); 97 createRolesB(null); 98 RelationSupport support = null; 99 try 100 { 101 support = new RelationSupport ("id", service, server, "relationTypeB", 102 rolesB); 103 } 104 catch(Exception e) 105 { 106 fail(e.toString()); 107 } 108 assertEquals("id", support.getRelationId()); 109 assertEquals("relationTypeB", support.getRelationTypeName()); 110 assertEquals("test:type=service", support.getRelationServiceName().toString()); 111 RoleList roleList = support.retrieveAllRoles(); 112 compare(rolesB, roleList); 113 } 114 115 118 public void testGetAllRoles() 119 { 120 MBeanServer server = createMBeanServer(); 121 ObjectName service = createRelationService("test:type=service", server); 122 createRelationTypeB(service); 123 createRolesB(server); 124 RoleResult result = null; 125 try 126 { 127 RelationSupport support = new RelationSupport ("id", service, server, 128 "relationTypeB", rolesB); 129 addRelation(server, service, support, "test:type=support"); 130 result = support.getAllRoles(); 131 } 132 catch(Exception e) 133 { 134 fail(e.toString()); 135 } 136 checkResult(result, roleInfosB, rolesB); 137 } 138 139 142 public void testGetReferencedMBeansNotRegistered() 143 { 144 MBeanServer server = createMBeanServer(); 145 ObjectName service = createRelationService("test:type=service", null); 146 createRelationTypeC(service); 147 createRolesC(server); 148 Map result = null; 149 try 150 { 151 RelationSupport support = new RelationSupport ("id", service, server, 152 "relationTypeC", rolesC); 153 result = support.getReferencedMBeans(); 154 } 155 catch(Exception e) 156 { 157 fail(e.toString()); 158 } 159 checkMBeans(result, rolesC); 160 } 161 162 165 public void testGetReferencedMBeansWhenRegistered() 166 { 167 MBeanServer server = createMBeanServer(); 168 ObjectName service = createRelationService("test:type=service", server); 169 createRelationTypeC(service); 170 createRolesC(server); 171 Map result = null; 172 try 173 { 174 RelationSupport support = new RelationSupport ("id", service, server, 175 "relationTypeC", rolesC); 176 addRelation(server, service, support, "test:type=support"); 177 result = support.getReferencedMBeans(); 178 } 179 catch(Exception e) 180 { 181 fail(e.toString()); 182 } 183 checkMBeans(result, rolesC); 184 } 185 186 189 public void testGetRole() 190 { 191 MBeanServer server = createMBeanServer(); 192 ObjectName service = createRelationService("test:type=service", server); 193 createRelationTypeC(service); 194 createRolesC(server); 195 List result = null; 196 try 197 { 198 RelationSupport support = new RelationSupport ("id", service, server, 199 "relationTypeC", rolesC); 200 addRelation(server, service, support, "test:type=support"); 201 result = support.getRole("roleC1"); 202 } 203 catch(Exception e) 204 { 205 fail(e.toString()); 206 } 207 compareListOfObjectNames(getRole(rolesC, "roleC1").getRoleValue(), result); 208 } 209 210 213 public void testGetRoleCardinalityUnregistered() 214 { 215 MBeanServer server = createMBeanServer(); 216 ObjectName service = createRelationService("test:type=service", null); 217 createRolesC(null); 218 Integer result = null; 219 RelationSupport support = null; 220 try 221 { 222 support = new RelationSupport ("id", service, server, 223 "relationTypeC", rolesC); 224 result = support.getRoleCardinality("roleC1"); 225 } 226 catch(Exception e) 227 { 228 fail(e.toString()); 229 } 230 assertEquals(2, result.intValue()); 231 232 try 233 { 234 result = support.getRoleCardinality("roleC2"); 235 } 236 catch(Exception e) 237 { 238 fail(e.toString()); 239 } 240 assertEquals(3, result.intValue()); 241 } 242 243 246 public void testGetRoleCardinalityRegistered() 247 { 248 MBeanServer server = createMBeanServer(); 249 ObjectName service = createRelationService("test:type=service", server); 250 createRelationTypeC(service); 251 createRolesC(server); 252 Integer result = null; 253 RelationSupport support = null; 254 try 255 { 256 support = new RelationSupport ("id", service, server, 257 "relationTypeC", rolesC); 258 addRelation(server, service, support, "test:type=support"); 259 result = support.getRoleCardinality("roleC1"); 260 } 261 catch(Exception e) 262 { 263 fail(e.toString()); 264 } 265 assertEquals(2, result.intValue()); 266 267 try 268 { 269 result = support.getRoleCardinality("roleC2"); 270 } 271 catch(Exception e) 272 { 273 fail(e.toString()); 274 } 275 assertEquals(3, result.intValue()); 276 } 277 278 281 public void testGetRoles() 282 { 283 MBeanServer server = createMBeanServer(); 284 ObjectName service = createRelationService("test:type=service", server); 285 createRelationTypeC(service); 286 createRolesC(server); 287 RoleResult result = null; 288 RelationSupport support = null; 289 try 290 { 291 support = new RelationSupport ("id", service, server, 292 "relationTypeC", rolesC); 293 addRelation(server, service, support, "test:type=support"); 294 result = support.getRoles(new String [] {"roleC1", "roleC2" }); 295 } 296 catch(Exception e) 297 { 298 fail(e.toString()); 299 } 300 checkResult(result, roleInfosC, rolesC); 301 302 try 303 { 304 result = support.getRoles(new String [] {"roleC1" }); 305 } 306 catch(Exception e) 307 { 308 fail(e.toString()); 309 } 310 RoleList resolved = result.getRoles(); 311 assertEquals(1, resolved.size()); 312 assertEquals(0, result.getRolesUnresolved().size()); 313 compare(getRole(rolesC, "roleC1"), (Role ) resolved.get(0)); 314 315 try 316 { 317 result = support.getRoles(new String [] {"roleC2" }); 318 } 319 catch(Exception e) 320 { 321 fail(e.toString()); 322 } 323 RoleUnresolvedList unresolved = result.getRolesUnresolved(); 324 assertEquals(0, result.getRoles().size()); 325 assertEquals(1, unresolved.size()); 326 assertEquals("roleC2", ((RoleUnresolved )unresolved.get(0)).getRoleName()); 327 } 328 329 332 public void testRelationServiceFlag() 333 { 334 MBeanServer server = createMBeanServer(); 335 ObjectName service = createRelationService("test:type=service", null); 336 createRolesB(null); 337 RelationSupport support = null; 338 try 339 { 340 support = new RelationSupport ("id", service, server, "relationTypeB", 341 rolesB); 342 } 343 catch(Exception e) 344 { 345 fail(e.toString()); 346 } 347 assertEquals(false, support.isInRelationService().booleanValue()); 348 support.setRelationServiceManagementFlag(new Boolean (true)); 349 assertEquals(true, support.isInRelationService().booleanValue()); 350 support.setRelationServiceManagementFlag(new Boolean (false)); 351 assertEquals(false, support.isInRelationService().booleanValue()); 352 } 353 354 357 public void testRetrieveAllRolesUnRegistered() 358 { 359 MBeanServer server = createMBeanServer(); 360 ObjectName service = createRelationService("test:type=service", null); 361 createRolesB(null); 362 RoleList result = null; 363 try 364 { 365 RelationSupport support = new RelationSupport ("id", service, server, 366 "relationTypeB", rolesB); 367 result = support.retrieveAllRoles(); 368 } 369 catch(Exception e) 370 { 371 fail(e.toString()); 372 } 373 compare(rolesB, result); 374 } 375 376 379 public void testRetrieveAllRolesRegistered() 380 { 381 MBeanServer server = createMBeanServer(); 382 ObjectName service = createRelationService("test:type=service", server); 383 createRelationTypeB(service); 384 createRolesB(server); 385 RoleList result = null; 386 try 387 { 388 RelationSupport support = new RelationSupport ("id", service, server, 389 "relationTypeB", rolesB); 390 addRelation(server, service, support, "test:type=support"); 391 result = support.retrieveAllRoles(); 392 } 393 catch(Exception e) 394 { 395 fail(e.toString()); 396 } 397 compare(rolesB, result); 398 } 399 400 403 public void testSetRole() 404 { 405 MBeanServer server = MBeanServerFactory.createMBeanServer(); 406 try 407 { 408 ObjectName service = createRelationService("test:type=service", server); 409 createRelationTypeC(service); 410 createRolesC(server); 411 createRolesCX(server); 412 RelationSupport support = null; 413 ObjectName on = null; 414 Listener listener = new Listener (RelationNotification.RELATION_MBEAN_UPDATE); 415 try 416 { 417 support = new RelationSupport ("id1", service, server, 418 "relationTypeC", rolesC); 419 addRelation(server, service, support, "test:type=support1"); 420 server.addNotificationListener(service, listener, null, null); 421 support.setRole(roleCX2); 422 on = new ObjectName ("test:type=support1"); 423 } 424 catch(Exception e) 425 { 426 fail(e.toString()); 427 } 428 RoleList shouldBe = new RoleList (); 429 shouldBe.add(roleC1); 430 shouldBe.add(roleCX2); 431 compare(shouldBe, support.retrieveAllRoles()); 432 RelationNotification rn = listener.check(1); 433 assertEquals(new ArrayList (), rn.getMBeansToUnregister()); 434 assertEquals(roleCX2.getRoleValue(), rn.getNewRoleValue()); 435 assertEquals(on, rn.getObjectName()); 436 assertEquals(roleC2.getRoleValue(), rn.getOldRoleValue()); 437 assertEquals("id1", rn.getRelationId()); 438 assertEquals("relationTypeC", rn.getRelationTypeName()); 439 assertEquals("roleC2", rn.getRoleName()); 440 } 441 finally 442 { 443 MBeanServerFactory.releaseMBeanServer(server); 444 } 445 } 446 447 451 public void testSetRoles() 452 { 453 MBeanServer server = MBeanServerFactory.createMBeanServer(); 454 try 455 { 456 ObjectName service = createRelationService("test:type=service", server); 457 createRelationTypeC(service); 458 createRolesC(server); 459 createRolesCX(server); 460 RelationSupport support = null; 461 Listener listener = new Listener (RelationNotification.RELATION_MBEAN_UPDATE); 462 RoleList shouldBe = new RoleList (); 463 shouldBe.add(roleC1); 464 shouldBe.add(roleCX2); 465 try 466 { 467 support = new RelationSupport ("id1", service, server, 468 "relationTypeC", rolesC); 469 addRelation(server, service, support, "test:type=support1"); 470 server.addNotificationListener(service, listener, null, null); 471 472 support.setRoles(shouldBe); 473 } 474 catch(Exception e) 475 { 476 fail(e.toString()); 477 } 478 compare(shouldBe, support.retrieveAllRoles()); 479 listener.check(1); 480 } 481 finally 482 { 483 MBeanServerFactory.releaseMBeanServer(server); 484 } 485 } 486 487 490 public void testErrors() 491 { 492 } 494 495 497 private MBeanServer createMBeanServer() 498 { 499 return MBeanServerFactory.createMBeanServer(); 500 } 501 502 private ObjectName createRelationService(String name, MBeanServer server) 503 { 504 ObjectName result = null; 505 RelationService relationService = new RelationService (true); 506 try 507 { 508 result = new ObjectName (name); 509 services.put(result, relationService); 510 if (server !=null) 511 server.registerMBean(relationService, result); 512 } 513 catch(Exception e) 514 { 515 fail(e.toString()); 516 } 517 return result; 518 } 519 520 private ObjectName addRelation(MBeanServer server, ObjectName service, 521 RelationSupport support, String name) 522 { 523 ObjectName result = null; 524 try 525 { 526 result = new ObjectName (name); 527 server.registerMBean(support, result); 528 if (service != null) 529 { 530 RelationService relationService = (RelationService ) services.get(service); 531 relationService.addRelation(result); 532 } 533 } 534 catch(Exception e) 535 { 536 fail(e.toString()); 537 } 538 return result; 539 } 540 541 private RoleInfo createRoleInfo(String name, Class mbean, 542 boolean read, boolean write, 543 int min, int max) 544 { 545 RoleInfo result = null; 546 try 547 { 548 result = new RoleInfo (name, mbean.getName(), read, write, min, max, ""); 549 } 550 catch(Exception e) 551 { 552 fail(e.toString()); 553 } 554 return result; 555 } 556 557 private void createRelationType(ObjectName relationService, String name, RoleInfo [] roleInfos) 558 { 559 try 560 { 561 RelationService service = (RelationService ) services.get(relationService); 562 service.createRelationType(name, roleInfos); 563 } 564 catch(Exception e) 565 { 566 fail(e.toString()); 567 } 568 } 569 570 private void compare(RoleList original, RoleList result) 571 { 572 assertEquals(original.size(), result.size()); 573 Iterator iterator = original.iterator(); 574 while (iterator.hasNext()) 575 { 576 Role originalRole = (Role ) iterator.next(); 577 Iterator iterator2 = result.iterator(); 578 while (iterator2.hasNext()) 579 { 580 Role resultRole = (Role ) iterator2.next(); 581 if (originalRole.getRoleName().equals(resultRole.getRoleName())) 582 { 583 compare(originalRole, resultRole); 584 iterator2.remove(); 585 } 586 } 587 } 588 assertEquals(0, result.size()); 589 } 590 591 private void compare(Role original, Role result) 592 { 593 assertEquals(original.getRoleName(), result.getRoleName()); 594 compareListOfObjectNames(original.getRoleValue(), result.getRoleValue()); 595 } 596 597 private void compareListOfObjectNames(List original, List result) 598 { 599 assertEquals(original.size(), result.size()); 600 Iterator iterator = original.iterator(); 601 while (iterator.hasNext()) 602 { 603 ObjectName originalBean = (ObjectName ) iterator.next(); 604 Iterator iterator2 = result.iterator(); 605 while (iterator2.hasNext()) 606 { 607 ObjectName resultBean = (ObjectName ) iterator2.next(); 608 if (originalBean.equals(resultBean)) 609 { 610 iterator2.remove(); 611 } 612 } 613 } 614 assertEquals(0, result.size()); 615 } 616 617 private void compareListOfStrings(List original, List result) 618 { 619 assertEquals(original.size(), result.size()); 620 Iterator iterator = original.iterator(); 621 while (iterator.hasNext()) 622 { 623 String originalString = (String ) iterator.next(); 624 Iterator iterator2 = result.iterator(); 625 while (iterator2.hasNext()) 626 { 627 String resultString = (String ) iterator2.next(); 628 if (originalString.equals(resultString)) 629 { 630 iterator2.remove(); 631 } 632 } 633 } 634 assertEquals(0, result.size()); 635 } 636 637 private ObjectName createRoleValueBean(String name, Class mbean, MBeanServer server) 638 { 639 ObjectName result = null; 640 try 641 { 642 result = new ObjectName (name); 643 if (server != null) 644 { 645 server.registerMBean(mbean.newInstance(), result); 646 } 647 } 648 catch(Exception e) 649 { 650 fail(e.toString()); 651 } 652 return result; 653 } 654 655 private void checkResult(RoleResult result, HashMap infos, RoleList roles) 656 { 657 checkResolved(result.getRoles(), infos, roles); 658 checkUnresolved(result.getRolesUnresolved(), infos, roles); 659 } 660 661 private void checkResolved(RoleList resolved, HashMap infos, RoleList roles) 662 { 663 RoleList copy = (RoleList ) roles.clone(); 664 Iterator iterator = resolved.iterator(); 665 while (iterator.hasNext()) 666 { 667 Role role = (Role ) iterator.next(); 668 String roleName = role.getRoleName(); 669 RoleInfo info = (RoleInfo ) infos.get(roleName); 670 if (info == null) 671 fail("unknown role " + roleName); 672 if (info.isReadable() == false) 673 fail("role should not be readable " + roleName); 674 Role original = removeRole(copy, roleName); 675 compareListOfObjectNames(original.getRoleValue(), role.getRoleValue()); 676 } 677 678 iterator = copy.iterator(); 679 while (iterator.hasNext()) 680 { 681 Role role = (Role ) iterator.next(); 682 String roleName = role.getRoleName(); 683 RoleInfo info = (RoleInfo ) infos.get(roleName); 684 if (info.isReadable() == true) 685 fail("missing role " + roleName); 686 } 687 } 688 689 private void checkUnresolved(RoleUnresolvedList unresolved, HashMap infos, RoleList roles) 690 { 691 RoleList copy = (RoleList ) roles.clone(); 692 Iterator iterator = unresolved.iterator(); 693 while (iterator.hasNext()) 694 { 695 RoleUnresolved roleUnresolved = (RoleUnresolved ) iterator.next(); 696 String roleName = roleUnresolved.getRoleName(); 697 RoleInfo info = (RoleInfo ) infos.get(roleName); 698 if (info == null) 699 fail("unknown role " + roleName); 700 if (info.isReadable() == true) 701 fail("role should be readable " + roleName); 702 removeRole(copy, roleName); 703 } 704 705 iterator = copy.iterator(); 706 while (iterator.hasNext()) 707 { 708 Role role = (Role ) iterator.next(); 709 String roleName = role.getRoleName(); 710 RoleInfo info = (RoleInfo ) infos.get(roleName); 711 if (info.isReadable() == false) 712 fail("missing unresolved role " + roleName); 713 } 714 } 715 716 private Role removeRole(RoleList roles, String roleName) 717 { 718 Iterator iterator = roles.iterator(); 719 while (iterator.hasNext()) 720 { 721 Role role = (Role ) iterator.next(); 722 if (role.getRoleName().equals(roleName)) 723 { 724 iterator.remove(); 725 return role; 726 } 727 } 728 fail("role was not in the original " + roleName); 729 return null; 730 } 731 732 private Role getRole(RoleList roles, String roleName) 733 { 734 Iterator iterator = roles.iterator(); 735 while (iterator.hasNext()) 736 { 737 Role role = (Role ) iterator.next(); 738 if (role.getRoleName().equals(roleName)) 739 { 740 return role; 741 } 742 } 743 fail("role was not in the original " + roleName); 744 return null; 745 } 746 747 private void checkMBeans(Map result, RoleList roles) 748 { 749 Map expected = calcMBeanRoleMap(roles); 751 752 Iterator iterator = result.entrySet().iterator(); 754 while (iterator.hasNext()) 755 { 756 Map.Entry entry = (Map.Entry ) iterator.next(); 757 ObjectName key = (ObjectName ) entry.getKey(); 758 ArrayList roleNames = (ArrayList ) entry.getValue(); 759 ArrayList expectedNames = (ArrayList ) expected.get(key); 760 if (expectedNames == null) 761 fail("Unexpected object name " + key); 762 compareListOfStrings(expectedNames, roleNames); 763 expected.remove(key); 764 } 765 assertEquals(0, expected.size()); 766 } 767 768 private Map calcMBeanRoleMap(RoleList roles) 769 { 770 HashMap result = new HashMap (); 771 Iterator iterator = roles.iterator(); 772 while (iterator.hasNext()) 773 { 774 Role role = (Role ) iterator.next(); 775 String roleName = role.getRoleName(); 776 ArrayList mbeans = (ArrayList ) role.getRoleValue(); 777 Iterator iterator2 = mbeans.iterator(); 778 while (iterator2.hasNext()) 779 { 780 ObjectName objectName = (ObjectName ) iterator2.next(); 781 ArrayList names = (ArrayList ) result.get(objectName); 782 if (names == null) 783 { 784 names = new ArrayList (); 785 result.put(objectName, names); 786 } 787 791 names.add(roleName); 792 } 793 } 794 return result; 795 } 796 797 private void createRolesB(MBeanServer server) 798 { 799 try 800 { 801 ArrayList roleB1Values = new ArrayList (); 802 roleB1Values.add(createRoleValueBean("x:relation=b,role=1,bean=1", 803 Trivial.class, server)); 804 roleB1Values.add(createRoleValueBean("x:relation=b,role=1,bean=2", 805 Trivial.class, server)); 806 Role roleB1 = new Role ("roleB1", roleB1Values); 807 808 ArrayList roleB2Values = new ArrayList (); 809 roleB2Values.add(createRoleValueBean("x:relation=b,role=2,bean=1", 810 Trivial.class, server)); 811 roleB2Values.add(createRoleValueBean("x:relation=b,role=2,bean=2", 812 Trivial.class, server)); 813 roleB2Values.add(createRoleValueBean("x:relation=b,role=2,bean=3", 814 Trivial.class, server)); 815 Role roleB2 = new Role ("roleB2", roleB2Values); 816 817 rolesB = new RoleList (); 818 rolesB.add(roleB1); 819 rolesB.add(roleB2); 820 } 821 catch(Exception e) 822 { 823 fail(e.toString()); 824 } 825 } 826 827 private void createRelationTypeB(ObjectName relationService) 828 { 829 try 830 { 831 RoleInfo roleInfoB1 = createRoleInfo("roleB1", Trivial.class, true, false, 1, 2); 832 RoleInfo roleInfoB2 = createRoleInfo("roleB2", Trivial.class, false, true, 3, 4); 833 RoleInfo [] roleInfos = new RoleInfo [] { roleInfoB1, roleInfoB2 }; 834 createRelationType(relationService, "relationTypeB", roleInfos ); 835 for (int i=0; i < roleInfos.length; i++) 836 roleInfosB.put(roleInfos[i].getName(), roleInfos[i]); 837 } 838 catch(Exception e) 839 { 840 fail(e.toString()); 841 } 842 } 843 844 private void createRolesC(MBeanServer server) 845 { 846 try 847 { 848 ArrayList roleC1Values = new ArrayList (); 849 roleC1Values.add(createRoleValueBean("x:relation=c,role=1,bean=1", 850 Trivial.class, server)); 851 roleC1Values.add(createRoleValueBean("x:relation=c,role=1,bean=1", 852 Trivial.class, null)); 853 roleC1 = new Role ("roleC1", roleC1Values); 854 855 ArrayList roleC2Values = new ArrayList (); 856 roleC2Values.add(createRoleValueBean("x:relation=c,role=1,bean=1", 857 Trivial.class, null)); 858 roleC2Values.add(createRoleValueBean("x:relation=c,role=2,bean=1", 859 Trivial.class, server)); 860 roleC2Values.add(createRoleValueBean("x:relation=c,role=2,bean=2", 861 Trivial.class, server)); 862 roleC2 = new Role ("roleC2", roleC2Values); 863 864 rolesC = new RoleList (); 865 rolesC.add(roleC1); 866 rolesC.add(roleC2); 867 } 868 catch(Exception e) 869 { 870 fail(e.toString()); 871 } 872 } 873 874 private void createRelationTypeC(ObjectName relationService) 875 { 876 try 877 { 878 RoleInfo roleInfoC1 = createRoleInfo("roleC1", Trivial.class, true, false, 1, 2); 879 RoleInfo roleInfoC2 = createRoleInfo("roleC2", Trivial.class, false, true, 3, 4); 880 RoleInfo [] roleInfos = new RoleInfo [] { roleInfoC1, roleInfoC2 }; 881 createRelationType(relationService, "relationTypeC", roleInfos ); 882 for (int i=0; i < roleInfos.length; i++) 883 roleInfosC.put(roleInfos[i].getName(), roleInfos[i]); 884 } 885 catch(Exception e) 886 { 887 fail(e.toString()); 888 } 889 } 890 891 private void createRolesCX(MBeanServer server) 892 { 893 try 894 { 895 ArrayList roleCX1Values = new ArrayList (); 896 roleCX1Values.add(createRoleValueBean("x:relation=c,role=2,bean=1", 897 Trivial.class, null)); 898 roleCX1 = new Role ("roleC1", roleCX1Values); 899 900 ArrayList roleCX2Values = new ArrayList (); 901 roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=1", 902 Trivial.class, null)); 903 roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=2", 904 Trivial.class, server)); 905 roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=3", 906 Trivial.class, server)); 907 roleCX2Values.add(createRoleValueBean("x:relation=c,role=1,bean=4", 908 Trivial.class, server)); 909 roleCX2 = new Role ("roleC2", roleCX2Values); 910 911 rolesCX = new RoleList (); 912 rolesCX.add(roleCX1); 913 rolesCX.add(roleCX2); 914 } 915 catch(Exception e) 916 { 917 fail(e.toString()); 918 } 919 } 920 921 private class Listener 922 implements NotificationListener 923 { 924 String type; 925 HashSet notifications = new HashSet (); 926 public Listener(String type) 927 { 928 this.type = type; 929 } 930 public void handleNotification(Notification n, Object h) 931 { 932 notifications.add(n); 933 } 934 public RelationNotification check(int size) 935 { 936 RelationNotification result = null; 937 assertEquals(size, notifications.size()); 938 Iterator iterator = notifications.iterator(); 939 while (iterator.hasNext()) 940 { 941 RelationNotification rn = (RelationNotification ) iterator.next(); 942 assertEquals(type, rn.getType()); 943 result = rn; 944 } 945 return result; 946 } 947 } 948 } 949 | Popular Tags |