deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rafael Pestano <>
Subject Best approach for testing repositories
Date Mon, 06 Apr 2015 20:12:31 GMT
Hi everyone,

besides OpenEJB and cdi-control-ejb used in [1] what are the alternatives
(in terms of Destaspike) for testing JPA based repositories?

For out container integration tests i usually use something like this:

  public void inicializarCenario() throws Exception {

  public void finalizarCenario() {

public void startConnection() {
    emf = Persistence.createEntityManagerFactory("TEST_PU");
    em = emf.createEntityManager();

  public void closeConnection() {

TEST_PU is in test resources and usually uses in memory db, something like

<persistence version="2.0"
xmlns="" xmlns:xsi=""

<persistence-unit name="TEST_PU" transaction-type="RESOURCE_LOCAL">
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"
<property name="javax.persistence.jdbc.driver"
value="org.hsqldb.jdbcDriver" />
            <property name="javax.persistence.jdbc.url"
value="jdbc:hsqldb:mem:." />
            <property name="javax.persistence.jdbc.user" value="sa" />
            <property name="javax.persistence.jdbc.password" value="" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.connection.shutdown" value="true"/>
            <property name="" value="create-drop"/>

The idea is to be "lighweight" and boot only JPA container so my
repositories can use the "test entityManager?

I think of something like this:

public class UserRepositoryTest {

  UserRepository userRepository;

  public void shouldInserUser(){
         User u = new User();;


Can we reach somethink like that with Deltaspike test control?

I also would like to integrate with dbunit so I can feed this test
datasource but thats another story




Rafael M. Pestano

Desenvolvedor Java Cia. de Processamento de Dados do Rio Grande do Sul
@realpestano <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message