4
I have a project built from the archetype of Demoiselle for Maven. The generated application is the one that exemplifies the Demoiselle, containing a register of bookmarks.
The programmer who generated the zero application revision is no longer accessible. This application has been modified to implement several specific registrations, no longer being the example application to become a proprietary application of our business domain.
The goal now is to add functionality and to implement such, make use of TDD to first write the test cases and then the application code itself (is a legacy application, where the TDD nay was used in its genesis).
By adding the very first test case, placed below, I get a Exception stack. The details are placed below.
The test case is as follows:
package br.ufpr.sap.hibernate.tests;
// imports diversos
@RunWith(DemoiselleRunner.class)
public class AlunoRepositorioTests {
@Inject
AlunoRepository alunos;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void shouldSelecionarUmAlunoESeusObjetosRelacionados() {
// Preparar
Long idAluno = 31106L;
// Executar
Aluno aluno = alunos.itemPorId(idAluno);
// Avaliar
assertNotNull(aluno);
}
}
The exceptions received are below. The call list has been cropped for easy reading.
org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct public br.gov.frameworkdemoiselle.internal.producer.EntityManagerFactoryProducer.loadPersistenceUnits() on br.gov.frameworkdemoiselle.internal.producer.EntityManagerFactoryProducer@68de8813
at org.jboss.weld.bean.AbstractClassBean.defaultPostConstruct(AbstractClassBean.java:400)
... muitas chamadas
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
... muitas chamadas
at org.jboss.weld.bean.AbstractClassBean.defaultPostConstruct(AbstractClassBean.java:398)
... 69 more
Caused by: br.gov.frameworkdemoiselle.DemoiselleException: javax.persistence.PersistenceException: [PersistenceUnit: gd0] Unable to build EntityManagerFactory
at br.gov.frameworkdemoiselle.internal.producer.EntityManagerFactoryProducer.loadPersistenceUnits(EntityManagerFactoryProducer.java:107)
... 79 more
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: gd0] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
... muitas chamadas
at br.gov.frameworkdemoiselle.internal.producer.EntityManagerFactoryProducer.loadPersistenceUnits(EntityManagerFactoryProducer.java:105)
... 79 more
Caused by: org.hibernate.service.jndi.JndiException: Error parsing JNDI name [java:jboss/env/jdbc/gd]
at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:92)
... muitas chamadas
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
... 85 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(Unknown Source)
at javax.naming.InitialContext.getNameParser(Unknown Source)
at org.hibernate.service.jndi.internal.JndiServiceImpl.parseName(JndiServiceImpl.java:86)
... 101 more
What is missing?
Thanks in advance!
Thank you for the answer. To avoid the problem, simply do not inject the repository
alunos
, simply commenting on the annotation@Inject
. This suggests to me that the problem is not related to the repository itself or what happens within it, but specifically to the attempt to inject the repository in the test case.– AlexSC
I have performed tests with Junit on other projects not based on Demoiselle and they run without problem. These other tests feature a Junit Runner simple that I found on the Internet to support the injection of dependencies and the production of
EntityManager
when necessary. So, faced with this, it seems to me that the problem is somehow related to the Demoiselle.– AlexSC