1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import java.util.Properties ; 32 import java.io.File ; 33 34 import junit.framework.*; 36 import junit.textui.TestRunner; 37 38 import javax.management.AttributeList ; 40 import javax.management.Attribute ; 41 import javax.management.ObjectName ; 42 import javax.management.MBeanException ; 43 import javax.management.MBeanServer ; 44 45 import com.sun.enterprise.config.ConfigFactory; 47 import com.sun.enterprise.config.ConfigContext; 48 import com.sun.enterprise.config.ConfigException; 49 50 import com.sun.enterprise.admin.meta.MBeanRegistry; 52 import com.sun.enterprise.admin.meta.MBeanRegistryFactory; 53 import com.sun.enterprise.admin.BaseAdminMBean; 54 55 public class ConfigsMBeanTest extends TestCase 56 { 57 public void testCreateConfigsMBean() 58 { 59 ConfigsMBean mbean = new ConfigsMBean(); 60 Assert.assertTrue(mbean != null); 61 } 62 63 public void testGetConfigMBean() throws Exception 64 { 65 ObjectName on = configsMBean.getConfigMBean(getTarget()); 66 Assert.assertEquals(getConfigMBean(), on); 67 } 68 69 public void testGetHttpServiceMBean() throws Exception 70 { 71 ObjectName on = configsMBean.getHttpServiceMBean(getTarget()); 72 Assert.assertEquals(getHttpService(), on); 73 } 74 75 public void testHttpListener() throws Exception 76 { 77 final String target = getTargetName(); 78 ObjectName on = configsMBean.createHttpListener( 79 getHttpListenerAttrs(), null, target); 80 Assert.assertTrue(on != null); 81 Assert.assertEquals(getHttpListener(), on); 82 ObjectName [] names = configsMBean.listHttpListeners(target); 83 Assert.assertTrue(names != null); 84 Assert.assertTrue(names.length > 0); 85 Assert.assertTrue(exists(getHttpListener(), names)); 86 boolean isDeleted = configsMBean.deleteHttpListener("mylistener", null); 87 Assert.assertTrue(isDeleted); 88 names = configsMBean.listHttpListeners(target); 89 Assert.assertFalse(exists(getHttpListener(), names)); 90 } 91 92 private AttributeList getHttpListenerAttrs() 93 { 94 AttributeList attrList = new AttributeList (); 95 attrList.add(new Attribute ("id", "mylistener")); 96 attrList.add(new Attribute ("address", "abcd")); 97 attrList.add(new Attribute ("port", "9999")); 98 attrList.add(new Attribute ("server-name", "server-name")); 99 attrList.add(new Attribute ("default-virtual-server", "server-name")); 100 return attrList; 101 } 102 103 public void testIiopListener() throws Exception 104 { 105 final String target = getTargetName(); 106 ObjectName on = configsMBean.createIiopListener( 107 getIiopListenerAttrs(), null, target); 108 Assert.assertTrue(on != null); 109 Assert.assertEquals(getIiopListener(), on); 110 ObjectName [] names = configsMBean.listIiopListeners(target); 111 Assert.assertTrue(names != null); 112 Assert.assertTrue(names.length > 0); 113 Assert.assertTrue(exists(getIiopListener(), names)); 114 boolean isDeleted = configsMBean.deleteIiopListener("mylistener", null); 115 Assert.assertTrue(isDeleted); 116 names = configsMBean.listIiopListeners(target); 117 Assert.assertFalse(exists(getIiopListener(), names)); 118 } 119 120 private AttributeList getIiopListenerAttrs() 121 { 122 AttributeList attrList = new AttributeList (); 123 attrList.add(new Attribute ("id", "mylistener")); 124 attrList.add(new Attribute ("address", "address")); 125 return attrList; 126 } 127 128 public void testSSL() throws Exception 129 { 130 final String target = getTargetName(); 131 try 132 { 133 configsMBean.createHttpListener(getHttpListenerAttrs(), null, target); 134 configsMBean.createIiopListener(getIiopListenerAttrs(), null, target); 135 testSSL("http-listener"); 136 testSSL("iiop-listener"); 137 testSSL("iiop-service"); 138 } 139 finally 140 { 141 configsMBean.deleteHttpListener("mylistener", target); 142 configsMBean.deleteIiopListener("mylistener", target); 143 } 144 } 145 146 void testSSL(String type) throws Exception 147 { 148 ObjectName ssl = null; 149 final String target = getTargetName(); 150 AttributeList al = new AttributeList (); 151 al.add(new Attribute ("cert-nickname", "nick1")); 152 ssl = configsMBean.createSsl(al, "mylistener", type, target); 153 Assert.assertTrue(ssl != null); 154 ObjectName on = configsMBean.getSsl(type, "mylistener", target); 155 Assert.assertEquals(ssl, on); 156 boolean isDeleted = configsMBean.deleteSsl( 157 "mylistener", type, target); 158 Assert.assertTrue(isDeleted); 159 } 160 161 public void testVirtualServer() throws Exception 162 { 163 final String target = getTargetName(); 164 ObjectName on = configsMBean.createVirtualServer( 165 getVirtualServerAttrs(), null, target); 166 Assert.assertTrue(on != null); 167 Assert.assertEquals(getVirtualServer(), on); 168 ObjectName [] names = configsMBean.listVirtualServers(target); 169 Assert.assertTrue(names != null); 170 Assert.assertTrue(names.length > 0); 171 Assert.assertTrue(exists(getVirtualServer(), names)); 172 boolean isDeleted = configsMBean.deleteVirtualServer( 173 "my-virtual-server", null); 174 Assert.assertTrue(isDeleted); 175 names = configsMBean.listVirtualServers(target); 176 Assert.assertFalse(exists(getVirtualServer(), names)); 177 } 178 179 private AttributeList getVirtualServerAttrs() 180 { 181 AttributeList attrList = new AttributeList (); 182 attrList.add(new Attribute ("id", "my-virtual-server")); 183 attrList.add(new Attribute ("hosts", "host1,host2")); 184 return attrList; 185 } 186 187 public void testAuthRealm() throws Exception 188 { 189 final String target = getTargetName(); 190 final String realm = "myAuth"; 191 final AttributeList al = new AttributeList (); 192 al.add(new Attribute ("name", realm)); 193 al.add(new Attribute ("classname", "myauth.Auth")); 194 195 ObjectName on = configsMBean.createAuthRealm(al, null, target); 196 Assert.assertTrue(on != null); 197 Assert.assertEquals(getAuthRealm(realm), on); 198 ObjectName [] authRealms = configsMBean.listAuthRealms(target); 199 Assert.assertTrue(authRealms != null); 200 Assert.assertTrue(exists(on, authRealms)); 201 boolean deleted = configsMBean.deleteAuthRealm(realm, target); 202 Assert.assertTrue(deleted); 203 authRealms = configsMBean.listAuthRealms(target); 204 Assert.assertTrue(authRealms != null); 205 Assert.assertTrue(!exists(on, authRealms)); 206 } 207 208 public void testProfiler() throws Exception 209 { 210 final String name = "myprofiler"; 211 AttributeList al = new AttributeList (); 212 al.add(new Attribute ("name", name)); 213 214 ObjectName on = configsMBean.createProfiler( 215 al, getProperties(), null); 216 Assert.assertTrue(on != null); 217 Assert.assertEquals(getProfiler(), on); 218 on = configsMBean.getProfiler(getTargetName()); 219 Assert.assertEquals(getObjectName("profiler", null), on); 220 boolean isDeleted = configsMBean.deleteProfiler(null); 221 Assert.assertTrue(isDeleted); 222 } 223 224 public void testJvmOptions() throws Exception 225 { 226 String [] exOpts = configsMBean.getJvmOptions(false, getTargetName()); 227 Assert.assertTrue(exOpts != null); 228 String [] jvmOpts = new String [] {"-Dn1=v1", "-Dn2=v2", "-Dn3=v3"}; 229 configsMBean.createJvmOptions(jvmOpts, false, getTargetName()); 230 configsMBean.deleteJvmOptions(jvmOpts, false, getTargetName()); 231 } 232 233 public void testFileUser() throws Exception 234 { 235 final String user = "ramakant3"; 236 final String pwd = "ramakant"; 237 final String [] grps = {"grp1"}; 238 final String realm = "file"; 239 240 configsMBean.addUser(user, pwd, grps, realm, getTargetName()); 241 configsMBean.updateUser(user, pwd, grps, realm, getTargetName()); 242 String [] users = configsMBean.getUserNames(realm, getTargetName()); 243 Assert.assertTrue(users != null); 244 Assert.assertTrue(exists(user, users)); 245 246 String [] groups = configsMBean.getGroupNames(user, realm, 247 getTargetName()); 248 Assert.assertTrue(groups != null); 249 Assert.assertTrue(exists(grps[0], groups)); 250 251 configsMBean.removeUser(user, realm, getTargetName()); 252 users = configsMBean.getUserNames(realm, getTargetName()); 253 Assert.assertFalse(exists(user, users)); 254 groups = configsMBean.getGroupNames(null, realm, getTargetName()); 255 Assert.assertFalse(exists(grps[0], groups)); 256 } 257 258 public void testAuditModule() throws Exception 259 { 260 AttributeList attrs = new AttributeList (); 261 attrs.add(new Attribute ("name", "xaudit")); 262 attrs.add(new Attribute ("classname", "audit.xaudit")); 263 264 ObjectName on = configsMBean.createAuditModule( 265 attrs, getProperties(), getTargetName()); 266 Assert.assertTrue(on != null); 267 Assert.assertEquals(getAuditModule("xaudit"), on); 268 269 ObjectName [] onames = configsMBean.listAuditModules(getTargetName()); 270 Assert.assertTrue(onames != null); 271 Assert.assertTrue(onames.length > 0); 272 Assert.assertTrue(exists(getAuditModule("xaudit"), onames)); 273 274 boolean isDeleted = configsMBean.deleteAuditModule( 275 "xaudit", getTargetName()); 276 Assert.assertTrue(isDeleted); 277 onames = configsMBean.listAuditModules(getTargetName()); 278 Assert.assertTrue(!exists(getAuditModule("xaudit"), onames)); 279 } 280 281 public void testJmsHost() throws Exception 282 { 283 final AttributeList attrs = new AttributeList (); 284 attrs.add(new Attribute ("name", "host1")); 285 286 ObjectName on = configsMBean.createJmsHost( 287 attrs, getProperties(), getTargetName()); 288 Assert.assertTrue(on != null); 289 Assert.assertEquals(getJmsHost("host1"), on); 290 ObjectName [] onames = configsMBean.listJmsHosts(getTargetName()); 291 Assert.assertTrue(onames != null); 292 Assert.assertTrue(onames.length > 0); 293 Assert.assertTrue(exists(getJmsHost("host1"), onames)); 294 boolean isDeleted = configsMBean.deleteJmsHost("host1", getTargetName()); 295 Assert.assertTrue(isDeleted); 296 onames = configsMBean.listJmsHosts(getTargetName()); 297 Assert.assertTrue(!exists(getJmsHost("host1"), onames)); 298 } 299 300 public void testJaccProvider() throws Exception 301 { 302 final AttributeList attrs = new AttributeList (); 303 attrs.add(new Attribute ("name", "provider1")); 304 attrs.add(new Attribute ("policy-provider", "provider1")); 305 attrs.add(new Attribute ("policy-configuration-factory-provider", 306 "providerfactory")); 307 308 ObjectName on = configsMBean.createJaccProvider( 309 attrs, getProperties(), getTargetName()); 310 ObjectName [] onames = configsMBean.listJaccProviders(getTargetName()); 311 Assert.assertTrue(onames != null); 312 Assert.assertTrue(onames.length > 0); 313 Assert.assertTrue(exists(getJaccProvider("provider1"), onames)); 314 boolean isDeleted = configsMBean.deleteJaccProvider( 315 "provider1", getTargetName()); 316 Assert.assertTrue(isDeleted); 317 onames = configsMBean.listJaccProviders(getTargetName()); 318 Assert.assertTrue(!exists(getJaccProvider("provider1"), onames)); 319 } 320 321 public void testThreadPool() throws Exception 322 { 323 final AttributeList attrs = new AttributeList (); 324 attrs.add(new Attribute ("thread-pool-id", "testPool")); 325 326 ObjectName on = configsMBean.createThreadPool( 327 attrs, null, getTargetName()); 328 ObjectName [] onames = configsMBean.listThreadPools(getTargetName()); 329 Assert.assertTrue(onames != null); 330 Assert.assertTrue(onames.length > 0); 331 Assert.assertTrue(exists(getThreadPool("testPool"), onames)); 332 boolean isDeleted = configsMBean.deleteThreadPool( 333 "testPool", getTargetName()); 334 Assert.assertTrue(isDeleted); 335 onames = configsMBean.listThreadPools(getTargetName()); 336 Assert.assertTrue(!exists(getThreadPool("testPool"), onames)); 337 } 338 339 public void testGetChild() throws Exception 340 { 341 getChild("http-listener", new String [] {"http-listener-1"}); 342 getChild("ejb-container", null); 343 getChild("ssl", new String [] {"http-listener-1"}); 344 getChild("ssl#", null); 345 getChild("ssl##", new String []{"SSL"}); 346 347 try 348 { 349 ObjectName on = configsMBean.getChild(null, null, getTargetName()); 350 Assert.assertTrue(false); 351 } 352 catch (Exception e) 353 { 354 } 356 } 357 358 private void getChild(String type, String [] loc) throws Exception 359 { 360 try 361 { 362 ObjectName on = configsMBean.getChild(type, loc, getTargetName()); 363 Assert.assertEquals(getObjectName(type, loc), on); 364 } 365 catch (MBeanException mbe) {} 366 } 367 368 public void testGetters() throws Exception 369 { 370 ObjectName on = configsMBean.getHttpService(getTargetName()); 371 Assert.assertEquals(getObjectName("http-service", null), on); 372 373 on = configsMBean.getIiopService(getTargetName()); 374 Assert.assertEquals(getObjectName("iiop-service", null), on); 375 376 on = configsMBean.getTransactionService(getTargetName()); 377 Assert.assertEquals(getObjectName("transaction-service", null), on); 378 379 on = configsMBean.getMonitoringService(getTargetName()); 380 Assert.assertEquals(getObjectName("monitoring-service", null), on); 381 382 on = configsMBean.getLogService(getTargetName()); 383 Assert.assertEquals(getObjectName("log-service", null), on); 384 385 on = configsMBean.getSecurityService(getTargetName()); 386 Assert.assertEquals(getObjectName("security-service", null), on); 387 388 on = configsMBean.getJmsService(getTargetName()); 389 Assert.assertEquals(getObjectName("jms-service", null), on); 390 391 on = configsMBean.getEjbContainer(getTargetName()); 392 Assert.assertEquals(getObjectName("ejb-container", null), on); 393 394 on = configsMBean.getWebContainer(getTargetName()); 395 Assert.assertEquals(getObjectName("web-container", null), on); 396 397 on = configsMBean.getMdbContainer(getTargetName()); 398 Assert.assertEquals(getObjectName("mdb-container", null), on); 399 400 on = configsMBean.getJavaConfig(getTargetName()); 401 Assert.assertEquals(getObjectName("java-config", null), on); 402 403 on = configsMBean.getHttpListener("http-listener-1", getTargetName()); 404 Assert.assertEquals( 405 getObjectName1("http-listener", "http-listener-1"), on); 406 407 on = configsMBean.getVirtualServer("server", getTargetName()); 408 Assert.assertEquals(getObjectName1("virtual-server", "server"), on); 409 410 on = configsMBean.getOrb(getTargetName()); 411 Assert.assertEquals(getObjectName("orb", null), on); 412 413 on = configsMBean.getIiopListener("orb-listener-1", getTargetName()); 414 Assert.assertEquals( 415 getObjectName1("iiop-listener", "orb-listener-1"), on); 416 417 on = configsMBean.getJmsHost("default_JMS_host", getTargetName()); 418 Assert.assertEquals(getObjectName1("jms-host", "default_JMS_host"), on); 419 420 on = configsMBean.getAuthRealm("file", getTargetName()); 421 Assert.assertEquals(getObjectName1("auth-realm", "file"), on); 422 423 on = configsMBean.getAuditModule("default", getTargetName()); 424 Assert.assertEquals(getObjectName1("audit-module", "default"), on); 425 426 on = configsMBean.getJaccProvider("default", getTargetName()); 427 Assert.assertEquals(getObjectName1("jacc-provider", "default"), on); 428 429 on = configsMBean.getModuleLogLevels(getTargetName()); 430 Assert.assertEquals(getObjectName("module-log-levels", null), on); 431 432 on = configsMBean.getModuleMonitoringLevels(getTargetName()); 433 Assert.assertEquals(getObjectName("module-monitoring-levels", null), on); 434 435 on = configsMBean.getThreadPool("thread-pool-1", getTargetName()); 436 Assert.assertEquals(getObjectName1("thread-pool", "thread-pool-1"), on); 437 } 438 439 public void testEjbTimerService() throws Exception 440 { 441 ObjectName on = configsMBean.createEjbTimerService( 442 null, getProperties(), getTargetName()); 443 Assert.assertTrue(on != null); 444 on = configsMBean.getEjbTimerService(getTargetName()); 445 Assert.assertEquals(getObjectName("ejb-timer-service", null), on); 446 boolean isDeleted = configsMBean.deleteEjbTimerService(getTargetName()); 447 Assert.assertTrue(isDeleted); 448 try 449 { 450 configsMBean.getEjbTimerService(getTargetName()); 451 Assert.assertTrue(false); 452 } 453 catch (Exception e) 454 { 455 } 457 } 458 459 public void testSessionConfig() throws Exception 460 { 461 ObjectName on = null; 462 boolean isDeleted = false; 463 464 on = configsMBean.createSessionProperties(null, getProperties(), 465 getTargetName()); 466 Assert.assertEquals(getObjectName("session-properties", null), on); 467 on = configsMBean.getSessionProperties(getTargetName()); 468 Assert.assertEquals(getObjectName("session-properties", null), on); 469 isDeleted = configsMBean.deleteSessionProperties(getTargetName()); 470 Assert.assertTrue(isDeleted); 471 472 on = configsMBean.createManagerProperties(null, null, getTargetName()); 473 Assert.assertEquals(getObjectName("manager-properties", null), on); 474 on = configsMBean.getManagerProperties(getTargetName()); 475 Assert.assertEquals(getObjectName("manager-properties", null), on); 476 isDeleted = configsMBean.deleteManagerProperties(getTargetName()); 477 Assert.assertTrue(isDeleted); 478 479 on = configsMBean.createStoreProperties(null, null, getTargetName()); 480 Assert.assertEquals(getObjectName("store-properties", null), on); 481 on = configsMBean.getStoreProperties(getTargetName()); 482 Assert.assertEquals(getObjectName("store-properties", null), on); 483 isDeleted = configsMBean.deleteStoreProperties(getTargetName()); 484 Assert.assertTrue(isDeleted); 485 486 isDeleted = configsMBean.deleteSessionConfig(getTargetName()); 487 Assert.assertTrue(isDeleted); 488 } 489 490 public ConfigsMBeanTest(String name) throws Exception 491 { 492 super(name); 493 } 494 495 private ConfigContext configContext; 496 private ConfigsMBean configsMBean; 497 498 protected void setUp() 499 { 500 configsMBean = new MyConfigsMBean(); 501 try 502 { 503 configContext = ConfigFactory.createConfigContext( 504 domainXml.getAbsolutePath()); 505 loadMBeanRegistry(); 506 } 507 catch (Exception e) 508 { 509 throw new RuntimeException (e.getMessage()); 510 } 511 } 512 513 protected void tearDown() 514 { 515 configsMBean = null; 516 configContext = null; 517 mbeanRegistry = null; 518 } 519 520 public static junit.framework.Test suite() 521 { 522 TestSuite suite = new TestSuite(ConfigsMBeanTest.class); 523 return suite; 524 } 525 526 public static void main(String args[]) throws Exception 527 { 528 setDomainXml(new File (args[0])); 529 setMBeanDescriptor(new File (args[1])); 530 531 final TestRunner runner= new TestRunner(); 532 final TestResult result = runner.doRun(ConfigsMBeanTest.suite(), false); 533 System.exit(result.errorCount() + result.failureCount()); 534 } 535 536 private static File domainXml; 537 538 public static void setDomainXml(File xml) 539 { 540 domainXml = xml; 541 } 542 543 private static File mbeanDescriptor; 544 545 public static void setMBeanDescriptor(File f) 546 { 547 mbeanDescriptor = f; 548 } 549 550 private static MBeanRegistry mbeanRegistry; 551 552 private static void loadMBeanRegistry() throws Exception 553 { 554 if (null == mbeanRegistry) 555 { 556 mbeanRegistry = MBeanRegistryFactory.getMBeanRegistry( 557 mbeanDescriptor.getAbsolutePath()); 558 } 559 } 560 561 private String getConfigRef() throws Exception 562 { 563 Target target = TargetBuilder.INSTANCE.createTarget( 564 getTargetName(), configContext); 565 return target.getConfigRef(); 566 } 567 568 ObjectName getHttpService() throws Exception 569 { 570 return new ObjectName ( 571 getTestDomain() + 572 ":type=http-service,category=config,config=" + getConfigRef()); 573 } 574 575 ObjectName getConfigMBean() throws Exception 576 { 577 return new ObjectName ( 578 getTestDomain() + 579 ":type=config,category=config,name=" + getConfigRef()); 580 } 581 582 ObjectName getHttpListener() throws Exception 583 { 584 return new ObjectName ( 585 getTestDomain() + 586 ":type=http-listener,category=config,id=mylistener,config=" + 587 getConfigRef()); 588 } 589 590 ObjectName getHttpListener(String listenerId) throws Exception 591 { 592 return new ObjectName ( 593 getTestDomain() + 594 ":type=http-listener,category=config,id=" + listenerId + 595 ",config=" + getConfigRef()); 596 } 597 598 ObjectName getIiopListener() throws Exception 599 { 600 return new ObjectName ( 601 getTestDomain() + 602 ":type=iiop-listener,category=config,id=mylistener,config=" + 603 getConfigRef()); 604 } 605 606 ObjectName getVirtualServer() throws Exception 607 { 608 return new ObjectName ( 609 getTestDomain() + 610 ":type=virtual-server,category=config,id=my-virtual-server,config=" 611 + getConfigRef()); 612 } 613 614 ObjectName getAuthRealm(String name) throws Exception 615 { 616 return new ObjectName ( 617 getTestDomain() + 618 ":type=auth-realm,category=config,config=" + getConfigRef() + 619 ",name=" + name); 620 } 621 622 ObjectName getProfiler() throws Exception 623 { 624 return new ObjectName ( 625 getTestDomain() + 626 ":type=profiler,category=config,config=" + getConfigRef()); 627 } 628 629 ObjectName getAuditModule(String name) throws Exception 630 { 631 return new ObjectName ( 632 getTestDomain() + 633 ":type=audit-module,category=config,config=" + getConfigRef() + 634 ",name=" + name); 635 } 636 637 ObjectName getJmsHost(String name) throws Exception 638 { 639 return new ObjectName ( 640 getTestDomain() + 641 ":type=jms-host,category=config,config=" + getConfigRef() + 642 ",name=" + name); 643 } 644 645 ObjectName getJaccProvider(String name) throws Exception 646 { 647 return new ObjectName ( 648 getTestDomain() + 649 ":type=jacc-provider,category=config,config=" + getConfigRef() + 650 ",name=" + name); 651 } 652 653 ObjectName getEjbContainer() throws Exception 654 { 655 return new ObjectName ( 656 getTestDomain() + 657 ":type=ejb-container,category=config,config=" + getConfigRef()); 658 } 659 660 ObjectName getSsl(String type, String id) throws Exception 661 { 662 String on = getTestDomain() + ":type=ssl,category=config,config=" + 663 getConfigRef(); 664 on += "iiop-service".equals(type) ? "" : ("," + type + '=' + id); 665 return new ObjectName (on); 666 } 667 668 ObjectName getThreadPool(String threadPoolId) throws Exception 669 { 670 return new ObjectName ( 671 getTestDomain() + 672 ":type=thread-pool,category=config,config=" + getConfigRef() + 673 ",thread-pool-id=" + threadPoolId); 674 } 675 676 ObjectName getObjectName1(String type, String loc) throws Exception 677 { 678 return getObjectName(type, new String [] {loc}); 679 } 680 681 ObjectName getObjectName2(String type, String loc1, String loc2) 682 throws Exception 683 { 684 return getObjectName(type, new String [] {loc1, loc2}); 685 } 686 687 ObjectName getObjectName(String type, String [] loc) throws Exception 688 { 689 if (null == loc) { loc = new String [0]; } 690 String [] oTokens = new String [loc.length + 2]; 691 oTokens[0] = getTestDomain(); 692 oTokens[1] = getConfigRef(); 693 for (int i = 2; i < oTokens.length; i++) 694 { 695 oTokens[i] = loc[i-2]; 696 } 697 return mbeanRegistry.getMbeanObjectName(type, oTokens); 698 } 699 700 boolean exists(Object on, Object [] names) 701 { 702 for (int i = 0; i < names.length; i++) 703 { 704 if (names[i].equals(on)) 705 { 706 return true; 707 } 708 } 709 return false; 710 } 711 712 private String getTargetName() 713 { 714 return null; 715 } 716 717 private Target getTarget() throws Exception 718 { 719 return TargetBuilder.INSTANCE.createTarget(getTargetName(), 720 configContext); 721 } 722 723 private Properties getProperties() 724 { 725 Properties props = new Properties (); 726 props.put("prop1", "val1"); 727 return props; 728 } 729 730 private String getTestDomain() 731 { 732 return "testdomain"; 733 } 734 735 private class MyConfigsMBean extends ConfigsMBean 736 { 737 private MBeanServer mbeanServer; 738 739 public ConfigContext getConfigContext() 740 { 741 return configContext; 742 } 743 744 public MBeanServer getMBeanServer() throws MBeanException 745 { 746 if (mbeanServer == null) 747 { 748 mbeanServer = javax.management.MBeanServerFactory. 749 createMBeanServer(); 750 } 751 return mbeanServer; 752 } 753 754 protected void postInvoke(String opName, Object ret) 755 throws MBeanException 756 { 757 try 758 { 759 if (ret instanceof ObjectName ) 760 { 761 ObjectName on = (ObjectName )ret; 762 if (!getMBeanServer().isRegistered(on)) 763 { 764 BaseAdminMBean mbean = 765 mbeanRegistry.instantiateConfigMBean( 766 on, null, getConfigContext()); 767 getMBeanServer().registerMBean(mbean, on); 768 } 769 } 770 flush(); 771 } 772 catch (Exception e) 773 { 774 throw MBeanExceptionFormatter.toMBeanException(e, null); 775 } 776 } 777 778 private void flush() throws MBeanException 779 { 780 try 781 { 782 final ConfigContext cctx = getConfigContext(); 783 if (cctx.isChanged()) 784 { 785 cctx.flush(); 786 } 787 } 788 catch (Exception e) 789 { 790 throw MBeanExceptionFormatter.toMBeanException(e, null); 791 } 792 } 793 794 public String getDomainName() 795 { 796 return getTestDomain(); 797 } 798 } 799 } | Popular Tags |