Seam and testing fail. TestNG
maykellff Jan 22, 2008 10:34 AMHi all, i'am following the book "Begining JBoss Seam. From novice to Profesional" like a helper to introduce my self in Seam. Now i've transformed a simple jsf application into a Seam-EJB3 application, everything works well but the tests. I'am using Red Hat Developer Studio, it comes with the TestNG plugin, i try to use TestNG to run a test i wrotte but always i get the same error.
Can it be something related to the package structure i have? Maybe TestNG most have some specific package structure in order to look for the resources it need to run the tests.
Any help will be very appreciated.
This is the error i get:
[Parser] Running:
D:\workspaceRHDS\jsfTest\temp-testng-customsuite.xml
log4j:WARN No appenders could be found for logger (org.hibernate.ejb.Version).
log4j:WARN Please initialize the log4j system properly.
FAILED CONFIGURATION: @BeforeClass init
javax.persistence.PersistenceException: No Persistence provider for EntityManager named jsfTest
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
at pruebas.ExpedienteFacadeTest.init(ExpedienteFacadeTest.java:47)
... Removed 22 stack frames
SKIPPED CONFIGURATION: @AfterClass destroy
SKIPPED: testBuscarExpediente
===============================================
pruebas.ExpedienteFacadeTest
Tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
===============================================
jsfTest
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================
I don't know what is happening, i've tried every posible solution but without results. It seens like it doesn't found the persistence.xml.
This is my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="jsfTest">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jsfTestDatasource</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.show_sql" value="true"/>
<property name="jboss.entity.manager.factory.jndi.name" value="java:/jsfTestEntityManagerFactory"/>
</properties>
</persistence-unit>
</persistence>
This is my components.xml:
<?xml version="1.0" encoding="UTF-8"?>
<components>
<component name="org.jboss.seam.core.init">
<property name="debug">true</property>
<property name="myFacesLifecycleBug">true</property>
<property name="jndiPattern">jsfTest/#{ejbName}/local</property>
</component>
<managed-persistence-context name="em" auto-create="true" persistence-unit-jndi-name="java:/jsfTestEntityManagerFactory"/>
<component name="exampleExpediente" class="com.domain.Expediente"/>
<entity-query name="queryExpedientes" ejbql="select e from Expediente e"/>
<persistence:managed-persistence-context name="em"
auto-create="true"
entity-manager-factory="#{emf}"/>
<persistence:entity-manager-factory name="emf"
persistence-unit-name="jsfTest"/>
</components>
This is my test class:
package pruebas;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.jboss.seam.annotations.In;
import org.testng.annotations.Configuration;
import org.testng.annotations.Test;
import com.domain.Expediente;
import com.domain.nomenclador.NTipoAcusado;
import com.facade.ExpedienteFacade;
import com.facade.impl.ExpedienteFacadeImpl;
public class ExpedienteFacadeTest {
@In
EntityManagerFactory emf;
@Test
public void testBuscarExpediente()
{
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
NTipoAcusado ta = new NTipoAcusado();
ta.setId_tipoacusado(1);ta.setValor("Acusado Libre");
Expediente exp = new Expediente();
exp.setTipoAcusado(ta);
ExpedienteFacadeImpl ef = new ExpedienteFacadeImpl();
ef.setEm(em);ef.setExpediente(exp);
String strResult = ef.buscarExpediente();
assert "some".equals(strResult);
em.getTransaction().rollback();
em.close();
}
@Configuration(beforeTestClass=true)
public void init()
{
emf = Persistence.createEntityManagerFactory("jsfTest");
}
@Configuration(afterTestClass=true)
public void destroy()
{
emf.close();
}
}