Description
Réda Housni Alaoui opened SPR-15274 and commented
Hello,
We have a project split up into multiple modules. Among them there are:
database
modulestream
module
Each of them defines a test project (database-test, stream-test)
And there is a consumer of these modules:
cqrs
module
cqrs
has a mandatory dependency on the database
module and optional dependency on the stream
module.
Therefore the AbstractCqrsIntegrationTest
extends AbstractDataIntegrationTest
and cannot extend an abstract stream
test class.
What I wanted to do was to create this meta annotation in the stream
module:
@Target({ ElementType.TYPE, ElementType.ANNOTATION_TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@ContextConfiguration(
classes = {StreamConfigurationTest.class},
initializers = StreamEnvironmentInitializerTest.class
)
public @interface EnableStreamTest {
}
And use it in cqrs
:
@EnableStreamTest
@ContextConfiguration(
classes = {CqrsConfigurationTest.class},
loader = AnnotationConfigContextLoader.class,
initializers = CqrsEnvironmentInitializer.class
)
public abstract class AbstractCqrsIntegrationTest extends AbstractDataIntegrationTest {
}
But @ContextConfiguration
coming from meta annotation is ignored and replaced by the one declared directly on AbstractCqrsIntegrationTest
.
I know that @ContextConfiguration
are correctly merged by traversing only superclasses. But this doesn't apply to my need.
Would it be possible to fetch all declared @ContextConfiguration
at the class level?
It seems it would require to add a method in MetaAnnotationUtils
similar to:
private static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(Class<?> clazz,
Set<Annotation> visited, Class<? extends Annotation>... annotationTypes)}}
that would return a list of descriptors and to use that list inside AbstractTestContextBootstrapper.buildMergedContextConfiguration
.
Issue Links:
- @ContextConfiguration defined on a base class and a composed annotation do not merge [SPR-13670] #18245
@ContextConfiguration
defined on a base class and a composed annotation do not merge