1 22 package org.jboss.test.jmx.compliance.server; 23 24 import javax.management.InstanceAlreadyExistsException ; 25 import javax.management.InstanceNotFoundException ; 26 import javax.management.MBeanServer ; 27 import javax.management.MBeanServerFactory ; 28 import javax.management.ObjectName ; 29 import javax.management.relation.RelationService ; 30 31 import junit.framework.TestCase; 32 33 import org.jboss.test.jmx.compliance.server.support.Broadcaster; 34 import org.jboss.test.jmx.compliance.server.support.Test; 35 36 51 public class DefaultDomainTestCase 52 extends TestCase 53 { 54 56 58 61 public DefaultDomainTestCase(String s) 62 { 63 super(s); 64 } 65 66 68 71 public void testDefaultDomainRegisterUnqualified() 72 { 73 MBeanServer server =null; 74 ObjectName unqualifiedName = null; 75 ObjectName qualifiedName = null; 76 try 77 { 78 server = MBeanServerFactory.createMBeanServer(); 79 unqualifiedName = new ObjectName (":property=1"); 80 qualifiedName = new ObjectName ("DefaultDomain:property=1"); 81 server.registerMBean(new Test(), unqualifiedName); 82 } 83 catch (Exception e) 84 { 85 fail(e.toString()); 86 } 87 88 assertEquals("DefaultDomain", server.getDefaultDomain()); 89 90 try 91 { 92 server.getObjectInstance(unqualifiedName); 93 } 94 catch (InstanceNotFoundException e) 95 { 96 fail("Unqualified lookup failed"); 97 } 98 99 try 100 { 101 server.getObjectInstance(qualifiedName); 102 } 103 catch (InstanceNotFoundException e) 104 { 105 fail("Qualified lookup failed"); 106 } 107 108 if (server != null) 109 MBeanServerFactory.releaseMBeanServer(server); 110 } 111 112 115 public void testDefaultDomainRegisterQualified() 116 { 117 MBeanServer server =null; 118 ObjectName unqualifiedName = null; 119 ObjectName qualifiedName = null; 120 try 121 { 122 server = MBeanServerFactory.createMBeanServer(); 123 unqualifiedName = new ObjectName (":property=1"); 124 qualifiedName = new ObjectName ("DefaultDomain:property=1"); 125 server.registerMBean(new Test(), qualifiedName); 126 } 127 catch (Exception e) 128 { 129 fail(e.toString()); 130 } 131 132 assertEquals("DefaultDomain", server.getDefaultDomain()); 133 134 try 135 { 136 server.getObjectInstance(unqualifiedName); 137 } 138 catch (InstanceNotFoundException e) 139 { 140 fail("Unqualified lookup failed"); 141 } 142 143 try 144 { 145 server.getObjectInstance(qualifiedName); 146 } 147 catch (InstanceNotFoundException e) 148 { 149 fail("Qualified lookup failed"); 150 } 151 152 if (server != null) 153 MBeanServerFactory.releaseMBeanServer(server); 154 } 155 156 159 public void testMyDefaultDomainRegisterUnqualified() 160 { 161 MBeanServer server =null; 162 ObjectName unqualifiedName = null; 163 ObjectName qualifiedName = null; 164 try 165 { 166 server = MBeanServerFactory.createMBeanServer("MyDomain"); 167 unqualifiedName = new ObjectName (":property=1"); 168 qualifiedName = new ObjectName ("MyDomain:property=1"); 169 server.registerMBean(new Test(), unqualifiedName); 170 } 171 catch (Exception e) 172 { 173 fail(e.toString()); 174 } 175 176 assertEquals("MyDomain", server.getDefaultDomain()); 177 178 try 179 { 180 server.getObjectInstance(unqualifiedName); 181 } 182 catch (InstanceNotFoundException e) 183 { 184 fail("Unqualified lookup failed"); 185 } 186 187 try 188 { 189 server.getObjectInstance(qualifiedName); 190 } 191 catch (InstanceNotFoundException e) 192 { 193 fail("Qualified lookup failed"); 194 } 195 196 if (server != null) 197 MBeanServerFactory.releaseMBeanServer(server); 198 } 199 200 203 public void testMyDefaultDomainRegisterQualified() 204 { 205 MBeanServer server =null; 206 ObjectName unqualifiedName = null; 207 ObjectName qualifiedName = null; 208 try 209 { 210 server = MBeanServerFactory.createMBeanServer("MyDomain"); 211 unqualifiedName = new ObjectName (":property=1"); 212 qualifiedName = new ObjectName ("MyDomain:property=1"); 213 server.registerMBean(new Test(), qualifiedName); 214 } 215 catch (Exception e) 216 { 217 fail(e.toString()); 218 } 219 220 assertEquals("MyDomain", server.getDefaultDomain()); 221 222 try 223 { 224 server.getObjectInstance(unqualifiedName); 225 } 226 catch (InstanceNotFoundException e) 227 { 228 fail("Unqualified lookup failed"); 229 } 230 231 try 232 { 233 server.getObjectInstance(qualifiedName); 234 } 235 catch (InstanceNotFoundException e) 236 { 237 fail("Qualified lookup failed"); 238 } 239 240 if (server != null) 241 MBeanServerFactory.releaseMBeanServer(server); 242 } 243 244 247 public void testRegisterQualifiedUnqualified() 248 { 249 duplicateRegister(":property=1", "MyDomain:property=1"); 250 } 251 252 255 public void testRegisterUnqualifiedQualified() 256 { 257 duplicateRegister("MyDomain:property=1", ":property=1"); 258 } 259 260 263 public void testRegisterUnqualifiedUnqualified() 264 { 265 duplicateRegister(":property=1", ":property=1"); 266 } 267 268 271 public void testInvokeQualifiedUnqualified() 272 { 273 invoke(":property=1", "MyDomain:property=1"); 274 } 275 276 279 public void testInvokeUnqualifiedQualified() 280 { 281 invoke("MyDomain:property=1", ":property=1"); 282 } 283 284 287 public void testInvokeUnqualifiedUnqualified() 288 { 289 invoke(":property=1", ":property=1"); 290 } 291 292 295 public void testRegisterQualifiedUnregisterUnqualified() 296 { 297 unregister("MyDomain:property=1", ":property=1"); 298 } 299 300 303 public void testRegisterUnQualifiedUnregisterQualified() 304 { 305 unregister(":property=1", "MyDomain:property=1"); 306 } 307 308 311 public void testRegisterUnqualifiedUnregisterUnqualified() 312 { 313 unregister(":property=1", ":property=1"); 314 } 315 316 319 public void testAddNLUnqualifiedNameListenerRegisterQualified() 320 { 321 addNLNameListener("MyDomain:property=1", ":property=1"); 322 } 323 324 327 public void testAddNLQualifiedNameListenerRegisterUnqualified() 328 { 329 addNLNameListener(":property=1", "MyDomain:property=1"); 330 } 331 332 335 public void testAddNLUnqualifiedNameListenerRegisterUnqualified() 336 { 337 addNLNameListener(":property=1", ":property=1"); 338 } 339 340 343 public void testAddNLUnqualifiedQualifiedRegisterUnqualifiedQualified() 344 { 345 addNLNameName(":property=1", "MyDomain:property=2",":property=1", "MyDomain:property=2"); 346 } 347 348 351 public void testAddNLUnqualifiedQualifiedRegisterQualifiedQualified() 352 { 353 addNLNameName(":property=1", "MyDomain:property=2","MyDomain:property=1", "MyDomain:property=2"); 354 } 355 356 359 public void testAddNLQualifiedQualifiedRegisterUnqualifiedQualified() 360 { 361 addNLNameName("MyDomain:property=1", "MyDomain:property=2",":property=1", "MyDomain:property=2"); 362 } 363 364 367 public void testAddNLQualifiedUnqualifiedRegisterQualifiedUnqualified() 368 { 369 addNLNameName("MyDomain:property=1", ":property=2","MyDomain:property=1", ":property=2"); 370 } 371 372 375 public void testAddNLQualifiedUnqualifiedRegisterQualifiedQualified() 376 { 377 addNLNameName("MyDomain:property=1", ":property=2","MyDomain:property=1", "MyDomain:property=2"); 378 } 379 380 383 public void testAddNLQualifiedQualifiedRegisterQualifiedUnqualified() 384 { 385 addNLNameName("MyDomain:property=1", "MyDomain:property=2","MyDomain:property=1", ":property=2"); 386 } 387 388 390 393 private void duplicateRegister(String register, String test) 394 { 395 MBeanServer server =null; 396 ObjectName registerName = null; 397 ObjectName testName = null; 398 try 399 { 400 server = MBeanServerFactory.createMBeanServer("MyDomain"); 401 registerName = new ObjectName (register); 402 testName = new ObjectName (test); 403 server.registerMBean(new Test(), registerName); 404 } 405 catch (Exception e) 406 { 407 fail(e.toString()); 408 } 409 410 boolean caught = false; 411 try 412 { 413 server.registerMBean(new Test(), testName); 414 } 415 catch (InstanceAlreadyExistsException e) 416 { 417 caught = true; 418 } 419 catch (Exception e) 420 { 421 fail(e.toString()); 422 } 423 424 if (caught == false) 425 fail("Allows duplicate registration"); 426 427 if (server != null) 428 MBeanServerFactory.releaseMBeanServer(server); 429 } 430 431 434 private void unregister(String register, String test) 435 { 436 MBeanServer server =null; 437 ObjectName registerName = null; 438 ObjectName testName = null; 439 try 440 { 441 server = MBeanServerFactory.createMBeanServer("MyDomain"); 442 registerName = new ObjectName (register); 443 testName = new ObjectName (test); 444 server.registerMBean(new Test(), registerName); 445 } 446 catch (Exception e) 447 { 448 fail(e.toString()); 449 } 450 451 try 452 { 453 server.unregisterMBean(testName); 454 } 455 catch (InstanceNotFoundException e) 456 { 457 fail("FAILS IN RI: unregisterMBean doesn't add the default domain"); 458 } 459 catch (Exception e) 460 { 461 fail(e.toString()); 462 } 463 464 if (server != null) 465 MBeanServerFactory.releaseMBeanServer(server); 466 } 467 468 471 private void addNLNameListener(String register, String test) 472 { 473 MBeanServer server =null; 474 ObjectName registerName = null; 475 ObjectName testName = null; 476 try 477 { 478 server = MBeanServerFactory.createMBeanServer("MyDomain"); 479 registerName = new ObjectName (register); 480 testName = new ObjectName (test); 481 server.registerMBean(new Broadcaster(), registerName); 482 } 483 catch (Exception e) 484 { 485 fail(e.toString()); 486 } 487 488 try 489 { 490 server.addNotificationListener(testName, new RelationService (true), null, null); 491 } 492 catch (Exception e) 493 { 494 fail(e.toString()); 495 } 496 497 if (server != null) 498 MBeanServerFactory.releaseMBeanServer(server); 499 } 500 501 504 private void addNLNameName(String register1, String register2, String test1, String test2) 505 { 506 MBeanServer server =null; 507 ObjectName register1Name = null; 508 ObjectName register2Name = null; 509 ObjectName test1Name = null; 510 ObjectName test2Name = null; 511 try 512 { 513 server = MBeanServerFactory.createMBeanServer("MyDomain"); 514 register1Name = new ObjectName (register1); 515 register2Name = new ObjectName (register2); 516 test1Name = new ObjectName (test1); 517 test2Name = new ObjectName (test2); 518 server.registerMBean(new Broadcaster(), register1Name); 519 server.registerMBean(new RelationService (true), register2Name); 520 } 521 catch (Exception e) 522 { 523 fail(e.toString()); 524 } 525 526 try 527 { 528 server.addNotificationListener(test1Name, test2Name, null, null); 529 } 530 catch (Exception e) 531 { 532 fail(e.toString()); 533 } 534 535 if (server != null) 536 MBeanServerFactory.releaseMBeanServer(server); 537 } 538 539 542 private void invoke(String register, String test) 543 { 544 MBeanServer server =null; 545 ObjectName registerName = null; 546 ObjectName testName = null; 547 try 548 { 549 server = MBeanServerFactory.createMBeanServer("MyDomain"); 550 registerName = new ObjectName (register); 551 testName = new ObjectName (test); 552 server.registerMBean(new Broadcaster(), registerName); 553 } 554 catch (Exception e) 555 { 556 fail(e.toString()); 557 } 558 559 try 560 { 561 server.invoke(testName, "doSomething", new Object [0], new String [0]); 562 } 563 catch (Exception e) 564 { 565 fail(e.toString()); 566 } 567 568 if (server != null) 569 MBeanServerFactory.releaseMBeanServer(server); 570 } 571 } 572 | Popular Tags |