Add test
This commit adds a test that reproduces the behaviour described in
SPR-11915 and validates that the fix introduced in f8b6114440 works
as expected.
Issue: SPR-11915
This commit is contained in:
parent
49e960c151
commit
5ed20d21b1
|
|
@ -118,6 +118,10 @@ public class AnnotationTransactionNamespaceHandlerTests extends TestCase {
|
|||
public void saveFoo() {
|
||||
}
|
||||
|
||||
@Transactional("qualifiedTransactionManager")
|
||||
public void saveQualifiedFoo() {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void exceptional(Throwable t) throws Throwable {
|
||||
throw t;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -21,6 +21,8 @@ import java.util.Map;
|
|||
import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AdviceMode;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -33,10 +35,13 @@ import org.springframework.transaction.annotation.AnnotationTransactionNamespace
|
|||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* Tests demonstrating use of @EnableTransactionManagement @Configuration classes.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Stephane Nicoll
|
||||
* @since 3.1
|
||||
*/
|
||||
public class EnableTransactionManagementTests {
|
||||
|
|
@ -101,6 +106,21 @@ public class EnableTransactionManagementTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spr11915() {
|
||||
AnnotationConfigApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(Spr11915Config.class);
|
||||
|
||||
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
|
||||
bean.saveQualifiedFoo();
|
||||
|
||||
CallCountingTransactionManager txManager = ctx
|
||||
.getBean("qualifiedTransactionManager", CallCountingTransactionManager.class);
|
||||
assertThat(txManager.begun, equalTo(1));
|
||||
assertThat(txManager.commits, equalTo(1));
|
||||
assertThat(txManager.rollbacks, equalTo(0));
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
|
|
@ -118,6 +138,25 @@ public class EnableTransactionManagementTests {
|
|||
static class EnableAspectJTxConfig {
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
static class Spr11915Config {
|
||||
|
||||
@Autowired
|
||||
private ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@PostConstruct
|
||||
public void initializeApp() {
|
||||
applicationContext.getBeanFactory().registerSingleton(
|
||||
"qualifiedTransactionManager", new CallCountingTransactionManager());
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TransactionalTestBean testBean() {
|
||||
return new TransactionalTestBean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class TxManagerConfig {
|
||||
|
|
|
|||
Loading…
Reference in New Issue