Search in sources :

Example 26 with CallCountingTransactionManager

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

the class AnnotationTransactionNamespaceHandlerTests method nonPublicMethodsNotAdvised.

@Test
public void nonPublicMethodsNotAdvised() {
    TransactionalTestBean testBean = getTestBean();
    CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
    assertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
    testBean.annotationsOnProtectedAreIgnored();
    assertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
}
Also used : CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) Test(org.junit.jupiter.api.Test)

Example 27 with CallCountingTransactionManager

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

the class AnnotationDrivenTests method doTestWithMultipleTransactionManagers.

private void doTestWithMultipleTransactionManagers(ApplicationContext context) {
    CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.class);
    CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.class);
    TransactionalService service = context.getBean("service", TransactionalService.class);
    assertThat(AopUtils.isCglibProxy(service)).isTrue();
    service.setSomething("someName");
    assertThat(tm1.commits).isEqualTo(1);
    assertThat(tm2.commits).isEqualTo(0);
    service.doSomething();
    assertThat(tm1.commits).isEqualTo(1);
    assertThat(tm2.commits).isEqualTo(1);
    service.setSomething("someName");
    assertThat(tm1.commits).isEqualTo(2);
    assertThat(tm2.commits).isEqualTo(1);
    service.doSomething();
    assertThat(tm1.commits).isEqualTo(2);
    assertThat(tm2.commits).isEqualTo(2);
}
Also used : CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager)

Aggregations

CallCountingTransactionManager (org.springframework.transaction.testfixture.CallCountingTransactionManager)27 Test (org.junit.jupiter.api.Test)24 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)3 ServletException (jakarta.servlet.ServletException)2 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)2 TestBean (org.springframework.beans.testfixture.beans.TestBean)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Advised (org.springframework.aop.framework.Advised)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 HotSwappableTargetSource (org.springframework.aop.target.HotSwappableTargetSource)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1 Bean (org.springframework.context.annotation.Bean)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 AfterTransaction (org.springframework.test.context.transaction.AfterTransaction)1 NoTransactionException (org.springframework.transaction.NoTransactionException)1 TransactionAttribute (org.springframework.transaction.interceptor.TransactionAttribute)1 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)1