-
1. Re: Cannot lookup JNDI name when start managed container in Arquillian
jayshaughnessy Oct 11, 2012 11:16 AM (in response to canhhiep)Hi,
I'm having the same issue. I'm trying to lookup the TransactionManager outside of the container. I'm using AS 7.1.1.Final and Arquillian 1.0.2.Final and testng, Unfortunately it seems that Injection of the InitialContext, EntityManager, etc does not happen outside of @Test. But I need to set some stuff up in @BeforeMethod. I would have thought injection would extend to the BeforeMethod but it does not seem to, at least not at the moment. I'm not sure if that is a bug or working as expected.
But given that it's currently the case, is there a way to do JNDI lookups? I haven't found the magic. Here is roughly what I have inside the BeforeMethod:
try {
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.as.naming.InitialContextFactory");
initialContext = new InitialContext(env);
TransactionManager tm = (TransactionManager) getInitialContext().lookup("java:jboss/TransactionManager");
} catch (Exception e) {
...
}
Which gives me: javax.naming.NameNotFoundException: java:jboss/TransactionManager
Is there something else I can try? Does this need to be a remote JNDI lookup?
Thanks, Jay
-
2. Re: Cannot lookup JNDI name when start managed container in Arquillian
jayshaughnessy Oct 31, 2012 10:08 AM (in response to jayshaughnessy)This was due to the "BeforeMethod" called twice behavior for Arquillian and testNg. By adding a check to ensure it was the in-container invocation this went away. This can be done by doing something like:
@ArquilianResource
InitialContext initialContext;
@BeforeMethod
public void before() {
if ( null == initialContext )
return;
// do beforeMethod work
}
See https://community.jboss.org/thread/173265 for more