use of cn.taketoday.orm.jpa.persistenceunit.MutablePersistenceUnitInfo in project today-infrastructure by TAKETODAY.
the class LocalContainerEntityManagerFactoryBeanTests method testApplicationManagedEntityManagerWithJtaTransaction.
@Test
public void testApplicationManagedEntityManagerWithJtaTransaction() throws Exception {
Object testEntity = new Object();
// This one's for the tx (shared)
EntityManager sharedEm = mock(EntityManager.class);
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
// This is the application-specific one
EntityManager mockEm = mock(EntityManager.class);
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
MutablePersistenceUnitInfo pui = ((MutablePersistenceUnitInfo) cefb.getPersistenceUnitInfo());
pui.setTransactionType(PersistenceUnitTransactionType.JTA);
JpaTransactionManager jpatm = new JpaTransactionManager();
jpatm.setEntityManagerFactory(cefb.getObject());
TransactionStatus txStatus = jpatm.getTransaction(new DefaultTransactionAttribute());
EntityManagerFactory emf = cefb.getObject();
assertThat(cefb.getObject()).as("EntityManagerFactory reference must be cached after init").isSameAs(emf);
assertThat(emf).as("EMF must be proxied").isNotSameAs(mockEmf);
EntityManager em = emf.createEntityManager();
em.joinTransaction();
assertThat(em.contains(testEntity)).isFalse();
jpatm.commit(txStatus);
cefb.destroy();
verify(mockEm).joinTransaction();
verify(mockEm).contains(testEntity);
verify(mockEmf).close();
}
use of cn.taketoday.orm.jpa.persistenceunit.MutablePersistenceUnitInfo in project today-framework by TAKETODAY.
the class LocalContainerEntityManagerFactoryBeanTests method testApplicationManagedEntityManagerWithJtaTransaction.
@Test
public void testApplicationManagedEntityManagerWithJtaTransaction() throws Exception {
Object testEntity = new Object();
// This one's for the tx (shared)
EntityManager sharedEm = mock(EntityManager.class);
given(sharedEm.getTransaction()).willReturn(new NoOpEntityTransaction());
// This is the application-specific one
EntityManager mockEm = mock(EntityManager.class);
given(mockEmf.createEntityManager()).willReturn(sharedEm, mockEm);
LocalContainerEntityManagerFactoryBean cefb = parseValidPersistenceUnit();
MutablePersistenceUnitInfo pui = ((MutablePersistenceUnitInfo) cefb.getPersistenceUnitInfo());
pui.setTransactionType(PersistenceUnitTransactionType.JTA);
JpaTransactionManager jpatm = new JpaTransactionManager();
jpatm.setEntityManagerFactory(cefb.getObject());
TransactionStatus txStatus = jpatm.getTransaction(new DefaultTransactionAttribute());
EntityManagerFactory emf = cefb.getObject();
assertThat(cefb.getObject()).as("EntityManagerFactory reference must be cached after init").isSameAs(emf);
assertThat(emf).as("EMF must be proxied").isNotSameAs(mockEmf);
EntityManager em = emf.createEntityManager();
em.joinTransaction();
assertThat(em.contains(testEntity)).isFalse();
jpatm.commit(txStatus);
cefb.destroy();
verify(mockEm).joinTransaction();
verify(mockEm).contains(testEntity);
verify(mockEmf).close();
}
Aggregations