Created
February 19, 2016 13:16
-
-
Save dilnei/729435189ea5a0bd5b32 to your computer and use it in GitHub Desktop.
CLasse abstrata para testes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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