use of org.exoplatform.container.jmx.support.ExoContainerFinder in project kernel by exoplatform.
the class TestRegistration method testFoo.
public void testFoo() throws Exception {
RootContainer root = createRootContainer("registration-configuration.xml");
assertNotNull(root.getMBeanServer());
Object instance = root.getComponentInstance("Foo");
assertNotNull(instance);
MBeanServer server = root.getMBeanServer();
Set<ObjectInstance> set = server.queryMBeans(ObjectName.getInstance("exo:object=Foo"), null);
assertEquals(1, set.size());
ObjectInstance oi = set.iterator().next();
ExoContainer oldContainer = ExoContainerContext.getCurrentContainerIfPresent();
ExoContainer currentContainer = new ExoContainer();
ExoContainerContext.setCurrentContainer(currentContainer);
try {
ExoContainerFinder proxyObject = MBeanServerInvocationHandler.newProxyInstance(server, oi.getObjectName(), ExoContainerFinder.class, false);
assertTrue("We expect to get the current exo container", oldContainer == proxyObject.getCurrentExoContainer());
assertTrue("We expect to get the previous exo container", ExoContainerContext.getCurrentContainerIfPresent() == currentContainer);
ExoContainerContext.setCurrentContainer(oldContainer);
assertTrue("We expect to get the current exo container", oldContainer == proxyObject.getCurrentExoContainer());
assertTrue("We expect to get the previous exo container", ExoContainerContext.getCurrentContainerIfPresent() == oldContainer);
ExoContainerContext.setCurrentContainer(null);
assertTrue("We expect to get the current exo container", oldContainer == proxyObject.getCurrentExoContainer());
assertTrue("We expect to get the previous exo container", ExoContainerContext.getCurrentContainerIfPresent() == oldContainer);
} finally {
ExoContainerContext.setCurrentContainer(oldContainer);
}
// Manual
root.registerComponentInstance("Bar", new ManagedWithObjectNameTemplate("Bar"));
Object instance2 = root.getComponentInstance("Bar");
assertNotNull(instance2);
Set set2 = server.queryMBeans(ObjectName.getInstance("exo:object=Bar"), null);
assertEquals(1, set2.size());
}
Aggregations