ServerHandle { public ObjectName registerMBeanAtServer(MBeanServer pServer, Object pMBean, String pName) throws MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException, MalformedObjectNameException { if (pName != null) { ObjectName oName = new ObjectName(pName); return pServer.registerMBean(pMBean,oName).getObjectName(); } else { return pServer.registerMBean(pMBean,null).getObjectName(); } } ServerHandle(String vendor, String product, String version, Map<String, String> extraInfo); String getVendor(); String getProduct(); String getVersion(); Map<String,String> getExtraInfo(MBeanServerExecutor pServerManager); void preDispatch(MBeanServerExecutor pMBeanServerExecutor, JmxRequest pJmxReq); void postDetect(MBeanServerExecutor pServerManager, Configuration pConfig, LogHandler pLoghandler); ObjectName registerMBeanAtServer(MBeanServer pServer, Object pMBean, String pName); JSONObject toJSONObject(MBeanServerExecutor pServerManager);  }
@Test public void registerAtMBeanServer() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { Config config = new Config(null,null,null); ObjectName oName = new ObjectName("jolokia:type=Config"); ObjectInstance oInstance = new ObjectInstance(oName,Config.class.getName()); MBeanServer server = EasyMock.createMock(MBeanServer.class); expect(server.registerMBean(eq(config),eq(oName))).andReturn(oInstance); replay(server); ObjectName resName = serverHandle.registerMBeanAtServer(server,config,"jolokia:type=Config"); assertEquals(resName,oName); verify(server); }
@Test public void registerAtMBeanServer2() throws MalformedObjectNameException, MBeanRegistrationException, InstanceAlreadyExistsException, NotCompliantMBeanException { Config config = new Config(null,null,null); ObjectInstance oInstance = new ObjectInstance("jolokia:type=dummy",Config.class.getName()); MBeanServer server = EasyMock.createMock(MBeanServer.class); expect(server.registerMBean(config,null)).andReturn(oInstance); replay(server); ObjectName resName = serverHandle.registerMBeanAtServer(server,config,null); assertEquals(resName,new ObjectName("jolokia:type=dummy")); verify(server); }