public abstract class TestContextTransactionUtils extends Object
Mainly for internal use within the framework.
| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_DATA_SOURCE_NAME
Default bean name for a
DataSource: "dataSource". |
static String |
DEFAULT_TRANSACTION_MANAGER_NAME
Default bean name for a
PlatformTransactionManager:
"transactionManager". |
| Constructor and Description |
|---|
TestContextTransactionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static org.springframework.transaction.interceptor.TransactionAttribute |
createDelegatingTransactionAttribute(TestContext testContext,
org.springframework.transaction.interceptor.TransactionAttribute targetAttribute)
Create a delegating
TransactionAttribute for the supplied target
TransactionAttribute and TestContext, using the names of
the test class and test method to build the name of the transaction. |
static DataSource |
retrieveDataSource(TestContext testContext,
String name)
Retrieve the
DataSource to use for the supplied test context. |
static org.springframework.transaction.PlatformTransactionManager |
retrieveTransactionManager(TestContext testContext,
String name)
Retrieve the transaction manager
to use for the supplied test context.
|
public static final String DEFAULT_DATA_SOURCE_NAME
DataSource: "dataSource".public static final String DEFAULT_TRANSACTION_MANAGER_NAME
PlatformTransactionManager:
"transactionManager".@Nullable public static DataSource retrieveDataSource(TestContext testContext, @Nullable String name)
DataSource to use for the supplied test context.
The following algorithm is used to retrieve the DataSource from
the ApplicationContext
of the supplied test context:
DataSource by type and name, if the supplied
name is non-empty, throwing a BeansException if the named
DataSource does not exist.
DataSource by type.
DataSource by type.
DataSource by type and the
default data source name.
testContext - the test context for which the DataSource
should be retrieved; never nullname - the name of the DataSource to retrieve
(may be null or empty)DataSource to use, or null if not foundorg.springframework.beans.BeansException - if an error occurs while retrieving an explicitly
named DataSource@Nullable public static org.springframework.transaction.PlatformTransactionManager retrieveTransactionManager(TestContext testContext, @Nullable String name)
The following algorithm is used to retrieve the transaction manager
from the ApplicationContext
of the supplied test context:
name is non-empty, throwing a BeansException if the named
transaction manager does not exist.
TransactionManagementConfigurer, if present.
testContext - the test context for which the transaction manager
should be retrieved; never nullname - the name of the transaction manager to retrieve
(may be null or empty)null if not foundorg.springframework.beans.BeansException - if an error occurs while retrieving an explicitly
named transaction managerIllegalStateException - if more than one TransactionManagementConfigurer
exists in the ApplicationContextpublic static org.springframework.transaction.interceptor.TransactionAttribute createDelegatingTransactionAttribute(TestContext testContext, org.springframework.transaction.interceptor.TransactionAttribute targetAttribute)
TransactionAttribute for the supplied target
TransactionAttribute and TestContext, using the names of
the test class and test method to build the name of the transaction.testContext - the TestContext upon which to base the nametargetAttribute - the TransactionAttribute to delegate toTransactionAttribute