Skip to content

Ability to use @ContextConfiguration directly and as meta-annotation on the same class [SPR-15274] #19839

Closed as not planned
@spring-projects-issues

Description

@spring-projects-issues

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:

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions