Demoiselle 2.4.0: Error executing test with JUnit

4

I have a project built from the Demoiselle archetype for Maven . The generated application is the one that exemplifies the Demoiselle, containing a register of bookmarks .

The developer who generated zero revision of the application is no longer accessible. This application has been changed to implement several specific registers, from being the example application to becoming an application of our own business domain.

The goal is now to add features and to implement such, make use of TDD to first write the test cases and then the application code itself (it is a legacy application where strong> was used in its genesis).

When adding the very first test case, placed below, I get an exception stack . 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);
    }
}

Exceptions received are listed below. The call list has been cropped for ease of 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's missing?

Thank you in advance!

    
asked by anonymous 18.12.2014 / 14:41

1 answer

0

Apparently the problem is in the environment configuration so that AlunoRepository.itemPorId can work. If you remove this call does it work?

It may be that the persistence.xml that your test is using is trying to bind a JNDI to a null InitialContext since the test application does not run on the application server.

For this the tests need to reset the configuration by establishing the connection to the database directly via JDBC. The "bookmark" application generated by the demoiselle-jsf-jpa archetype already gives a ready example in the file

18.12.2014 / 20:04