maciejwalkowiak / wiremock-spring-boot

WireMock Spring Boot drastically simplifies testing HTTP clients in Spring Boot & Junit 5 based integration tests.
MIT License
218 stars 13 forks source link

add support for multiple property injection #28

Open rfelgent opened 6 months ago

rfelgent commented 6 months ago

Hi @maciejwalkowiak

I would like to suggest one enhancement: introduction of multiple property mapping (instead of a single one):

This leads to a simplified setup, for example:

current, complex approach:

@EnableWireMock({
    @ConfigureWireMock(name = "product-aggregates-service", property = "app.client-apis.product-aggregates.base-path", configurationCustomizers = {WireMockCustomizer.class}),
    @ConfigureWireMock(name = "participations-service", property = "app.client-apis.participations.base-path", configurationCustomizers = {WireMockCustomizer.class}),
    @ConfigureWireMock(name = "businesspartners-service", property = "app.client-apis.businesspartners.base-path", configurationCustomizers = {WireMockCustomizer.class}),
    @ConfigureWireMock(name = "usageinformations-service", property = "app.client-apis.usage-informations.base-path", configurationCustomizers = {WireMockCustomizer.class})
})

new, simplified aproach:

@EnableWireMock({
    @ConfigureWireMock(name = "services",
         property = {
            "app.client-apis.product-aggregates.base-path"
            "app.client-apis.participations.base-path",      
            "app.client-apis.businesspartners.base-path",
            "app.client-apis.usage-informations.base-path"
         },
        configurationCustomizers = {WireMockCustomizer.class})
})

If you are convinced by that feature, I can try to make a PR

maciejwalkowiak commented 6 months ago

The name maps to configured WireMockServer instance, with an idea that each instance's base url is bound to a single property. Do you mean in your example that all of these base paths would have the same url?

rfelgent commented 6 months ago

Hi @maciejwalkowiak ,

sorry for the late response!

For the sake of simplified test setup, I want one WireMock instances for all 3rd party RESTful services that my app depends on.

So that I can inject one instance

@InjectWireMock("services")
private WireMockServer servicesWireMock;

instead of

@InjectWireMock("product-aggregates-service")
private WireMockServer productAggregatesWireMock;
@InjectWireMock("businesspartners-service")
private WireMockServer businessPartnersWireMock;
@InjectWireMock("participations-service")
private WireMockServer participationsWireMock;
@InjectWireMock("usageinformations-service")
private WireMockServer usageinformationsWireMock;

I am aware, that WireMock documentation recommends to have a dedicated WireMock instance for every RESTful service, but I do not need this high level of isolation. For my requirements, it is sufficient to isolate the different RESTFul services by path only.

Being that said and in relation to your question

Do you mean in your example that all of these base paths would have the same url?

I configure one base url (not really base path) pointing to one and the same host and the application code has some code snippet for the different paths.

I think this feature request makes it more easy to support "default instance" requirement: #19

rfelgent commented 6 months ago

ping @maciejwalkowiak

maciejwalkowiak commented 6 months ago

@rfelgent go for it!

rfelgent commented 6 months ago

Hi @maciejwalkowiak

when will you find the time to Look at the pull request?

Greetingz

maciejwalkowiak commented 6 months ago

Soonish, hopefully beginning of the next week

rfelgent commented 5 months ago

ping @maciejwalkowiak :)

rfelgent commented 5 months ago

ping @maciejwalkowiak

maciejwalkowiak commented 5 months ago

@rfelgent Check PR. I've remembered about this PR, it just had to wait for its time. Pinging does not help 😉

rfelgent commented 3 months ago

Hi @maciejwalkowiak,

What is the current status?