Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Extrapolation attribute values of custom annotation

I write a spring-boot test and created a custom annotation:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("integration-test")
public @interface IntegrationTest {

    String[] properties() default {};
}

As you can see, I’ve defined the properties attribute to have the possibility to override properties like that:

@IntegrationTest(properties = {"my.property=value"})
public class MyIntegrationTest {
    // test code here
}

I don’t have any additional configurations and value of my attribute is automatic put into @SpringBootTest(properties = ), that is what I actually wanted to achieve.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But now I’m wondering how it is understood that the value of this attribute should be put in @SpringBootTest(properties = )?

>Solution :

You should annotate the properties with @AliasFor as follows:

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@SpringBootTest
@AutoConfigureMockMvc
@ActiveProfiles("integration-test")
public @interface IntegrationTest {

    @AliasFor(annotation = SpringBootTest.class, attribute = "properties")
    String[] properties() default {};
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading