Réda Housni Alaoui opened SPR-15274 and commented
Hello,
We have a project split up into multiple modules. Among them there are:
- database
module
- stream
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:
- #18245 @ContextConfiguration
defined on a base class and a composed annotation do not merge
Comment From: snicoll
@sbrannen I can see you've assigned yourself and I am wondering if that wouldn't be a duplicate of #26142 that has been declined.
Comment From: sbrannen
- Duplicate of #26142