@groovy.util.logging.Slf4j @groovy.transform.CompileStatic class DatabaseCleanupInterceptor extends AbstractMethodInterceptor
Spock method interceptor that performs database cleanup after tests annotated with DatabaseCleanup. Supports both class-level and method-level annotations.
During setup, this interceptor eagerly resolves the ApplicationContext from the TestContextHolderListener ThreadLocal and stores it on the DatabaseCleanupContext. After cleanup completes, the ThreadLocal is cleared.
When datasource entries are specified in the annotation (with optional database type mappings), only those data sources are cleaned using the specified or auto-discovered cleaners. Otherwise, all datas ources are cleaned.
| Constructor and description |
|---|
DatabaseCleanupInterceptor(DatabaseCleanupContext context, boolean classLevelCleanup, boolean cleanupAfterSpec, DatasourceCleanupMapping mapping, ApplicationContextResolver resolver)
|
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
interceptCleanupMethod(IMethodInvocation invocation) |
|
void |
interceptCleanupSpecMethod(IMethodInvocation invocation) |
|
void |
interceptSetupMethod(IMethodInvocation invocation) |
context - the cleanup context containing the cleaners and configurationclassLevelCleanup - if true, cleanup runs after every test method;
if false, only after methods annotated withmapping - the parsed datasource-to-type mapping from the class-level annotation;
for method-level cleanup, the method's own annotation values are parsed at runtimeresolver - the strategy for resolving the ApplicationContext from test instances