EntityManagerFactory not found in JNDI when running TestNG
mmaia Apr 4, 2010 8:01 AMI have implemented JpaIdentityStore for authentication. It's working perfectly when running JBoss and deploying the seam project.
I have an Observer to listen to login events:
package br.com.anototudo.seguranca; import ... @Name("autenticacaoObserver") public class AutenticacaoObserver { @Logger private Log log; @In private Credentials credentials; @Observer(Credentials.EVENT_INIT_CREDENTIALS) public void credentialsInicializadas() { log.info("Credenciais foram inicializadas"); } @Observer(Identity.EVENT_LOGIN_SUCCESSFUL) public void loginSuccessful() { log.info("O login foi efetuado com sucesso para u Usuario: #0", credentials.getUsername()); } @Observer(Identity.EVENT_LOGIN_FAILED) public void loginFailed(Exception e) { log.info("Erro na autenticacao do usuario: #0, Excecao: #1, Causa: #2", credentials.getUsername(), e, e.getCause()); } /** * Coloca o objeto User na sessao ao fazer o login. * @param user */ @Observer(JpaIdentityStore.EVENT_USER_AUTHENTICATED) public void usuarioAutenticado(User user) { log.info("Login do usuario: " + user.getEmail()); Contexts.getSessionContext().set("user", user); } }
I'm trying to write an Integration test based on seam examples to test login. When I run my test class I get the following error reported by loginFailed method from my observer above:
INFO [br.com.anototudo.seguranca.AutenticacaoObserver] Erro na autenticacao do usuario: maia.marcos@gmail.com, Excecao: javax.security.auth.login.LoginException: EntityManagerFactory not found in JNDI : java:/anototudoEntityManagerFactory, Causa: java.lang.IllegalArgumentException: EntityManagerFactory not found in JNDI : java:/anototudoEntityManagerFactory
In my componentx.xml I have declared my entityManager with the following code:
<persistence:managed-persistence-context name="entityManager" auto-create="true" entity-manager-factory="#{anototudo}" persistence-unit-jndi-name="java:/anototudoEntityManagerFactory"/>
As I mentioned it's all working perfectly when running on JBoss AS. The error is only when I run my test class: