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);
}
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"));
}
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;
}
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());
}
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);
}
Aggregations