Search in sources :

Example 11 with BeanFactory

use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerDefaultSeveralTimes.

@Test
public void determineTransactionManagerDefaultSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
    PlatformTransactionManager txManager = mock(PlatformTransactionManager.class);
    given(beanFactory.getBean(TransactionManager.class)).willReturn(txManager);
    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(TransactionManager.class);
}
Also used : TransactionManager(cn.taketoday.transaction.TransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) BeanFactory(cn.taketoday.beans.factory.BeanFactory) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 12 with BeanFactory

use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerWithQualifierAndDefaultName.

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

Example 13 with BeanFactory

use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerWithQualifierSeveralTimes.

@Test
public void determineTransactionManagerWithQualifierSeveralTimes() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
    PlatformTransactionManager txManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setQualifier("fooTransactionManager");
    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)).containsBean("fooTransactionManager");
    verify(beanFactory, times(1)).getBean("fooTransactionManager", PlatformTransactionManager.class);
}
Also used : TransactionManager(cn.taketoday.transaction.TransactionManager) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) BeanFactory(cn.taketoday.beans.factory.BeanFactory) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 14 with BeanFactory

use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerWithQualifierAndDefault.

@Test
public void determineTransactionManagerWithQualifierAndDefault() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    PlatformTransactionManager transactionManager = mock(PlatformTransactionManager.class);
    TransactionInterceptor ti = transactionInterceptorWithTransactionManager(transactionManager, beanFactory);
    PlatformTransactionManager fooTransactionManager = associateTransactionManager(beanFactory, "fooTransactionManager");
    DefaultTransactionAttribute attribute = new DefaultTransactionAttribute();
    attribute.setQualifier("fooTransactionManager");
    assertThat(ti.determineTransactionManager(attribute)).isSameAs(fooTransactionManager);
}
Also used : BeanFactory(cn.taketoday.beans.factory.BeanFactory) PlatformTransactionManager(cn.taketoday.transaction.PlatformTransactionManager) Test(org.junit.jupiter.api.Test)

Example 15 with BeanFactory

use of cn.taketoday.beans.factory.BeanFactory in project today-infrastructure by TAKETODAY.

the class TransactionInterceptorTests method determineTransactionManagerWithNoTransactionAttribute.

@Test
public void determineTransactionManagerWithNoTransactionAttribute() {
    BeanFactory beanFactory = mock(BeanFactory.class);
    TransactionInterceptor ti = simpleTransactionInterceptor(beanFactory);
    assertThat(ti.determineTransactionManager(null)).isNull();
}
Also used : BeanFactory(cn.taketoday.beans.factory.BeanFactory) Test(org.junit.jupiter.api.Test)

Aggregations

BeanFactory (cn.taketoday.beans.factory.BeanFactory)80 Test (org.junit.jupiter.api.Test)60 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)24 StandardBeanFactory (cn.taketoday.beans.factory.support.StandardBeanFactory)16 PlatformTransactionManager (cn.taketoday.transaction.PlatformTransactionManager)16 ClassPathXmlApplicationContext (cn.taketoday.context.support.ClassPathXmlApplicationContext)10 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)8 CallCountingTransactionManager (cn.taketoday.testfixture.transaction.CallCountingTransactionManager)8 TransactionManager (cn.taketoday.transaction.TransactionManager)8 NestedTestBean (cn.taketoday.beans.testfixture.beans.NestedTestBean)6 List (java.util.List)6 DataSource (javax.sql.DataSource)6 Advised (cn.taketoday.aop.framework.Advised)4 BeansException (cn.taketoday.beans.BeansException)4 FatalBeanException (cn.taketoday.beans.FatalBeanException)4 NoSuchBeanDefinitionException (cn.taketoday.beans.factory.NoSuchBeanDefinitionException)4 Nullable (cn.taketoday.lang.Nullable)4 Collection (java.util.Collection)4 Set (java.util.Set)4 ServletException (jakarta.servlet.ServletException)3