forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support TransactionManagementConfigurer in the TCF
Currently the Spring TestContext Framework looks up a PlatformTransactionManager bean named "transactionManager". The exact name of the bean can be overridden via @TransactionConfiguration or @transactional; however, the bean will always be looked up 'by name'. The TransactionManagementConfigurer interface that was introduced in Spring 3.1 provides a programmatic approach to specifying the PlatformTransactionManager bean to be used for annotation-driven transaction management, and that bean is not required to be named "transactionManager". However, as of Spring 3.1.2, using the TransactionManagementConfigurer on a @configuration class has no effect on how the TestContext framework looks up the transaction manager. Consequently, if an explicit name or qualifier has not been specified, the bean must be named "transactionManager" in order for a transactional integration test to work. This commit addresses this issue by refactoring the TransactionalTestExecutionListener so that it looks up and delegates to a single TransactionManagementConfigurer as part of the algorithm for determining the transaction manager. Issue: SPR-9604
- Loading branch information
Showing
11 changed files
with
155 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...ework/test/context/junit4/spr9604/LookUpTxMgrViaTransactionManagementConfigurerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright 2002-2012 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.test.context.junit4.spr9604; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.transaction.AfterTransaction; | ||
import org.springframework.test.context.transaction.BeforeTransaction; | ||
import org.springframework.test.transaction.CallCountingTransactionManager; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.TransactionManagementConfigurer; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* Integration tests that verify the behavior requested in | ||
* <a href="https://jira.springsource.org/browse/SPR-9604">SPR-9604</a>. | ||
* | ||
* @author Sam Brannen | ||
* @since 3.2 | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration | ||
@Transactional | ||
public class LookUpTxMgrViaTransactionManagementConfigurerTests { | ||
|
||
private static final CallCountingTransactionManager txManager1 = new CallCountingTransactionManager(); | ||
private static final CallCountingTransactionManager txManager2 = new CallCountingTransactionManager(); | ||
|
||
|
||
@Configuration | ||
static class Config implements TransactionManagementConfigurer { | ||
|
||
public PlatformTransactionManager annotationDrivenTransactionManager() { | ||
return txManager1(); | ||
} | ||
|
||
@Bean | ||
public PlatformTransactionManager txManager1() { | ||
return txManager1; | ||
} | ||
|
||
@Bean | ||
public PlatformTransactionManager txManager2() { | ||
return txManager2; | ||
} | ||
} | ||
|
||
|
||
@BeforeTransaction | ||
public void beforeTransaction() { | ||
txManager1.clear(); | ||
txManager2.clear(); | ||
} | ||
|
||
@Test | ||
public void transactionalTest() { | ||
assertEquals(1, txManager1.begun); | ||
assertEquals(1, txManager1.inflight); | ||
assertEquals(0, txManager1.commits); | ||
assertEquals(0, txManager1.rollbacks); | ||
|
||
assertEquals(0, txManager2.begun); | ||
assertEquals(0, txManager2.inflight); | ||
assertEquals(0, txManager2.commits); | ||
assertEquals(0, txManager2.rollbacks); | ||
} | ||
|
||
@AfterTransaction | ||
public void afterTransaction() { | ||
assertEquals(1, txManager1.begun); | ||
assertEquals(0, txManager1.inflight); | ||
assertEquals(0, txManager1.commits); | ||
assertEquals(1, txManager1.rollbacks); | ||
|
||
assertEquals(0, txManager2.begun); | ||
assertEquals(0, txManager2.inflight); | ||
assertEquals(0, txManager2.commits); | ||
assertEquals(0, txManager2.rollbacks); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters