Search in sources :

Example 1 with JpaTransactionManager

use of cn.taketoday.orm.jpa.JpaTransactionManager in project today-infrastructure by TAKETODAY.

the class PersistenceContextTransactionTests method setup.

@BeforeEach
public void setup() {
    factory = mock(EntityManagerFactory.class);
    manager = mock(EntityManager.class);
    tx = mock(EntityTransaction.class);
    JpaTransactionManager tm = new JpaTransactionManager(factory);
    tt = new TransactionTemplate(tm);
    given(factory.createEntityManager()).willReturn(manager);
    given(manager.getTransaction()).willReturn(tx);
    given(manager.isOpen()).willReturn(true);
    bean = new EntityManagerHoldingBean();
    @SuppressWarnings("serial") PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {

        @Override
        protected EntityManagerFactory findEntityManagerFactory(@Nullable String unitName, String requestingBeanName) {
            return factory;
        }
    };
    pabpp.processDependencies(null, bean, "bean");
    assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
    assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
}
Also used : EntityTransaction(jakarta.persistence.EntityTransaction) EntityManager(jakarta.persistence.EntityManager) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) JpaTransactionManager(cn.taketoday.orm.jpa.JpaTransactionManager) TransactionTemplate(cn.taketoday.transaction.support.TransactionTemplate) Nullable(cn.taketoday.lang.Nullable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with JpaTransactionManager

use of cn.taketoday.orm.jpa.JpaTransactionManager in project today-framework by TAKETODAY.

the class PersistenceContextTransactionTests method setup.

@BeforeEach
public void setup() {
    factory = mock(EntityManagerFactory.class);
    manager = mock(EntityManager.class);
    tx = mock(EntityTransaction.class);
    JpaTransactionManager tm = new JpaTransactionManager(factory);
    tt = new TransactionTemplate(tm);
    given(factory.createEntityManager()).willReturn(manager);
    given(manager.getTransaction()).willReturn(tx);
    given(manager.isOpen()).willReturn(true);
    bean = new EntityManagerHoldingBean();
    @SuppressWarnings("serial") PersistenceAnnotationBeanPostProcessor pabpp = new PersistenceAnnotationBeanPostProcessor() {

        @Override
        protected EntityManagerFactory findEntityManagerFactory(@Nullable String unitName, String requestingBeanName) {
            return factory;
        }
    };
    pabpp.processDependencies(null, bean, "bean");
    assertThat(TransactionSynchronizationManager.getResourceMap().isEmpty()).isTrue();
    assertThat(TransactionSynchronizationManager.isSynchronizationActive()).isFalse();
}
Also used : EntityTransaction(jakarta.persistence.EntityTransaction) EntityManager(jakarta.persistence.EntityManager) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) JpaTransactionManager(cn.taketoday.orm.jpa.JpaTransactionManager) TransactionTemplate(cn.taketoday.transaction.support.TransactionTemplate) Nullable(cn.taketoday.lang.Nullable) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

Nullable (cn.taketoday.lang.Nullable)2 JpaTransactionManager (cn.taketoday.orm.jpa.JpaTransactionManager)2 TransactionTemplate (cn.taketoday.transaction.support.TransactionTemplate)2 EntityManager (jakarta.persistence.EntityManager)2 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)2 EntityTransaction (jakarta.persistence.EntityTransaction)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2