Search in sources :

Example 6 with IvmContext

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

the class IvmContextTest method testBindFromRootSetsTheCorrectParent_lookupRelativeToTheCurrentNode.

@Test
public void testBindFromRootSetsTheCorrectParent_lookupRelativeToTheCurrentNode() throws Exception {
    final IvmContext root = IvmContext.createRootContext();
    root.bind("a/b/c", null);
    IvmContext a = (IvmContext) root.lookup("a");
    // TODO Do we want ROOT to be a parent to the top-level contexts ?
    requireCorrectParentChildRelationship(null, a);
    IvmContext b = (IvmContext) a.lookup("b");
    requireCorrectParentChildRelationship(a, b);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) Test(org.junit.Test)

Example 7 with IvmContext

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

the class IvmContextTest method unbindWithSubContext.

@Test
public void unbindWithSubContext() throws NamingException {
    final IvmContext context = new IvmContext("");
    context.bind("global/foo/Bar", "Bar");
    Contexts.createSubcontexts(context, "global/foo/Bar");
    assertEquals("Bar", context.lookup("global/foo/Bar"));
    context.unbind("global/foo/Bar");
    try {
        context.lookup("global/foo/Bar");
        fail();
    } catch (final NamingException ne) {
    // ok
    }
    try {
        ((Context) ((Context) context.lookup("global")).lookup("foo")).lookup("Bar");
        fail();
    } catch (final NamingException ne) {
    // ok
    }
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) Test(org.junit.Test)

Example 8 with IvmContext

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

the class IvmContextTest method testBindFromRootUnbindFromCurrentContext.

@Test(expected = NameNotFoundException.class)
public void testBindFromRootUnbindFromCurrentContext() throws Exception {
    IvmContext root = IvmContext.createRootContext();
    root.bind("a/b/object", new Object());
    IvmContext b = (IvmContext) root.lookup("a/b");
    b.unbind("object");
    // must fail with NameNotFoundException
    Object object = root.lookup("a/b/object");
    fail("Lookup should have failed. Instead it returned: " + object);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) Test(org.junit.Test)

Example 9 with IvmContext

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

the class IvmContextTest method unbind.

@Test
public void unbind() throws NamingException {
    final IvmContext context = new IvmContext();
    context.bind("global/foo/Bar", "Bar");
    assertEquals("Bar", context.lookup("global/foo/Bar"));
    context.unbind("global/foo/Bar");
    try {
        context.lookup("global/foo/Bar");
        fail();
    } catch (final NamingException ne) {
    // ok
    }
    try {
        final Context subCtx = (Context) context.lookup("global/foo");
        subCtx.lookup("Bar");
        fail();
    } catch (final NamingException ne) {
    // ok
    }
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) Test(org.junit.Test)

Example 10 with IvmContext

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

the class IvmContextTest method testBindRelativeToRootAndLookupRelativeToTheCurrentContext.

@Test
public void testBindRelativeToRootAndLookupRelativeToTheCurrentContext() throws Exception {
    final IvmContext root = IvmContext.createRootContext();
    final Object boundObject = new Object();
    root.bind("a/b/object", boundObject);
    IvmContext b = (IvmContext) root.lookup("a/b");
    final Object lookedUpObject = b.lookup("object");
    assertSame(boundObject, lookedUpObject);
}
Also used : IvmContext(org.apache.openejb.core.ivm.naming.IvmContext) 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