Class SqlScriptsTestExecutionListener
- All Implemented Interfaces:
Ordered,TestExecutionListener
TestExecutionListener that provides support for executing SQL
scripts and inlined statements
configured via the @Sql annotation.
Scripts and inlined statements will be executed before
or after execution of the corresponding
test method, depending on the configured
value of the executionPhase flag.
Scripts and inlined statements 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.
Script Resources
For details on default script detection and how script resource locations
are interpreted, see Sql.scripts().
Required Spring Beans
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.
- Since:
- 4.1
- Author:
- Sam Brannen, Dmitry Semukhin
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterTestMethod(TestContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedTestContextafter the current test method.voidbeforeTestMethod(TestContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedTestContextbefore the current test method.final intgetOrder()Returns5000.Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, afterTestExecution, beforeTestClass, beforeTestExecution, prepareTestInstance
-
Constructor Details
-
SqlScriptsTestExecutionListener
public SqlScriptsTestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns5000.- Specified by:
getOrderin interfaceOrdered- Overrides:
getOrderin classAbstractTestExecutionListener- Returns:
- the order value
- See Also:
-
beforeTestMethod
Execute SQL scripts configured via@Sqlfor the suppliedTestContextbefore the current test method.- Specified by:
beforeTestMethodin interfaceTestExecutionListener- Overrides:
beforeTestMethodin classAbstractTestExecutionListener- Parameters:
testContext- the test context in which the test method will be executed; nevernull- See Also:
-
afterTestMethod
Execute SQL scripts configured via@Sqlfor the suppliedTestContextafter the current test method.- Specified by:
afterTestMethodin interfaceTestExecutionListener- Overrides:
afterTestMethodin classAbstractTestExecutionListener- Parameters:
testContext- the test context in which the test method was executed; nevernull- See Also:
-