spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

Add the possibility to specify custom test annotations via the spring-cloud-contract-maven-plugin

Open virgiliu-ratoi-ec-ext opened this issue 4 years ago • 4 comments

Is your feature request related to a problem? Please describe. The spring-cloud-contract-maven-plugin has the option of specifying imports and static imports for the generated tests. Sometimes you might need to add some custom annotations to the tests, for instance when using OpenEJB to start a TomEE server with JAX-RS services you have to add the @EnableServices(value = "jaxrs") and @RunWith(ApplicationComposer.class) annotations to each test because they are not inherited from the base test class.

Describe the solution you'd like The plugin should accept a configuration XML element similar to the existing imports and static imports.

Describe alternatives you've considered The alternative is to create a separate library which defines a custom JavaTestGenerator and reference it as a dependency but it would be much easier just to define annotation(s) at the configuration level.

Additional context Add any other context or screenshots about the feature request here.

virgiliu-ratoi-ec-ext avatar May 07 '20 16:05 virgiliu-ratoi-ec-ext

Hi @virgiliu-ratoi-ec-ext , won't you be able in do this setup in the test base class?

OlgaMaciaszek avatar May 08 '20 15:05 OlgaMaciaszek

Hi @virgiliu-ratoi-ec-ext , won't you be able in do this setup in the test base class?

Unfortunately, the required annotations from the test base class are not inherited so they need to be specified in the child class.

virgiliu-ratoi-ec-ext avatar May 11 '20 09:05 virgiliu-ratoi-ec-ext

That's a good idea. So the plugin setup would require a list of FQN imports for the annotation e.g. <imports>a.b.c.EnableServices</imports> and sth like classAnnotations, methodAnnotations ? e.g. <classAnnotations>@EnableServices(value = "jaxrs")</classAnnotations> ?

As a workaround you can check out this issue and do sth similar as described here in this issue https://github.com/spring-cloud/spring-cloud-contract/issues/1074 with the replacer plugin

marcingrzejszczak avatar May 20 '20 08:05 marcingrzejszczak

That's a good idea. So the plugin setup would require a list of FQN imports for the annotation e.g. <imports>a.b.c.EnableServices</imports> and sth like classAnnotations, methodAnnotations ? e.g. <classAnnotations>@EnableServices(value = "jaxrs")</classAnnotations> ?

As a workaround you can check out this issue and do sth similar as described here in this issue #1074 with the replacer plugin

Indeed, something like that could make things easier. Of course, there is the option you mentioned with the maven-replacer-plugin which I was not aware of.

virgiliu-ratoi-ec-ext avatar May 20 '20 13:05 virgiliu-ratoi-ec-ext