You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AbstractTransactionalJUnit4SpringContextTests and AbstractTransactionalTestNGSpringContextTests provide the ability to manually execute a specific SQL script for the current test via their protected executeSqlScript() methods. For more control over the configuration of such scripts, one can optionally use either ResourceDatabasePopulator or ScriptUtils directly.
The above provide several options for programmatically executing scripts; however, it would be nice if the Spring TestContext Framework provided declarative support via an annotation and an associated TestExecutionListener.
Deliverables
The semantics for locating SQL script resources should be consistent with @ContextConfiguration's semantics for locating XML configuration files.
There needs to be a mechanism for specifying which DataSource and PlatformTransactionManager to use from the test's ApplicationContext, including default conventions consistent with TransactionalTestExecutionListener and @TransactionConfiguration
The annotation can be applied at either the class or method level with method-level overrides.
The annotation can be used as a meta-annotation.
The annotation must support all of the configuration options currently supported by ResourceDatabasePopulator - for example, encoding, statement separator, comment prefix, block comment delimiters, error handling flags, etc.
The annotation and listener must support execution phases for scripts, for example "before test" and "after test".
The listener should execute the named scripts within the current test's transaction if present, outside of the current test's transaction if present, or always in a new transaction, depending on the value of a boolean flag in the annotation.
The listener should delegate to ResourceDatabasePopulator#execute to actually execute the scripts.
The listener should be registered by default in abstract base classes as well as in TestContextBootstrapper implementations.
Proposed Annotation Names
@SqlGroup as a container with nested, repeatable@Sql entries
@ExecuteSql as a container with nested, repeatable@SqlScripts entries
@DatabaseInitializers as a container with nested, repeatable@DatabaseInitializer entries
omar elmandour opened SPR-7655 and commented
Overview
AbstractTransactionalJUnit4SpringContextTestsandAbstractTransactionalTestNGSpringContextTestsprovide the ability to manually execute a specific SQL script for the current test via their protectedexecuteSqlScript()methods. For more control over the configuration of such scripts, one can optionally use eitherResourceDatabasePopulatororScriptUtilsdirectly.The above provide several options for programmatically executing scripts; however, it would be nice if the Spring TestContext Framework provided declarative support via an annotation and an associated
TestExecutionListener.Deliverables
@ContextConfiguration's semantics for locating XML configuration files.DataSourceandPlatformTransactionManagerto use from the test'sApplicationContext, including default conventions consistent withTransactionalTestExecutionListenerand@TransactionConfigurationResourceDatabasePopulator- for example, encoding, statement separator, comment prefix, block comment delimiters, error handling flags, etc.ResourceDatabasePopulator#executeto actually execute the scripts.TestContextBootstrapperimplementations.Proposed Annotation Names
@SqlGroupas a container with nested, repeatable@Sqlentries@ExecuteSqlas a container with nested, repeatable@SqlScriptsentries@DatabaseInitializersas a container with nested, repeatable@DatabaseInitializerentriesCode Examples
Defaults
Single Script
Multiple Scripts
Multiple Annotations with Container
Multiple Annotations without Container (Java 8)
Affects: 3.0 GA
Issue Links:
@SqlConfigfor common SQL script configuration ("is depended on by")@Sqlscript support in the reference manual ("is depended on by")@Sql("is depended on by")Referenced from: commits 0c1249f, abdb010, 5fd6ebb, ae29f48
3 votes, 5 watchers