Search in sources :

Example 66 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.

the class TransactionInterceptorTests method determineTransactionManagerWithNoBeanFactory.

@Test
public void determineTransactionManagerWithNoBeanFactory() {
    PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
    TransactionInterceptor ti = transactionInterceptorWithTransactionManager(transactionManager, null);
    assertThat(ti.determineTransactionManager(new DefaultTransactionAttribute())).isSameAs(transactionManager);
}
Also used : PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 67 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.

the class TransactionInterceptorTests method determineTransactionManagerWithBeanNameSeveralTimes.

@Test
public void determineTransactionManagerWithBeanNameSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("fooTransactionManager", beanFactory);
    PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    TransactionManager actual = ti.determineTransactionManager(attribute);
    assertThat(actual).isSameAs(txManager);
    // Call again, should be cached
    TransactionManager actual2 = ti.determineTransactionManager(attribute);
    assertThat(actual2).isSameAs(txManager);
    verify(beanFactory, times(1)).getBean("fooTransactionManager", TransactionManager.class);
}
Also used : TransactionManager(org.springframework.transaction.TransactionManager) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) BeanFactory(org.springframework.beans.factory.BeanFactory) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 68 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.

the class TransactionInterceptorTests method associateTransactionManager.

private PlatformTransactionManager associateTransactionManager(BeanFactory beanFactory, String name) {
    PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
    given(beanFactory.containsBean(name)).willReturn(true);
    given(beanFactory.getBean(name, TransactionManager.class)).willReturn(transactionManager);
    return transactionManager;
}
Also used : PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager)

Example 69 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.

the class TransactionInterceptorTests method determineTransactionManagerWithEmptyQualifierAndDefaultName.

@Test
public void determineTransactionManagerWithEmptyQualifierAndDefaultName() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    PlatformTransactionManager defaultTransactionManager = associateTransactionManager(beanFactory, "defaultTransactionManager");
    TransactionInterceptor ti = transactionInterceptorWithTransactionManagerName("defaultTransactionManager", beanFactory);
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setQualifier("");
    assertThat(ti.determineTransactionManager(attribute)).isSameAs(defaultTransactionManager);
}
Also used : BeanFactory(org.springframework.beans.factory.BeanFactory) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 70 with PlatformTransactionManager

use of org.springframework.transaction.PlatformTransactionManager in project spring-framework by spring-projects.

the class TransactionInterceptorTests method determineTransactionManagerWithNoBeanFactoryAndNoTransactionAttribute.

@Test
public void determineTransactionManagerWithNoBeanFactoryAndNoTransactionAttribute() {
    PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
    TransactionInterceptor ti = transactionInterceptorWithTransactionManager(transactionManager, null);
    assertThat(ti.determineTransactionManager(null)).isSameAs(transactionManager);
}
Also used : PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Aggregations

PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)74 Test (org.junit.jupiter.api.Test)24 TransactionStatus (org.springframework.transaction.TransactionStatus)15 Test (org.junit.Test)14 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)10 TestBean (org.springframework.beans.testfixture.beans.TestBean)10 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)9 BeanFactory (org.springframework.beans.factory.BeanFactory)8 Method (java.lang.reflect.Method)7 CannotCreateTransactionException (org.springframework.transaction.CannotCreateTransactionException)7 TransactionException (org.springframework.transaction.TransactionException)7 UnexpectedRollbackException (org.springframework.transaction.UnexpectedRollbackException)7 StreamCapableTransactionalOperationAdapter (org.broadleafcommerce.common.util.StreamCapableTransactionalOperationAdapter)6 HeuristicCompletionException (org.springframework.transaction.HeuristicCompletionException)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 DataSource (javax.sql.DataSource)5 ServiceException (org.broadleafcommerce.common.exception.ServiceException)5 PersistenceResponse (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse)5 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)5