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