use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class Rollback method testProgrammaticRollback.
@Test
void testProgrammaticRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
boolean condition = bean instanceof CallCountingTransactionManager;
assertThat(condition).isTrue();
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
Rollback rb = (Rollback) bf.getBean("rollback");
assertThat(txMan.commits).isEqualTo(0);
rb.rollbackOnly(false);
assertThat(txMan.commits).as("Transaction counts match").isEqualTo(1);
assertThat(txMan.rollbacks).isEqualTo(0);
// Will cause rollback only
rb.rollbackOnly(true);
assertThat(txMan.rollbacks).isEqualTo(1);
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class Rollback method testRollbackRulesOnMethodCauseRollback.
/**
* Should not roll back on servlet exception.
*/
@Test
void testRollbackRulesOnMethodCauseRollback() throws Exception {
BeanFactory bf = getBeanFactory();
Rollback rb = (Rollback) bf.getBean("rollback");
CallCountingTransactionManager txMan = (CallCountingTransactionManager) bf.getBean(TXMANAGER_BEAN_NAME);
OrderedTxCheckAdvisor txc = (OrderedTxCheckAdvisor) bf.getBean("orderedBeforeTransaction");
assertThat(txc.getCountingBeforeAdvice().getCalls()).isEqualTo(0);
assertThat(txMan.commits).isEqualTo(0);
rb.echoException(null);
// Fires only on setters
assertThat(txc.getCountingBeforeAdvice().getCalls()).isEqualTo(0);
assertThat(txMan.commits).as("Transaction counts match").isEqualTo(1);
assertThat(txMan.rollbacks).isEqualTo(0);
Exception ex = new Exception();
try {
rb.echoException(ex);
} catch (Exception actual) {
assertThat(actual).isEqualTo(ex);
}
assertThat(txMan.rollbacks).as("Transaction counts match").isEqualTo(1);
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementIntegrationTests method implicitTxManager.
@Test
void implicitTxManager() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImplicitTxManagerConfig.class);
FooRepository fooRepository = ctx.getBean(FooRepository.class);
fooRepository.findAll();
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
assertThat(txManager.begun).isEqualTo(1);
assertThat(txManager.commits).isEqualTo(1);
assertThat(txManager.rollbacks).isEqualTo(0);
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementTests method txManagerIsResolvedCorrectlyWhenMultipleManagersArePresentAndOneIsPrimary.
@Test
public void txManagerIsResolvedCorrectlyWhenMultipleManagersArePresentAndOneIsPrimary() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(EnableTxConfig.class, PrimaryMultiTxManagerConfig.class);
assertThat(ctx.getBeansOfType(TransactionManager.class)).hasSize(2);
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
CallCountingTransactionManager primary = ctx.getBean("primary", CallCountingTransactionManager.class);
CallCountingTransactionManager txManager2 = ctx.getBean("txManager2", CallCountingTransactionManager.class);
// invoke a transactional method, causing the PlatformTransactionManager bean to be resolved.
bean.findAllFoos();
assertThat(primary.begun).isEqualTo(1);
assertThat(primary.commits).isEqualTo(1);
assertThat(primary.rollbacks).isEqualTo(0);
assertThat(txManager2.begun).isEqualTo(0);
assertThat(txManager2.commits).isEqualTo(0);
assertThat(txManager2.rollbacks).isEqualTo(0);
ctx.close();
}
use of org.springframework.transaction.testfixture.CallCountingTransactionManager in project spring-framework by spring-projects.
the class EnableTransactionManagementTests method spr14322FindsOnInterfaceWithCglibProxy.
@Test
public void spr14322FindsOnInterfaceWithCglibProxy() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Spr14322ConfigB.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();
}
Aggregations