Skip to content

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

Closed as not planned

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:

Activity

  1. added
    status: waiting-for-triage
    in: test
    type: enhancement
    and removed
    type: enhancement
    on Jan 11, 2019
  2. self-assigned this
    on Jan 15, 2019
  3. snicoll commented on Sep 20, 2023

    @snicoll
    Member

    @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.

  4. changed the title [-]Ability to use @ContextConfiguration and a meta @ContextConfiguration on the same class [SPR-15274][/-] [+]Ability to use `@ContextConfiguration` directly and as meta-annotation on the same class [SPR-15274][/+] on Jan 8, 2024
  5. sbrannen commented on Jan 8, 2024

    @sbrannen
    Member
  6. added
    status: duplicate
    type: enhancement
    and removed
    status: waiting-for-triage
    on Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: teststatus: duplicatetype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions