Search in sources :

Example 21 with CallCountingTransactionManager

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

the class EnableTransactionManagementTests method spr14322FindsOnInterfaceWithInterfaceProxy.

@Test
public void spr14322FindsOnInterfaceWithInterfaceProxy() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigA.class);
    TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class);
    CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
    bean.saveFoo();
    bean.saveBar();
    assertThat(txManager.begun).isEqualTo(2);
    assertThat(txManager.commits).isEqualTo(2);
    assertThat(txManager.rollbacks).isEqualTo(0);
    ctx.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) Test(org.junit.jupiter.api.Test)

Example 22 with CallCountingTransactionManager

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

the class LookUpTxMgrViaTransactionManagementConfigurerWithSingleTxMgrBeanTests method transactionalTest.

@Test
void transactionalTest() {
    assertThat(txManager.begun).isEqualTo(0);
    assertThat(txManager.inflight).isEqualTo(0);
    assertThat(txManager.commits).isEqualTo(0);
    assertThat(txManager.rollbacks).isEqualTo(0);
    CallCountingTransactionManager annotationDriven = config.annotationDriven;
    assertThat(annotationDriven.begun).isEqualTo(1);
    assertThat(annotationDriven.inflight).isEqualTo(1);
    assertThat(annotationDriven.commits).isEqualTo(0);
    assertThat(annotationDriven.rollbacks).isEqualTo(0);
}
Also used : CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) Test(org.junit.jupiter.api.Test)

Example 23 with CallCountingTransactionManager

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

the class LookUpTxMgrViaTransactionManagementConfigurerWithSingleTxMgrBeanTests method afterTransaction.

@AfterTransaction
void afterTransaction() {
    assertThat(txManager.begun).isEqualTo(0);
    assertThat(txManager.inflight).isEqualTo(0);
    assertThat(txManager.commits).isEqualTo(0);
    assertThat(txManager.rollbacks).isEqualTo(0);
    CallCountingTransactionManager annotationDriven = config.annotationDriven;
    assertThat(annotationDriven.begun).isEqualTo(1);
    assertThat(annotationDriven.inflight).isEqualTo(0);
    assertThat(annotationDriven.commits).isEqualTo(0);
    assertThat(annotationDriven.rollbacks).isEqualTo(1);
}
Also used : CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) AfterTransaction(org.springframework.test.context.transaction.AfterTransaction)

Example 24 with CallCountingTransactionManager

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

the class BeanFactoryTransactionTests method testCglibTransactionProxyImplementsNoInterfaces.

@Test
public void testCglibTransactionProxyImplementsNoInterfaces() {
    ImplementsNoInterfaces ini = (ImplementsNoInterfaces) factory.getBean("cglibNoInterfaces");
    assertThat(AopUtils.isCglibProxy(ini)).as("testBean is CGLIB advised").isTrue();
    boolean condition = ini instanceof TransactionalProxy;
    assertThat(condition).isTrue();
    String newName = "Gordon";
    // Install facade
    CallCountingTransactionManager ptm = new CallCountingTransactionManager();
    PlatformTransactionManagerFacade.delegate = ptm;
    ini.setName(newName);
    assertThat(ini.getName()).isEqualTo(newName);
    assertThat(ptm.commits).isEqualTo(2);
}
Also used : CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) Test(org.junit.jupiter.api.Test)

Example 25 with CallCountingTransactionManager

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

the class BeanFactoryTransactionTests method testDynamicTargetSource.

/**
 * Test that we can set the target to a dynamic TargetSource.
 */
@Test
public void testDynamicTargetSource() {
    // Install facade
    CallCountingTransactionManager txMan = new CallCountingTransactionManager();
    PlatformTransactionManagerFacade.delegate = txMan;
    TestBean tb = (TestBean) factory.getBean("hotSwapped");
    assertThat(tb.getAge()).isEqualTo(666);
    int newAge = 557;
    tb.setAge(newAge);
    assertThat(tb.getAge()).isEqualTo(newAge);
    TestBean target2 = new TestBean();
    target2.setAge(65);
    HotSwappableTargetSource ts = (HotSwappableTargetSource) factory.getBean("swapper");
    ts.swap(target2);
    assertThat(tb.getAge()).isEqualTo(target2.getAge());
    tb.setAge(newAge);
    assertThat(target2.getAge()).isEqualTo(newAge);
    assertThat(txMan.inflight).isEqualTo(0);
    assertThat(txMan.commits).isEqualTo(2);
    assertThat(txMan.rollbacks).isEqualTo(0);
}
Also used : DerivedTestBean(org.springframework.beans.testfixture.beans.DerivedTestBean) TestBean(org.springframework.beans.testfixture.beans.TestBean) ITestBean(org.springframework.beans.testfixture.beans.ITestBean) HotSwappableTargetSource(org.springframework.aop.target.HotSwappableTargetSource) CallCountingTransactionManager(org.springframework.transaction.testfixture.CallCountingTransactionManager) Test(org.junit.jupiter.api.Test)

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