Search in sources :

Example 11 with IvmContext

use of org.apache.openejb.core.ivm.naming.IvmContext in project tomee by apache.

the class IvmContextTest method testBindRelativeToRootAndLookupRelativeToRoot.

@Test
public void testBindRelativeToRootAndLookupRelativeToRoot() throws Exception {
    final IvmContext root = IvmContext.createRootContext();
    final Object boundObject = new Object();
    root.bind("a/b/object", boundObject);
    final Object lookedUpObject = root.lookup("a/b/object");
    assertSame(boundObject, lookedUpObject);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) Test(org.junit.Test)

Example 12 with IvmContext

use of org.apache.openejb.core.ivm.naming.IvmContext in project tomee by apache.

the class IvmContextTest method rebind.

@Test
public void rebind() throws NamingException {
    final IvmContext root = IvmContext.createRootContext();
    root.rebind("global/App.EAR/foo", "test");
    final Context last = Contexts.createSubcontexts(root, "global/App.EAR/foo");
    last.rebind("foo", "test");
    // first ensure all is bound correctly
    assertEquals("test", root.lookup("global/App.EAR/foo"));
    assertEquals("test", last.lookup("foo"));
    // even after cache clearance
    // clear cache
    last.unbind("missing");
    assertEquals("test", root.lookup("global/App.EAR/foo"));
    assertEquals("test", last.lookup("foo"));
    // now rebound, shouldnt throw any exception
    final Context lastContext = Contexts.createSubcontexts(root, "global/App.EAR/foo");
    lastContext.rebind("foo", "test2");
    assertSame(lastContext, last);
    root.rebind("global/App.EAR/foo", "test2");
    assertEquals("test2", root.lookup("global/App.EAR/foo"));
    assertEquals("test2", last.lookup("foo"));
    // even after cache clearance
    lastContext.unbind("missing");
    assertEquals("test2", root.lookup("global/App.EAR/foo"));
    assertEquals("test2", last.lookup("foo"));
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) Test(org.junit.Test)

Example 13 with IvmContext

use of org.apache.openejb.core.ivm.naming.IvmContext in project tomee by apache.

the class IvmContextTest method createTestIvmContext.

private IvmContext createTestIvmContext() throws NamingException {
    final IvmContext root = IvmContext.createRootContext();
    root.createSubcontext("global");
    root.createSubcontext("module");
    root.createSubcontext("app");
    root.bind("global/GlobalBean-1", "GlobalBean-1");
    root.bind("global/GlobalBean-2", "GlobalBean-2");
    root.bind("app/AppBean-1", "AppBean-1");
    root.bind("app/AppBean-2", "AppBean-2");
    root.bind("module/env/properties/prop-1", "prop-1");
    root.bind("module/env/properties/prop-2", "prop-2");
    root.bind("module/env/properties/prop-3", "prop-3");
    final IvmContext federatedProperties = new IvmContext();
    root.bind("module/env/properties", federatedProperties);
    federatedProperties.bind("federated-prop-1", "federated-prop-1");
    federatedProperties.bind("federated-prop-2", "federated-prop-2");
    federatedProperties.bind("federated-prop-3", "federated-prop-3");
    final IvmContext federatedConfigurations = new IvmContext();
    root.bind("module/env/configurations", federatedConfigurations);
    federatedConfigurations.bind("federated-conf-1", "federated-conf-1");
    federatedConfigurations.bind("federated-conf-2", "federated-conf-2");
    federatedConfigurations.bind("federated-conf-3", "federated-conf-3");
    root.bind("module/env/configurations/conf-1", "conf-1");
    root.bind("module/env/configurations/conf-2", "conf-2");
    root.bind("module/env/configurations/conf-3", "conf-3");
    root.bind("module/env/env-1", "env-1");
    root.bind("module/env/env-2", "env-2");
    root.bind("module/env/env-3", "env-3");
    root.bind("module/Bean-1", "Bean-1");
    root.bind("module/Bean-2", "Bean-2");
    root.bind("module/Bean-3", "Bean-3");
    return root;
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext)

Example 14 with IvmContext

use of org.apache.openejb.core.ivm.naming.IvmContext in project tomee by apache.

the class IvmContextTest method testBindThrowsNameAlreadyBoundException.

@Test(expected = NameAlreadyBoundException.class)
public void testBindThrowsNameAlreadyBoundException() throws Exception {
    IvmContext root = IvmContext.createRootContext();
    root.bind("a/b/object", new Object());
    IvmContext b = (IvmContext) root.lookup("a/b");
    // already bound from root -> must fail
    b.bind("object", new Object());
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) Test(org.junit.Test)

Example 15 with IvmContext

use of org.apache.openejb.core.ivm.naming.IvmContext in project tomee by apache.

the class IvmContextTest method testContextList.

@Test
public void testContextList() throws NamingException {
    final IvmContext root = createTestIvmContext();
    final ByteArrayOutputStream logBuffer = new ByteArrayOutputStream();
    final PrintWriter logWriter = new PrintWriter(logBuffer);
    final boolean hasErrors = listContext(root, "", logWriter);
    logWriter.flush();
    assertFalse(logBuffer.toString(), hasErrors);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

IvmContext (org.apache.openejb.core.ivm.naming.IvmContext)19 Test (org.junit.Test)13 AppContext (org.apache.openejb.AppContext)4 BeanContext (org.apache.openejb.BeanContext)3 ArrayList (java.util.ArrayList)2 ModuleContext (org.apache.openejb.ModuleContext)2 WebContext (org.apache.openejb.core.WebContext)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InvalidObjectException (java.io.InvalidObjectException)1 ObjectStreamException (java.io.ObjectStreamException)1 PrintWriter (java.io.PrintWriter)1 Method (java.lang.reflect.Method)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 URLClassLoader (java.net.URLClassLoader)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1