Search in sources :

Example 11 with CallCountingTransactionManager

use of org.springframework.tests.transaction.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() throws NoSuchMethodException {
    // Install facade
    CallCountingTransactionManager txMan = new CallCountingTransactionManager();
    PlatformTransactionManagerFacade.delegate = txMan;
    TestBean tb = (TestBean) factory.getBean("hotSwapped");
    assertEquals(666, tb.getAge());
    int newAge = 557;
    tb.setAge(newAge);
    assertEquals(newAge, tb.getAge());
    TestBean target2 = new TestBean();
    target2.setAge(65);
    HotSwappableTargetSource ts = (HotSwappableTargetSource) factory.getBean("swapper");
    ts.swap(target2);
    assertEquals(target2.getAge(), tb.getAge());
    tb.setAge(newAge);
    assertEquals(newAge, target2.getAge());
    assertEquals(0, txMan.inflight);
    assertEquals(2, txMan.commits);
    assertEquals(0, txMan.rollbacks);
}
Also used : DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) HotSwappableTargetSource(org.springframework.aop.target.HotSwappableTargetSource) CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager) Test(org.junit.Test)

Example 12 with CallCountingTransactionManager

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

the class EnableTransactionManagementTests method spr14322FindsOnInterfaceWithCglibProxy.

// TODO
@Test
// TODO
@Ignore
public void spr14322FindsOnInterfaceWithCglibProxy() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigB.class);
    TransactionalTestInterface bean = ctx.getBean(TransactionalTestInterface.class);
    CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
    bean.saveFoo();
    assertThat(txManager.begun, equalTo(1));
    assertThat(txManager.commits, equalTo(1));
    assertThat(txManager.rollbacks, equalTo(0));
    ctx.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 13 with CallCountingTransactionManager

use of org.springframework.tests.transaction.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();
    assertThat(txManager.begun, equalTo(1));
    assertThat(txManager.commits, equalTo(1));
    assertThat(txManager.rollbacks, equalTo(0));
    ctx.close();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager) Test(org.junit.Test)

Example 14 with CallCountingTransactionManager

use of org.springframework.tests.transaction.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);
    assertTrue(AopUtils.isCglibProxy(service));
    service.setSomething("someName");
    assertEquals(1, tm1.commits);
    assertEquals(0, tm2.commits);
    service.doSomething();
    assertEquals(1, tm1.commits);
    assertEquals(1, tm2.commits);
    service.setSomething("someName");
    assertEquals(2, tm1.commits);
    assertEquals(1, tm2.commits);
    service.doSomething();
    assertEquals(2, tm1.commits);
    assertEquals(2, tm2.commits);
}
Also used : CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager)

Example 15 with CallCountingTransactionManager

use of org.springframework.tests.transaction.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");
    assertEquals("Should not have any started transactions", 0, ptm.begun);
    testBean.annotationsOnProtectedAreIgnored();
    assertEquals("Should not have any started transactions", 0, ptm.begun);
}
Also used : CallCountingTransactionManager(org.springframework.tests.transaction.CallCountingTransactionManager) Test(org.junit.Test)

Aggregations

CallCountingTransactionManager (org.springframework.tests.transaction.CallCountingTransactionManager)20 Test (org.junit.Test)18 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)7 BeanFactory (org.springframework.beans.factory.BeanFactory)4 ITestBean (org.springframework.tests.sample.beans.ITestBean)3 ServletException (javax.servlet.ServletException)2 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)2 TestBean (org.springframework.tests.sample.beans.TestBean)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 Ignore (org.junit.Ignore)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 NoTransactionException (org.springframework.transaction.NoTransactionException)1 TransactionInterceptor (org.springframework.transaction.interceptor.TransactionInterceptor)1