类 SqlScriptsTestExecutionListener
- 所有已实现的接口:
cn.taketoday.core.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 Infra-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 Infra Beans
A PlatformTransactionManager and a DataSource,
just a PlatformTransactionManager, or just a DataSource
must be defined as beans in the Infra ApplicationContext for the
corresponding test. Consult the javadocs for SqlConfig.transactionMode(),
SqlConfig.transactionManager(), SqlConfig.dataSource(),
TestContextTransactionUtils.retrieveDataSource(cn.taketoday.test.context.TestContext, java.lang.String), and
TestContextTransactionUtils.retrieveTransactionManager(cn.taketoday.test.context.TestContext, java.lang.String) for details
on permissible configuration constellations and on the algorithms used to
locate these beans.
Required Dependencies
Use of this listener requires the today-jdbc and today-tx
modules as well as their transitive dependencies to be present on the classpath.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Dmitry Semukhin, Andreas Ahlenstorf, Harry Yang
- 另请参阅:
-
SqlSqlConfigSqlMergeModeSqlGroupTestContextTransactionUtilsTransactionalTestExecutionListenerResourceDatabasePopulatorScriptUtilsSqlSqlConfigSqlGroupTestContextTransactionUtilsTransactionalTestExecutionListenerResourceDatabasePopulatorScriptUtils
-
字段概要
字段修饰符和类型字段说明private static final cn.taketoday.logging.Loggerprivate static final Stringprivate static final cn.taketoday.util.ReflectionUtils.MethodFilter从接口继承的字段 cn.taketoday.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明voidafterTestClass(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.private cn.taketoday.jdbc.datasource.init.ResourceDatabasePopulatorcreateDatabasePopulator(MergedSqlConfig mergedSqlConfig) private StringdetectDefaultScript(Class<?> testClass, Method testMethod, boolean classLevel) Detect a default SQL script by implementing the algorithm defined inSql.scripts().private voidexecuteClassLevelSqlScripts(TestContext testContext, Sql.ExecutionPhase executionPhase) Execute class-level SQL scripts configured via@Sqlfor the suppliedTestContextand the suppliedBEFORE_TEST_CLASSorAFTER_TEST_CLASSexecution phase.private voidexecuteSqlScripts(Sql sql, Sql.ExecutionPhase executionPhase, TestContext testContext, boolean classLevel) Execute the SQL scripts configured via the supplied@Sqlannotation for the givenSql.ExecutionPhaseandTestContext.private voidexecuteSqlScripts(TestContext testContext, Sql.ExecutionPhase executionPhase) private voidexecuteSqlScripts(Set<Sql> sqlAnnotations, TestContext testContext, Sql.ExecutionPhase executionPhase, boolean classLevel) Execute SQL scripts for the supplied@Sqlannotations.private DataSourcegetDataSourceFromTransactionManager(cn.taketoday.transaction.PlatformTransactionManager transactionManager) final intgetOrder()Returns5000.private String[]getScripts(Sql sql, Class<?> testClass, Method testMethod, boolean classLevel) getSqlAnnotationsFor(Class<?> clazz) Get the@Sqlannotations declared on the supplied class.getSqlAnnotationsFor(Method method) Get the@Sqlannotations declared on the supplied method.private SqlMergeModegetSqlMergeModeFor(Class<?> clazz) Get the@SqlMergeModeannotation declared on the supplied class.private SqlMergeModegetSqlMergeModeFor(Method method) Get the@SqlMergeModeannotation declared on the supplied method.getSqlMethods(Class<?> testClass) private static booleanisValidMethodLevelPhase(Sql.ExecutionPhase executionPhase) private booleanmergeSqlAnnotations(TestContext testContext) Determine if method-level@Sqlannotations should be merged with class-level@Sqlannotations.voidprocessAheadOfTime(cn.taketoday.aot.hint.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.private voidregisterClasspathResources(String[] paths, cn.taketoday.aot.hint.RuntimeHints runtimeHints, ClassLoader classLoader) private static booleansameDataSource(DataSource ds1, DataSource ds2) Determine if the two data sources are effectively the same, unwrapping proxies as necessary to compare the target instances.从类继承的方法 cn.taketoday.test.context.support.AbstractTestExecutionListener
afterTestExecution, beforeTestExecution, prepareTestInstance从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.test.context.TestExecutionListener
afterTestExecution, beforeTestExecution, prepareTestInstance
-
字段详细资料
-
SLASH
- 另请参阅:
-
logger
private static final cn.taketoday.logging.Logger logger -
sqlMethodFilter
private static final cn.taketoday.util.ReflectionUtils.MethodFilter sqlMethodFilter
-
-
构造器详细资料
-
SqlScriptsTestExecutionListener
public SqlScriptsTestExecutionListener()
-
-
方法详细资料
-
getOrder
public final int getOrder()Returns5000.- 指定者:
getOrder在接口中cn.taketoday.core.Ordered- 覆盖:
getOrder在类中AbstractTestExecutionListener
-
beforeTestClass
Execute SQL scripts configured via@Sqlfor the suppliedTestContextonce per test class before any test method is run.- 指定者:
beforeTestClass在接口中TestExecutionListener- 覆盖:
beforeTestClass在类中AbstractTestExecutionListener- 参数:
testContext- the test context for the test; nevernull- 抛出:
Exception- allows any exception to propagate
-
afterTestClass
Execute SQL scripts configured via@Sqlfor the suppliedTestContextonce per test class after all test methods have been run.- 指定者:
afterTestClass在接口中TestExecutionListener- 覆盖:
afterTestClass在类中AbstractTestExecutionListener- 参数:
testContext- the test context for the test; nevernull- 抛出:
Exception- allows any exception to propagate
-
beforeTestMethod
Execute SQL scripts configured via@Sqlfor the suppliedTestContextbefore the current test method.- 指定者:
beforeTestMethod在接口中TestExecutionListener- 覆盖:
beforeTestMethod在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method will be executed; nevernull- 另请参阅:
-
afterTestMethod
Execute SQL scripts configured via@Sqlfor the suppliedTestContextafter the current test method.- 指定者:
afterTestMethod在接口中TestExecutionListener- 覆盖:
afterTestMethod在类中AbstractTestExecutionListener- 参数:
testContext- the test context in which the test method was executed; nevernull- 另请参阅:
-
processAheadOfTime
public void processAheadOfTime(cn.taketoday.aot.hint.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.- 指定者:
processAheadOfTime在接口中AotTestExecutionListener- 参数:
runtimeHints- theRuntimeHintsto usetestClass- the test class to processclassLoader- the classloader to use
-
executeClassLevelSqlScripts
private void executeClassLevelSqlScripts(TestContext testContext, Sql.ExecutionPhase executionPhase) Execute class-level SQL scripts configured via@Sqlfor the suppliedTestContextand the suppliedBEFORE_TEST_CLASSorAFTER_TEST_CLASSexecution phase. -
executeSqlScripts
-
mergeSqlAnnotations
Determine if method-level@Sqlannotations should be merged with class-level@Sqlannotations. -
getSqlMergeModeFor
Get the@SqlMergeModeannotation declared on the supplied class. -
getSqlMergeModeFor
Get the@SqlMergeModeannotation declared on the supplied method. -
getSqlAnnotationsFor
Get the@Sqlannotations declared on the supplied class. -
getSqlAnnotationsFor
Get the@Sqlannotations declared on the supplied method. -
executeSqlScripts
private void executeSqlScripts(Set<Sql> sqlAnnotations, TestContext testContext, Sql.ExecutionPhase executionPhase, boolean classLevel) Execute SQL scripts for the supplied@Sqlannotations. -
executeSqlScripts
private void executeSqlScripts(Sql sql, Sql.ExecutionPhase executionPhase, TestContext testContext, boolean classLevel) Execute the SQL scripts configured via the supplied@Sqlannotation for the givenSql.ExecutionPhaseandTestContext.Special care must be taken in order to properly support the configured
SqlConfig.transactionMode().- 参数:
sql- the@Sqlannotation to parseexecutionPhase- the current execution phasetestContext- the currentTestContextclassLevel-trueif@Sqlwas declared at the class level
-
createDatabasePopulator
@NonNull private cn.taketoday.jdbc.datasource.init.ResourceDatabasePopulator createDatabasePopulator(MergedSqlConfig mergedSqlConfig) -
sameDataSource
Determine if the two data sources are effectively the same, unwrapping proxies as necessary to compare the target instances.- 另请参阅:
-
TransactionSynchronizationUtils.unwrapResourceIfNecessary(Object)
-
getDataSourceFromTransactionManager
@Nullable private DataSource getDataSourceFromTransactionManager(cn.taketoday.transaction.PlatformTransactionManager transactionManager) -
getScripts
-
detectDefaultScript
private String detectDefaultScript(Class<?> testClass, @Nullable Method testMethod, boolean classLevel) Detect a default SQL script by implementing the algorithm defined inSql.scripts(). -
getSqlMethods
-
registerClasspathResources
private void registerClasspathResources(String[] paths, cn.taketoday.aot.hint.RuntimeHints runtimeHints, ClassLoader classLoader) -
isValidMethodLevelPhase
-