public void testMX4JOnServerJMXRIOnClientNotificationReceiving() throws Exception
{
MBeanServer server = newMBeanServer();
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://localhost");
JMXConnectorServer cntorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, null, server);
cntorServer.start();
url = cntorServer.getAddress();
ClassLoader ri = createRemoteJMXRIWithTestsClassLoader();
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(ri);
Object cntor = connectJMXRIConnector(ri, url.toString());
Method method = cntor.getClass().getMethod("getMBeanServerConnection", new Class[0]);
Object cntion = method.invoke(cntor, new Object[0]);
Class cntionClass = ri.loadClass(MBeanServerConnection.class.getName());
Class objectNameClass = ri.loadClass(ObjectName.class.getName());
method = objectNameClass.getMethod("getInstance", new Class[]{String.class});
Object delegateName = method.invoke(null, new Object[]{"JMImplementation:type=MBeanServerDelegate"});
Class notificationListenerClass = ri.loadClass(NotificationListener.class.getName());
Class notificationFilterClass = ri.loadClass(NotificationFilter.class.getName());
Object listener = ri.loadClass(InteroperabilityListener.class.getName()).newInstance();
method = cntionClass.getMethod("addNotificationListener", new Class[]{objectNameClass, notificationListenerClass, notificationFilterClass, Object.class});
method.invoke(cntion, new Object[]{delegateName, listener, null, null});
sleep(1000);
method = objectNameClass.getMethod("getInstance", new Class[]{String.class});
Object mletName = method.invoke(null, new Object[]{":mbean=mlet"});
method = cntionClass.getMethod("createMBean", new Class[]{String.class, objectNameClass, objectNameClass});
method.invoke(cntion, new Object[]{MLet.class.getName(), mletName, null});
sleep(1000);
method = listener.getClass().getMethod("get", new Class[0]);
Object notification = method.invoke(listener, new Object[0]);
assertNotNull(notification);
method = listener.getClass().getMethod("reset", new Class[0]);
method.invoke(listener, new Object[0]);
method = cntionClass.getMethod("removeNotificationListener", new Class[]{objectNameClass, notificationListenerClass});
method.invoke(cntion, new Object[]{delegateName, listener});
method = cntionClass.getMethod("unregisterMBean", new Class[]{objectNameClass});
method.invoke(cntion, new Object[]{mletName});
sleep(1000);
method = listener.getClass().getMethod("get", new Class[0]);
notification = method.invoke(listener, new Object[0]);
assertNull(notification);
method = cntor.getClass().getMethod("close", new Class[0]);
method.invoke(cntor, new Object[0]);
Thread.currentThread().setContextClassLoader(tccl);
cntorServer.stop();
sleep(2000);
}