use of javax.naming.InitialContext in project jetty.project by eclipse.
the class TestNamingEntries method testLink.
@Test
public void testLink() throws Exception {
ScopeA scope = new ScopeA();
InitialContext icontext = new InitialContext();
Link link = new Link("linked-resourceA", "resourceB");
NamingEntry ne = NamingEntryUtil.lookupNamingEntry(null, "linked-resourceA");
assertNotNull(ne);
assertTrue(ne instanceof Link);
assertEquals(icontext.lookup("linked-resourceA"), "resourceB");
link = new Link(scope, "jdbc/linked-resourceX", "jdbc/linked-resourceY");
ne = NamingEntryUtil.lookupNamingEntry(scope, "jdbc/linked-resourceX");
assertNotNull(ne);
assertTrue(ne instanceof Link);
}
use of javax.naming.InitialContext in project jetty.project by eclipse.
the class TestNamingEntries method testResource.
@Test
public void testResource() throws Exception {
InitialContext icontext = new InitialContext();
Resource resource = new Resource(null, "resourceA/b/c", someObject);
NamingEntry ne = NamingEntryUtil.lookupNamingEntry(null, "resourceA/b/c");
assertNotNull(ne);
assertTrue(ne instanceof Resource);
assertEquals(icontext.lookup("resourceA/b/c"), someObject);
Object scope = new ScopeA();
Resource resource2 = new Resource(scope, "resourceB", someObject);
ne = NamingEntryUtil.lookupNamingEntry(scope, "resourceB");
assertNotNull(ne);
assertTrue(ne instanceof Resource);
ne = NamingEntryUtil.lookupNamingEntry(null, "resourceB");
assertNull(ne);
ne = NamingEntryUtil.lookupNamingEntry(new ScopeB(), "resourceB");
assertNull(ne);
testLink();
}
use of javax.naming.InitialContext in project jetty.project by eclipse.
the class TestNamingEntries method after.
/**
* after each test we should scrape out any lingering bindings to prevent cross test pollution
* as observed when running java 7
*
* @throws Exception on test failure
*/
@After
public void after() throws Exception {
InitialContext icontext = new InitialContext();
NamingEnumeration<Binding> bindings = icontext.listBindings("");
List<String> names = new ArrayList<String>();
while (bindings.hasMore()) {
Binding bd = (Binding) bindings.next();
names.add(bd.getName());
}
for (String name : names) {
icontext.unbind(name);
}
}
use of javax.naming.InitialContext in project jetty.project by eclipse.
the class TestNamingEntries method testResourceReferenceable.
@Test
public void testResourceReferenceable() throws Exception {
SomeOtherObject someOtherObj = new SomeOtherObject("100");
InitialContext icontext = new InitialContext();
Resource res = new Resource("resourceByReferenceable", someOtherObj);
Object o = icontext.lookup("resourceByReferenceable");
assertNotNull(o);
assertTrue(o instanceof SomeOtherObject);
assertEquals(((SomeOtherObject) o).getValue(), 100);
}
use of javax.naming.InitialContext in project jetty.project by eclipse.
the class TestNamingEntryUtil method testGetContextForScope.
@Test
public void testGetContextForScope() throws Exception {
ScopeA scope = new ScopeA();
try {
Context c = NamingEntryUtil.getContextForScope(scope);
fail("context should not exist");
} catch (NameNotFoundException e) {
//expected
}
InitialContext ic = new InitialContext();
Context scopeContext = ic.createSubcontext(NamingEntryUtil.getNameForScope(scope));
assertNotNull(scopeContext);
try {
Context c = NamingEntryUtil.getContextForScope(scope);
assertNotNull(c);
} catch (NameNotFoundException e) {
fail(e.getMessage());
}
}
Aggregations