MBeanServerHandler implements MBeanServerHandlerMBean, MBeanRegistration { public Object dispatchRequest(JsonRequestHandler pRequestHandler, JmxRequest pJmxReq) throws InstanceNotFoundException, AttributeNotFoundException, ReflectionException, MBeanException, NotChangedException { serverHandle.preDispatch(mBeanServerManager,pJmxReq); if (pRequestHandler.handleAllServersAtOnce(pJmxReq)) { try { return pRequestHandler.handleRequest(mBeanServerManager,pJmxReq); } catch (IOException e) { throw new IllegalStateException("Internal: IOException " + e + ". Shouldn't happen.",e); } } else { return mBeanServerManager.handleRequest(pRequestHandler, pJmxReq); } } MBeanServerHandler(Configuration pConfig, LogHandler pLogHandler); Object dispatchRequest(JsonRequestHandler pRequestHandler, JmxRequest pJmxReq); final ObjectName registerMBean(Object pMBean,String ... pOptionalName); final void destroy(); MBeanServerExecutorLocal getMBeanServerManager(); ServerHandle getServerHandle(); static List<ServerDetector> lookupDetectors(); String mBeanServersInfo(); ObjectName preRegister(MBeanServer server, ObjectName name); final String getObjectName(); void postRegister(Boolean registrationDone); void preDeregister(); void postDeregister();  }
@Test public void dispatchRequest() throws MalformedObjectNameException, InstanceNotFoundException, ReflectionException, AttributeNotFoundException, MBeanException, IOException, NotChangedException { JsonRequestHandler reqHandler = createMock(JsonRequestHandler.class); Object result = new Object(); expect(reqHandler.handleAllServersAtOnce(request)).andReturn(false); expect(reqHandler.handleRequest(EasyMock.<MBeanServerConnection>anyObject(), eq(request))).andReturn(result); replay(reqHandler); assertEquals(handler.dispatchRequest(reqHandler, request),result); }
@Test public void dispatchAtOnce() throws InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException, NotChangedException { JsonRequestHandler reqHandler = createMock(JsonRequestHandler.class); Object result = new Object(); expect(reqHandler.handleAllServersAtOnce(request)).andReturn(true); expect(reqHandler.handleRequest(isA(MBeanServerExecutor.class), eq(request))).andReturn(result); replay(reqHandler); assertEquals(handler.dispatchRequest(reqHandler, request),result); }
@Test(expectedExceptions = IllegalStateException.class,expectedExceptionsMessageRegExp = ".*Internal.*") public void dispatchAtWithException() throws InstanceNotFoundException, IOException, ReflectionException, AttributeNotFoundException, MBeanException, NotChangedException { JsonRequestHandler reqHandler = createMock(JsonRequestHandler.class); expect(reqHandler.handleAllServersAtOnce(request)).andReturn(true); expect(reqHandler.handleRequest(isA(MBeanServerExecutor.class), eq(request))).andThrow(new IOException()); replay(reqHandler); handler.dispatchRequest(reqHandler, request); }