The following test case illustrates the problem. I must call twice new InitialContext(configuration) to be able to lookup the java:/openejb folder, otherwise a NameNotFoundException is thrown. I call OpenEJB.destroy() in order to reinitialize OpenEJB context between the two tests calls.
@Test
public void testJNDI_OK() throws Exception
{
Properties configuration = new Properties();
configuration.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
configuration.put("MyDatasource", "new://Resource?type=DataSource");
InitialContext context = new InitialContext(configuration);
context = new InitialContext(configuration);
Assert.assertNotNull(context .lookup("java:/openejb/Resource/MyDatasource"));
OpenEJB.destroy();// Otherwise testJNDIFail won't fail
}
@Test
public void testJNDI_Fail() throws Exception
{ // A NameNotFoundException is thrown
Properties configuration = new Properties();
configuration.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
configuration.put("MyDatasource", "new://Resource?type=DataSource");
InitialContext context = new InitialContext(configuration);
Assert.assertNotNull(context .lookup("java:/openejb/Resource/MyDatasource"));
OpenEJB.destroy();
}