Skip to content

Commit 5ed20d2

Browse files
committed
Add test
This commit adds a test that reproduces the behaviour described in SPR-11915 and validates that the fix introduced in f8b6114 works as expected. Issue: SPR-11915
1 parent 49e960c commit 5ed20d2

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

spring-tx/src/test/java/org/springframework/transaction/annotation/AnnotationTransactionNamespaceHandlerTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ public Collection<?> findAllFoos() {
118118
public void saveFoo() {
119119
}
120120

121+
@Transactional("qualifiedTransactionManager")
122+
public void saveQualifiedFoo() {
123+
}
124+
121125
@Transactional
122126
public void exceptional(Throwable t) throws Throwable {
123127
throw t;

spring-tx/src/test/java/org/springframework/transaction/annotation/EnableTransactionManagementTests.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
2121
import org.junit.Test;
2222

2323
import org.springframework.aop.support.AopUtils;
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.context.ConfigurableApplicationContext;
2426
import org.springframework.context.annotation.AdviceMode;
2527
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2628
import org.springframework.context.annotation.Bean;
@@ -33,10 +35,13 @@
3335
import static org.hamcrest.CoreMatchers.*;
3436
import static org.junit.Assert.*;
3537

38+
import javax.annotation.PostConstruct;
39+
3640
/**
3741
* Tests demonstrating use of @EnableTransactionManagement @Configuration classes.
3842
*
3943
* @author Chris Beams
44+
* @author Stephane Nicoll
4045
* @since 3.1
4146
*/
4247
public class EnableTransactionManagementTests {
@@ -101,6 +106,21 @@ public void proxyTypeAspectJCausesRegistrationOfAnnotationTransactionAspect() {
101106
}
102107
}
103108

109+
@Test
110+
public void spr11915() {
111+
AnnotationConfigApplicationContext ctx =
112+
new AnnotationConfigApplicationContext(Spr11915Config.class);
113+
114+
TransactionalTestBean bean = ctx.getBean(TransactionalTestBean.class);
115+
bean.saveQualifiedFoo();
116+
117+
CallCountingTransactionManager txManager = ctx
118+
.getBean("qualifiedTransactionManager", CallCountingTransactionManager.class);
119+
assertThat(txManager.begun, equalTo(1));
120+
assertThat(txManager.commits, equalTo(1));
121+
assertThat(txManager.rollbacks, equalTo(0));
122+
}
123+
104124

105125
@Configuration
106126
@EnableTransactionManagement
@@ -118,6 +138,25 @@ static class InheritedEnableTxConfig extends EnableTxConfig {
118138
static class EnableAspectJTxConfig {
119139
}
120140

141+
@Configuration
142+
@EnableTransactionManagement
143+
static class Spr11915Config {
144+
145+
@Autowired
146+
private ConfigurableApplicationContext applicationContext;
147+
148+
@PostConstruct
149+
public void initializeApp() {
150+
applicationContext.getBeanFactory().registerSingleton(
151+
"qualifiedTransactionManager", new CallCountingTransactionManager());
152+
}
153+
154+
@Bean
155+
public TransactionalTestBean testBean() {
156+
return new TransactionalTestBean();
157+
}
158+
}
159+
121160

122161
@Configuration
123162
static class TxManagerConfig {

0 commit comments

Comments
 (0)