1 7 8 package test.compliance.relation; 9 10 import java.io.Serializable; 11 import java.util.ArrayList; 12 13 import javax.management.ObjectName; 14 import javax.management.relation.RelationNotification; 15 import javax.management.relation.RelationService; 16 17 import junit.framework.TestCase; 18 19 28 public class RelationNotificationTestCase 29 extends TestCase 30 implements Serializable 31 { 32 33 35 static final long serialVersionUID = 516562336428465857L; 36 static String[] types = new String[] 37 { 38 RelationNotification.RELATION_BASIC_CREATION, 39 RelationNotification.RELATION_MBEAN_CREATION, 40 RelationNotification.RELATION_BASIC_UPDATE, 41 RelationNotification.RELATION_MBEAN_UPDATE, 42 RelationNotification.RELATION_BASIC_REMOVAL, 43 RelationNotification.RELATION_MBEAN_REMOVAL 44 }; 45 46 48 50 53 public RelationNotificationTestCase(String s) 54 { 55 super(s); 56 } 57 58 60 63 public void testDifferent() 64 { 65 for (int i = 0; i < (types.length - 1); i++) 66 { 67 for (int j = i + 1; j < types.length; j++) 68 if (types[i].equals(types[j])) 69 fail("Relation Notifications types not unique"); 70 } 71 } 72 73 76 public void testBasicCreation() 77 { 78 RelationNotification rn = null; 79 try 80 { 81 rn = new RelationNotification(RelationNotification.RELATION_BASIC_CREATION, 82 new RelationService(true), 21, 23, "message", "relationId", 83 "relationTypeName", null, null); 84 } 85 catch (Exception e) 86 { 87 fail(e.toString()); 88 } 89 assertEquals(RelationNotification.RELATION_BASIC_CREATION, rn.getType()); 90 assertEquals(21, rn.getSequenceNumber()); 91 assertEquals(23, rn.getTimeStamp()); 92 assertEquals("message", rn.getMessage()); 93 assertEquals("relationId", rn.getRelationId()); 94 assertEquals("relationTypeName", rn.getRelationTypeName()); 95 assertEquals(null, rn.getObjectName()); 96 assertEquals(0, rn.getMBeansToUnregister().size()); 97 } 98 99 102 public void testBasicRemoval() 103 { 104 RelationNotification rn = null; 105 ObjectName objectName = null; 106 ArrayList unregs = new ArrayList(); 107 try 108 { 109 rn = new RelationNotification(RelationNotification.RELATION_BASIC_REMOVAL, 110 new RelationService(true), 21, 23, "message", "relationId", 111 "relationTypeName", null, unregs); 112 } 113 catch (Exception e) 114 { 115 fail(e.toString()); 116 } 117 assertEquals(RelationNotification.RELATION_BASIC_REMOVAL, rn.getType()); 118 assertEquals(21, rn.getSequenceNumber()); 119 assertEquals(23, rn.getTimeStamp()); 120 assertEquals("message", rn.getMessage()); 121 assertEquals("relationId", rn.getRelationId()); 122 assertEquals("relationTypeName", rn.getRelationTypeName()); 123 assertEquals(null, rn.getObjectName()); 124 assertEquals(unregs, rn.getMBeansToUnregister()); 125 } 126 127 130 public void testMBeanCreation() 131 { 132 RelationNotification rn = null; 133 ObjectName objectName = null; 134 try 135 { 136 objectName = new ObjectName(":a=a"); 137 rn = new RelationNotification(RelationNotification.RELATION_MBEAN_CREATION, 138 new RelationService(true), 21, 23, "message", "relationId", 139 "relationTypeName", objectName, null); 140 } 141 catch (Exception e) 142 { 143 fail(e.toString()); 144 } 145 assertEquals(RelationNotification.RELATION_MBEAN_CREATION, rn.getType()); 146 assertEquals(21, rn.getSequenceNumber()); 147 assertEquals(23, rn.getTimeStamp()); 148 assertEquals("message", rn.getMessage()); 149 assertEquals("relationId", rn.getRelationId()); 150 assertEquals("relationTypeName", rn.getRelationTypeName()); 151 assertEquals(objectName, rn.getObjectName()); 152 assertEquals(0, rn.getMBeansToUnregister().size()); 153 } 154 155 158 public void testMBeanRemoval() 159 { 160 RelationNotification rn = null; 161 ObjectName objectName = null; 162 ArrayList unregs = new ArrayList(); 163 try 164 { 165 objectName = new ObjectName(":a=a"); 166 rn = new RelationNotification(RelationNotification.RELATION_MBEAN_REMOVAL, 167 new RelationService(true), 21, 23, "message", "relationId", 168 "relationTypeName", objectName, unregs); 169 } 170 catch (Exception e) 171 { 172 fail(e.toString()); 173 } 174 assertEquals(RelationNotification.RELATION_MBEAN_REMOVAL, rn.getType()); 175 assertEquals(21, rn.getSequenceNumber()); 176 assertEquals(23, rn.getTimeStamp()); 177 assertEquals("message", rn.getMessage()); 178 assertEquals("relationId", rn.getRelationId()); 179 assertEquals("relationTypeName", rn.getRelationTypeName()); 180 assertEquals(objectName, rn.getObjectName()); 181 assertEquals(unregs, rn.getMBeansToUnregister()); 182 } 183 184 187 public void testBasicUpdate() 188 { 189 RelationNotification rn = null; 190 ArrayList newRoles = new ArrayList(); 191 ArrayList oldRoles = new ArrayList(); 192 try 193 { 194 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 195 new RelationService(true), 21, 23, "message", "relationId", 196 "relationTypeName", null, "roleName", newRoles, oldRoles); 197 } 198 catch (Exception e) 199 { 200 fail(e.toString()); 201 } 202 assertEquals(RelationNotification.RELATION_BASIC_UPDATE, rn.getType()); 203 assertEquals(21, rn.getSequenceNumber()); 204 assertEquals(23, rn.getTimeStamp()); 205 assertEquals("message", rn.getMessage()); 206 assertEquals("relationId", rn.getRelationId()); 207 assertEquals("relationTypeName", rn.getRelationTypeName()); 208 assertEquals(null, rn.getObjectName()); 209 assertEquals("roleName", rn.getRoleName()); 210 assertEquals(0, rn.getNewRoleValue().size()); 211 assertEquals(0, rn.getOldRoleValue().size()); 212 } 213 214 217 public void testMBeanUpdate() 218 { 219 RelationNotification rn = null; 220 ObjectName objectName = null; 221 ArrayList newRoles = new ArrayList(); 222 ArrayList oldRoles = new ArrayList(); 223 try 224 { 225 objectName = new ObjectName(":a=a"); 226 rn = new RelationNotification(RelationNotification.RELATION_MBEAN_UPDATE, 227 new RelationService(true), 21, 23, "message", "relationId", 228 "relationTypeName", objectName, "roleName", newRoles, oldRoles); 229 } 230 catch (Exception e) 231 { 232 fail(e.toString()); 233 } 234 assertEquals(RelationNotification.RELATION_MBEAN_UPDATE, rn.getType()); 235 assertEquals(21, rn.getSequenceNumber()); 236 assertEquals(23, rn.getTimeStamp()); 237 assertEquals("message", rn.getMessage()); 238 assertEquals("relationId", rn.getRelationId()); 239 assertEquals("relationTypeName", rn.getRelationTypeName()); 240 assertEquals(objectName, rn.getObjectName()); 241 assertEquals("roleName", rn.getRoleName()); 242 assertEquals(0, rn.getNewRoleValue().size()); 243 assertEquals(0, rn.getOldRoleValue().size()); 244 } 245 246 249 public void testCreationRemovalErrors() 250 { 251 RelationNotification rn = null; 252 ObjectName objectName = null; 253 try 254 { 255 objectName = new ObjectName(":a=a"); 256 } 257 catch (Exception e) 258 { 259 fail(e.toString()); 260 } 261 ArrayList unregs = new ArrayList(); 262 263 boolean caught = false; 264 try 265 { 266 rn = new RelationNotification("blah", 267 new RelationService(true), 21, 23, "message", "relationId", 268 "relationTypeName", objectName, unregs); 269 } 270 catch (IllegalArgumentException e) 271 { 272 caught = true; 273 } 274 catch (Exception e) 275 { 276 fail(e.toString()); 277 } 278 if (caught == false) 279 fail("Creation/Removal accepts an invalid type"); 280 281 caught = false; 282 try 283 { 284 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 285 new RelationService(true), 21, 23, "message", "relationId", 286 "relationTypeName", objectName, unregs); 287 } 288 catch (IllegalArgumentException e) 289 { 290 caught = true; 291 } 292 catch (Exception e) 293 { 294 fail(e.toString()); 295 } 296 if (caught == false) 297 fail("Creation/Removal accepts basic update"); 298 299 caught = false; 300 try 301 { 302 rn = new RelationNotification(RelationNotification.RELATION_MBEAN_UPDATE, 303 new RelationService(true), 21, 23, "message", "relationId", 304 "relationTypeName", objectName, unregs); 305 } 306 catch (IllegalArgumentException e) 307 { 308 caught = true; 309 } 310 catch (Exception e) 311 { 312 fail(e.toString()); 313 } 314 if (caught == false) 315 fail("Creation/Removal accepts mean update"); 316 317 caught = false; 318 try 319 { 320 rn = new RelationNotification(RelationNotification.RELATION_BASIC_CREATION, 321 null, 21, 23, "message", "relationId", 322 "relationTypeName", objectName, unregs); 323 } 324 catch (IllegalArgumentException e) 325 { 326 caught = true; 327 } 328 catch (Exception e) 329 { 330 fail(e.toString()); 331 } 332 if (caught == false) 333 fail("Creation/Removal accepts null source"); 334 335 caught = false; 336 try 337 { 338 rn = new RelationNotification(RelationNotification.RELATION_BASIC_CREATION, 339 new RelationService(true), 21, 23, "message", null, 340 "relationTypeName", objectName, unregs); 341 } 342 catch (IllegalArgumentException e) 343 { 344 caught = true; 345 } 346 catch (Exception e) 347 { 348 fail(e.toString()); 349 } 350 if (caught == false) 351 fail("Creation/Removal accepts null relation id"); 352 353 caught = false; 354 try 355 { 356 rn = new RelationNotification(RelationNotification.RELATION_BASIC_CREATION, 357 new RelationService(true), 21, 23, "message", "relation id", 358 null, objectName, unregs); 359 } 360 catch (IllegalArgumentException e) 361 { 362 caught = true; 363 } 364 catch (Exception e) 365 { 366 fail(e.toString()); 367 } 368 if (caught == false) 369 fail("Creation/Removal accepts null relation type name"); 370 } 371 372 375 public void testCreationRemovalErrors2() 376 { 377 RelationNotification rn = null; 378 ObjectName objectName = null; 379 try 380 { 381 objectName = new ObjectName(":a=a"); 382 } 383 catch (Exception e) 384 { 385 fail(e.toString()); 386 } 387 ArrayList unregs = new ArrayList(); 388 389 boolean caught = false; 390 try 391 { 392 rn = new RelationNotification(null, 393 new RelationService(true), 21, 23, "message", "relationId", 394 "relationTypeName", objectName, unregs); 395 } 396 catch (NullPointerException e) 397 { 398 fail("FAILS IN RI: Throws the wrong exception type"); 399 } 400 catch (IllegalArgumentException e) 401 { 402 caught = true; 403 } 404 catch (Exception e) 405 { 406 fail(e.toString()); 407 } 408 if (caught == false) 409 fail("Creation/Removal accepts an a null type"); 410 } 411 412 415 public void testUpdateErrors() 416 { 417 RelationNotification rn = null; 418 ObjectName objectName = null; 419 try 420 { 421 objectName = new ObjectName(":a=a"); 422 } 423 catch (Exception e) 424 { 425 fail(e.toString()); 426 } 427 ArrayList newRoles = new ArrayList(); 428 ArrayList oldRoles = new ArrayList(); 429 430 boolean caught = false; 431 try 432 { 433 rn = new RelationNotification("blah", 434 new RelationService(true), 21, 23, "message", "relationId", 435 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 436 } 437 catch (IllegalArgumentException e) 438 { 439 caught = true; 440 } 441 catch (Exception e) 442 { 443 fail(e.toString()); 444 } 445 if (caught == false) 446 fail("Update accepts an invalid type"); 447 448 caught = false; 449 try 450 { 451 rn = new RelationNotification(RelationNotification.RELATION_BASIC_CREATION, 452 new RelationService(true), 21, 23, "message", "relationId", 453 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 454 } 455 catch (IllegalArgumentException e) 456 { 457 caught = true; 458 } 459 catch (Exception e) 460 { 461 fail(e.toString()); 462 } 463 if (caught == false) 464 fail("Update accepts basic create"); 465 466 caught = false; 467 try 468 { 469 rn = new RelationNotification(RelationNotification.RELATION_MBEAN_CREATION, 470 new RelationService(true), 21, 23, "message", "relationId", 471 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 472 } 473 catch (IllegalArgumentException e) 474 { 475 caught = true; 476 } 477 catch (Exception e) 478 { 479 fail(e.toString()); 480 } 481 if (caught == false) 482 fail("Creation/Removal accepts mean create"); 483 484 caught = false; 485 try 486 { 487 rn = new RelationNotification(RelationNotification.RELATION_BASIC_REMOVAL, 488 new RelationService(true), 21, 23, "message", "relationId", 489 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 490 } 491 catch (IllegalArgumentException e) 492 { 493 caught = true; 494 } 495 catch (Exception e) 496 { 497 fail(e.toString()); 498 } 499 if (caught == false) 500 fail("Update accepts basic remove"); 501 502 caught = false; 503 try 504 { 505 rn = new RelationNotification(RelationNotification.RELATION_MBEAN_REMOVAL, 506 new RelationService(true), 21, 23, "message", "relationId", 507 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 508 } 509 catch (IllegalArgumentException e) 510 { 511 caught = true; 512 } 513 catch (Exception e) 514 { 515 fail(e.toString()); 516 } 517 if (caught == false) 518 fail("Update accepts mean remove"); 519 520 caught = false; 521 try 522 { 523 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 524 null, 21, 23, "message", "relationId", 525 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 526 } 527 catch (IllegalArgumentException e) 528 { 529 caught = true; 530 } 531 catch (Exception e) 532 { 533 fail(e.toString()); 534 } 535 if (caught == false) 536 fail("Update accepts null source"); 537 538 caught = false; 539 try 540 { 541 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 542 new RelationService(true), 21, 23, "message", null, 543 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 544 } 545 catch (IllegalArgumentException e) 546 { 547 caught = true; 548 } 549 catch (Exception e) 550 { 551 fail(e.toString()); 552 } 553 if (caught == false) 554 fail("Update accepts null relation id"); 555 556 caught = false; 557 try 558 { 559 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 560 new RelationService(true), 21, 23, "message", "relation id", 561 null, objectName, "roleInfo", newRoles, oldRoles); 562 } 563 catch (IllegalArgumentException e) 564 { 565 caught = true; 566 } 567 catch (Exception e) 568 { 569 fail(e.toString()); 570 } 571 if (caught == false) 572 fail("Update accepts null relation type name"); 573 574 caught = false; 575 try 576 { 577 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 578 new RelationService(true), 21, 23, "message", "relation id", 579 null, objectName, null, newRoles, oldRoles); 580 } 581 catch (IllegalArgumentException e) 582 { 583 caught = true; 584 } 585 catch (Exception e) 586 { 587 fail(e.toString()); 588 } 589 if (caught == false) 590 fail("Update accepts null role info"); 591 592 caught = false; 593 try 594 { 595 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 596 new RelationService(true), 21, 23, "message", "relation id", 597 "relationTypeName", objectName, "roleInfo", null, oldRoles); 598 } 599 catch (IllegalArgumentException e) 600 { 601 caught = true; 602 } 603 catch (Exception e) 604 { 605 fail(e.toString()); 606 } 607 if (caught == false) 608 fail("Creation/Removal accepts null new role value"); 609 610 caught = false; 611 try 612 { 613 rn = new RelationNotification(RelationNotification.RELATION_BASIC_UPDATE, 614 new RelationService(true), 21, 23, "message", "relation id", 615 "relationTypeName", objectName, "roleInfo", newRoles, null); 616 } 617 catch (IllegalArgumentException e) 618 { 619 caught = true; 620 } 621 catch (Exception e) 622 { 623 fail(e.toString()); 624 } 625 if (caught == false) 626 fail("Update accepts null old role value"); 627 } 628 629 632 public void testUpdateErrors2() 633 { 634 RelationNotification rn = null; 635 ObjectName objectName = null; 636 try 637 { 638 objectName = new ObjectName(":a=a"); 639 } 640 catch (Exception e) 641 { 642 fail(e.toString()); 643 } 644 ArrayList newRoles = new ArrayList(); 645 ArrayList oldRoles = new ArrayList(); 646 647 boolean caught = false; 648 try 649 { 650 rn = new RelationNotification(null, 651 new RelationService(true), 21, 23, "message", "relationId", 652 "relationTypeName", objectName, "roleInfo", newRoles, oldRoles); 653 } 654 catch (NullPointerException e) 655 { 656 fail("FAILS IN RI: Throws the wrong exception type"); 657 } 658 catch (IllegalArgumentException e) 659 { 660 caught = true; 661 } 662 catch (Exception e) 663 { 664 fail(e.toString()); 665 } 666 if (caught == false) 667 fail("Update accepts an a null type"); 668 } 669 670 673 707 710 746 747 750 786 787 790 827 828 831 869 870 873 913 } 914 | Popular Tags |