package de.hilling.junit.cdi.jee;
import de.hilling.junit.cdi.annotations.GlobalTestImplementation;
import de.hilling.junit.cdi.scope.TestSuiteScoped;
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
/**
* Producer for EntityManagers used in cdi-test unit tests.
*/
@TestSuiteScoped
public class EntityManagerTestProducer {
private EntityManagerFactory entityManagerFactory;
@Inject
private JEETestConfiguration configuration;
@PostConstruct
protected void createEntityManagerFactory() {
entityManagerFactory = Persistence.createEntityManagerFactory(configuration.getTestPersistenceUnitName());
}
@Produces
@GlobalTestImplementation
@RequestScoped
protected EntityManagerFactory provideTestEntityManagerFactory() {
return entityManagerFactory;
}
@Produces
@GlobalTestImplementation
@RequestScoped
protected EntityManager provideTestEntityManager() {
return entityManagerFactory.createEntityManager();
}
}