Class SqlScriptstestExecutionListener
- All Implemented Interfaces:
Ordered, AottestExecutionListener, testExecutionListener
testExecutionListener that provides support for executing SQL
scripts and inlined statements
configured via the @Sql annotation.
Class-level annotations that are constrained to a class-level execution
phase (BEFORE_test_CLASS or
AFTER_test_CLASS) will be run
once before all test methods or
once after all test methods,
respectively. All other 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(testContext, String), and
testContextTransactionUtils.retrieveTransactionManager(testContext, String) for details
on permissible configuration constellations and on the algorithms used to
locate these beans.
Required Dependencies
Use of this listener requires the spring-jdbc and spring-tx
modules as well as their transitive dependencies to be present on the classpath.
- Since:
- 4.1
- Author:
- Sam Brannen, Dmitry Semukhin, Andreas Ahlenstorf
- See Also:
-
Field Summary
FieldsFields inherited from interface Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaftertestClass(testContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedtestContextonce per test class after all test methods have been run.voidaftertestMethod(testContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedtestContextafter the current test method.voidbeforetestClass(testContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedtestContextonce per test class before any test method is run.voidbeforetestMethod(testContext testContext) Execute SQL scripts configured via@Sqlfor the suppliedtestContextbefore the current test method.final intgetOrder()Returns 5000, which ensures that theSqlScriptstestExecutionListeneris ordered after theTransactionaltestExecutionListenerand before theEventPublishingtestExecutionListener.voidprocessAheadOfTime(RuntimeHints runtimeHints, Class<?> testClass, ClassLoader classLoader) Process the supplied test class and its methods and register run-time hints for any SQL scripts configured or detected as classpath resources via@Sql.Methods inherited from class AbstracttestExecutionListener
aftertestExecution, beforetestExecution, preparetestInstanceMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface testExecutionListener
aftertestExecution, beforetestExecution, preparetestInstance
-
Field Details
-
ORDER
-
-
Constructor Details
-
SqlScriptstestExecutionListener
public SqlScriptstestExecutionListener()
-
-
Method Details
-
getOrder
public final int getOrder()Returns 5000, which ensures that theSqlScriptstestExecutionListeneris ordered after theTransactionaltestExecutionListenerand before theEventPublishingtestExecutionListener.- Specified by:
getOrderin interfaceOrdered- Overrides:
getOrderin classAbstracttestExecutionListener- Returns:
- the order value
- See Also:
-
beforetestClass
Execute SQL scripts configured via@Sqlfor the suppliedtestContextonce per test class before any test method is run.- Specified by:
beforetestClassin interfacetestExecutionListener- Overrides:
beforetestClassin classAbstracttestExecutionListener- Parameters:
testContext- the test context for the test; nevernull- Throws:
Exception- allows any exception to propagate- Since:
- 6.1
-
aftertestClass
Execute SQL scripts configured via@Sqlfor the suppliedtestContextonce per test class after all test methods have been run.- Specified by:
aftertestClassin interfacetestExecutionListener- Overrides:
aftertestClassin classAbstracttestExecutionListener- Parameters:
testContext- the test context for the test; nevernull- Throws:
Exception- allows any exception to propagate- Since:
- 6.1
-
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:
-
processAheadOfTime
public void processAheadOfTime(RuntimeHints runtimeHints, Class<?> testClass, ClassLoader classLoader) Process the supplied test class and its methods and register run-time hints for any SQL scripts configured or detected as classpath resources via@Sql.- Specified by:
processAheadOfTimein interfaceAottestExecutionListener- Parameters:
runtimeHints- theRuntimeHintsto usetestClass- the test class to processclassLoader- the classloader to use- Since:
- 6.0
-