Skip to content

Instantly share code, notes, and snippets.

@dilnei
Created February 19, 2016 13:16
Show Gist options
  • Select an option

  • Save dilnei/729435189ea5a0bd5b32 to your computer and use it in GitHub Desktop.

Select an option

Save dilnei/729435189ea5a0bd5b32 to your computer and use it in GitHub Desktop.
CLasse abstrata para testes
package br.com.myproject.model.repository;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
* Abstract class used for testing, responsible for open connection to HSQLDB
* and finalize the resources after the tests.
*
* @author Dilnei_Cunha
*/
public abstract class AbstractRepositoryTest {
protected static EntityManagerFactory emFactory;
protected static EntityManager em;
/**
* Open connection with database, create EntityManager and open transaction.
*/
@BeforeClass
public static void setUp0() {
emFactory = Persistence.createEntityManagerFactory("myproject-ejbPU-test");
em = emFactory.createEntityManager();
em.getTransaction().begin();
}
/**
* Commit transaction, finalize EntityManager and factory.
*/
@AfterClass
public static void tearDown0() {
em.getTransaction().commit();
em.close();
emFactory.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment