Search in sources :

Example 11 with InitialContext

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);
}
Also used : InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 12 with InitialContext

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();
}
Also used : InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 13 with InitialContext

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);
    }
}
Also used : Binding(javax.naming.Binding) ArrayList(java.util.ArrayList) InitialContext(javax.naming.InitialContext) After(org.junit.After)

Example 14 with InitialContext

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);
}
Also used : InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 15 with InitialContext

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());
    }
}
Also used : InitialContext(javax.naming.InitialContext) Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Aggregations

InitialContext (javax.naming.InitialContext)1068 Test (org.junit.Test)325 EJBException (javax.ejb.EJBException)228 Properties (java.util.Properties)213 Context (javax.naming.Context)194 RemoteException (java.rmi.RemoteException)173 TestFailureException (org.apache.openejb.test.TestFailureException)172 NamingException (javax.naming.NamingException)168 AssertionFailedError (junit.framework.AssertionFailedError)168 JMSException (javax.jms.JMSException)167 RemoveException (javax.ejb.RemoveException)66 CreateException (javax.ejb.CreateException)57 DataSource (javax.sql.DataSource)55 Hashtable (java.util.Hashtable)54 Assembler (org.apache.openejb.assembler.classic.Assembler)47 EjbJar (org.apache.openejb.jee.EjbJar)41 NameNotFoundException (javax.naming.NameNotFoundException)40 ConfigurationFactory (org.apache.openejb.config.ConfigurationFactory)38 Connection (java.sql.Connection)37 StatelessBean (org.apache.openejb.jee.StatelessBean)30