public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListener
TestExecutionListener that provides support for executing SQL scripts
configured via the @Sql annotation.
Scripts will be executed before
or after execution of the corresponding
test method, depending on the configured
value of the executionPhase flag.
Scripts will be executed without a transaction, within an existing
Spring-managed transaction, or within an isolated transaction, depending
on the configured value of SqlConfig.transactionMode() and the
presence of a transaction manager.
For details on default script detection and how explicit script locations
are interpreted, see Sql.scripts().
A PlatformTransactionManager and a DataSource,
just a PlatformTransactionManager, or just a DataSource
must be defined as beans in the Spring ApplicationContext for the
corresponding test. Consult the javadocs for SqlConfig.transactionMode(),
SqlConfig.transactionManager(), SqlConfig.dataSource(),
TestContextTransactionUtils.retrieveDataSource(org.springframework.test.context.TestContext, java.lang.String), and
TestContextTransactionUtils.retrieveTransactionManager(org.springframework.test.context.TestContext, java.lang.String) for details
on permissible configuration constellations and on the algorithms used to
locate these beans.
Sql,
SqlConfig,
SqlGroup,
TestContextTransactionUtils,
TransactionalTestExecutionListener,
ResourceDatabasePopulator,
ScriptUtils| Constructor and Description |
|---|
SqlScriptsTestExecutionListener() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterTestMethod(TestContext testContext)
Execute SQL scripts configured via
@Sql for the supplied
TestContext after the current test method. |
void |
beforeTestMethod(TestContext testContext)
Execute SQL scripts configured via
@Sql for the supplied
TestContext before the current test method. |
int |
getOrder()
Returns
5000. |
afterTestClass, beforeTestClass, prepareTestInstancepublic final int getOrder()
5000.getOrder in interface org.springframework.core.OrderedgetOrder in class AbstractTestExecutionListenerpublic void beforeTestMethod(TestContext testContext) throws Exception
@Sql for the supplied
TestContext before the current test method.beforeTestMethod in interface TestExecutionListenerbeforeTestMethod in class AbstractTestExecutionListenertestContext - the test context in which the test method will be
executed; never nullException - allows any exception to propagatepublic void afterTestMethod(TestContext testContext) throws Exception
@Sql for the supplied
TestContext after the current test method.afterTestMethod in interface TestExecutionListenerafterTestMethod in class AbstractTestExecutionListenertestContext - the test context in which the test method was
executed; never nullException - allows any exception to propagate