use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class TxNamespaceHandlerTests method invokeTransactional.
@Test
public void invokeTransactional() {
ITestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
assertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
testBean.getName();
assertThat(ptm.lastDefinition.isReadOnly()).isTrue();
assertThat(ptm.lastDefinition.getTimeout()).isEqualTo(5);
assertThat(ptm.begun).as("Should have 1 started transaction").isEqualTo(1);
assertThat(ptm.commits).as("Should have 1 committed transaction").isEqualTo(1);
// try with non-transaction
testBean.haveBirthday();
assertThat(ptm.begun).as("Should not have started another transaction").isEqualTo(1);
// try with exceptional
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> testBean.exceptional(new IllegalArgumentException("foo")));
assertThat(ptm.begun).as("Should have another started transaction").isEqualTo(2);
assertThat(ptm.rollbacks).as("Should have 1 rolled back transaction").isEqualTo(1);
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class AnnotationTransactionNamespaceHandlerTests method invokeTransactional.
@Test
public void invokeTransactional() throws Exception {
TransactionalTestBean testBean = getTestBean();
CallCountingTransactionManager ptm = (CallCountingTransactionManager) context.getBean("transactionManager");
// try with transactional
assertThat(ptm.begun).as("Should not have any started transactions").isEqualTo(0);
testBean.findAllFoos();
assertThat(ptm.begun).as("Should have 1 started transaction").isEqualTo(1);
assertThat(ptm.commits).as("Should have 1 committed transaction").isEqualTo(1);
// try with non-transaction
testBean.doSomething();
assertThat(ptm.begun).as("Should not have started another transaction").isEqualTo(1);
// try with exceptional
assertThatExceptionOfType(Throwable.class).isThrownBy(() -> testBean.exceptional(new IllegalArgumentException("foo"))).satisfies(ex -> {
assertThat(ptm.begun).as("Should have another started transaction").isEqualTo(2);
assertThat(ptm.rollbacks).as("Should have 1 rolled back transaction").isEqualTo(1);
});
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class TransactionManagerConfiguration method transactionManager2.
@Bean
@NoSynch
public PlatformTransactionManager transactionManager2() {
CallCountingTransactionManager tm = new CallCountingTransactionManager();
tm.setTransactionSynchronization(CallCountingTransactionManager.SYNCHRONIZATION_NEVER);
return tm;
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementTests method spr11915TransactionManagerAsManualSingleton.
@Test
public void spr11915TransactionManagerAsManualSingleton() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr11915Config.class);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
CallCountingTransactionManager txManager = ctx.getBean("qualifiedTransactionManager", CallCountingTransactionManager.class);
bean.saveQualifiedFoo();
assertThat(txManager.begun).isEqualTo(1);
assertThat(txManager.commits).isEqualTo(1);
assertThat(txManager.rollbacks).isEqualTo(0);
bean.saveQualifiedFooWithAttributeAlias();
assertThat(txManager.begun).isEqualTo(2);
assertThat(txManager.commits).isEqualTo(2);
assertThat(txManager.rollbacks).isEqualTo(0);
ctx.close();
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementTests method txManagerIsResolvedCorrectlyWithTxMgmtConfigurerAndPrimaryPresent.
@Test
public void txManagerIsResolvedCorrectlyWithTxMgmtConfigurerAndPrimaryPresent() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(EnableTxConfig.class, PrimaryTxManagerAndTxMgmtConfigurerConfig.class);
assertThat(ctx.getBeansOfType(TransactionManager.class)).hasSize(2);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
CallCountingTransactionManager primary = ctx.getBean("primary", CallCountingTransactionManager.class);
CallCountingTransactionManager annotationDriven = ctx.getBean("annotationDrivenTransactionManager", CallCountingTransactionManager.class);
// invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
bean.findAllFoos();
assertThat(primary.begun).isEqualTo(0);
assertThat(primary.commits).isEqualTo(0);
assertThat(primary.rollbacks).isEqualTo(0);
assertThat(annotationDriven.begun).isEqualTo(1);
assertThat(annotationDriven.commits).isEqualTo(1);
assertThat(annotationDriven.rollbacks).isEqualTo(0);
ctx.close();
}
Aggregations