Search in sources :

Example 1 with ExoContainerFinder

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());
}
Also used : ManagedWithObjectNameTemplate(org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate) Set(java.util.Set) ExoContainer(org.exoplatform.container.ExoContainer) ExoContainerFinder(org.exoplatform.container.jmx.support.ExoContainerFinder) ObjectInstance(javax.management.ObjectInstance) RootContainer(org.exoplatform.container.RootContainer) MBeanServer(javax.management.MBeanServer)

Aggregations

Set (java.util.Set)1 MBeanServer (javax.management.MBeanServer)1 ObjectInstance (javax.management.ObjectInstance)1 ExoContainer (org.exoplatform.container.ExoContainer)1 RootContainer (org.exoplatform.container.RootContainer)1 ExoContainerFinder (org.exoplatform.container.jmx.support.ExoContainerFinder)1 ManagedWithObjectNameTemplate (org.exoplatform.container.jmx.support.ManagedWithObjectNameTemplate)1