Class SqlScriptsTestExecutionListener
- java.lang.Object
- org.springframework.test.context.support.AbstractTestExecutionListener
- org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener
- All Implemented Interfaces:
Ordered
,TestExecutionListener
public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListener
TestExecutionListener
that provides support for executing SQLscripts
and inlinedstatements
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 aDataSource
, just aPlatformTransactionManager
, or just aDataSource
must be defined as beans in the SpringApplicationContext
for the corresponding test. Consult the javadocs forSqlConfig.transactionMode()
,SqlConfig.transactionManager()
,SqlConfig.dataSource()
,TestContextTransactionUtils.retrieveDataSource(org.springframework.test.context.TestContext, java.lang.String)
, andTestContextTransactionUtils.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
- See Also:
Sql
,SqlConfig
,SqlGroup
,TestContextTransactionUtils
,TransactionalTestExecutionListener
,ResourceDatabasePopulator
,ScriptUtils
Field Summary
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
Constructor Summary
Constructors Constructor Description SqlScriptsTestExecutionListener()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterTestMethod(TestContext testContext)
Execute SQL scripts configured via@Sql
for the suppliedTestContext
after the current test method.void
beforeTestMethod(TestContext testContext)
Execute SQL scripts configured via@Sql
for the suppliedTestContext
before the current test method.int
getOrder()
Returns5000
.Methods inherited from class org.springframework.test.context.support.AbstractTestExecutionListener
afterTestClass, beforeTestClass, prepareTestInstance
Constructor Detail
SqlScriptsTestExecutionListener
public SqlScriptsTestExecutionListener()
Method Detail
getOrder
public final int getOrder()
Returns5000
.- Specified by:
getOrder
in interfaceOrdered
- Overrides:
getOrder
in classAbstractTestExecutionListener
- Returns:
- the order value
- See Also:
Ordered.HIGHEST_PRECEDENCE
,Ordered.LOWEST_PRECEDENCE
beforeTestMethod
public void beforeTestMethod(TestContext testContext) throws Exception
Execute SQL scripts configured via@Sql
for the suppliedTestContext
before the current test method.- Specified by:
beforeTestMethod
in interfaceTestExecutionListener
- Overrides:
beforeTestMethod
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context in which the test method will be executed; nevernull
- Throws:
Exception
- allows any exception to propagate
afterTestMethod
public void afterTestMethod(TestContext testContext) throws Exception
Execute SQL scripts configured via@Sql
for the suppliedTestContext
after the current test method.- Specified by:
afterTestMethod
in interfaceTestExecutionListener
- Overrides:
afterTestMethod
in classAbstractTestExecutionListener
- Parameters:
testContext
- the test context in which the test method was executed; nevernull
- Throws:
Exception
- allows any exception to propagate