public abstract class TestContextTransactionUtils
extends java.lang.Object
Mainly for internal use within the framework.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_DATA_SOURCE_NAME
Default bean name for a
DataSource : "dataSource" . |
static java.lang.String |
DEFAULT_TRANSACTION_MANAGER_NAME
Default bean name for a
PlatformTransactionManager :
"transactionManager" . |
Modifier and Type | Method and Description |
---|---|
static TransactionAttribute |
createDelegatingTransactionAttribute(TestContext testContext,
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 javax.sql.DataSource |
retrieveDataSource(TestContext testContext,
java.lang.String name)
Retrieve the
DataSource to use for the supplied test context. |
static PlatformTransactionManager |
retrieveTransactionManager(TestContext testContext,
java.lang.String name)
Retrieve the transaction manager
to use for the supplied test context.
|
public static final java.lang.String DEFAULT_DATA_SOURCE_NAME
DataSource
: "dataSource"
.public static final java.lang.String DEFAULT_TRANSACTION_MANAGER_NAME
PlatformTransactionManager
:
"transactionManager"
.public static javax.sql.DataSource retrieveDataSource(TestContext testContext, java.lang.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 null
name
- the name of the DataSource
to retrieve; may be null
or emptyDataSource
to use, or null
if not foundBeansException
- if an error occurs while retrieving an explicitly
named DataSource
public static PlatformTransactionManager retrieveTransactionManager(TestContext testContext, java.lang.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 null
name
- the name of the transaction manager to retrieve; may be
null
or emptynull
if not foundBeansException
- if an error occurs while retrieving an explicitly
named transaction managerjava.lang.IllegalStateException
- if more than one TransactionManagementConfigurer
exists in the ApplicationContextpublic static TransactionAttribute createDelegatingTransactionAttribute(TestContext testContext, 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 name; never null
targetAttribute
- the TransactionAttribute
to delegate to; never null
TransactionAttribute