From 5633f0a5793bcf1c55db89eeb0cb39959b78b620 Mon Sep 17 00:00:00 2001 From: Maciej Walkowiak Date: Sun, 29 Oct 2023 09:07:12 +0100 Subject: [PATCH] Polish --- README.md | 27 +++++++++++++++++++ ... WireMockConfigurationCustomizerTest.java} | 11 +++----- 2 files changed, 31 insertions(+), 7 deletions(-) rename wiremock-spring-boot/src/test/java/com/maciejwalkowiak/wiremock/spring/{WireMockConfigurationCustomizerTests.java => WireMockConfigurationCustomizerTest.java} (86%) diff --git a/README.md b/README.md index 59dd02b..565cb3e 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,33 @@ It can be changed with setting `stubLocation` on `@ConfigureWireMock`: @ConfigureWireMock(name = "...", property = "...", stubLocation = "my-stubs") ``` +### Advanced configuration + +More advanced configuration can be applied through configuration customizers: + +```java +@ConfigureWireMock( + name = "todo-service", + property = "todo-service.url", + configurationCustomizers = SampleConfigurationCustomizer.class +) +``` + +Where `SampleConfigurationCustomizer` is a class implementing `WireMockConfigurationCustomizer`: + +```java +class SampleConfigurationCustomizer implements WireMockConfigurationCustomizer { + + @Override + public void customize(WireMockConfiguration configuration, ConfigureWireMock options) { + // apply changes to configuration + } +} +``` + +> [!IMPORTANT] +> `WireMockConfigurationCustomizer` must have a no-arg constructor. + Sounds good? Consider [❤️ Sponsoring](https://github.com/sponsors/maciejwalkowiak) the project! Thank you! ## 🙏 Credits diff --git a/wiremock-spring-boot/src/test/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizerTests.java b/wiremock-spring-boot/src/test/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizerTest.java similarity index 86% rename from wiremock-spring-boot/src/test/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizerTests.java rename to wiremock-spring-boot/src/test/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizerTest.java index 80dd24e..4e99bfa 100644 --- a/wiremock-spring-boot/src/test/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizerTests.java +++ b/wiremock-spring-boot/src/test/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizerTest.java @@ -10,28 +10,25 @@ import static org.assertj.core.api.Assertions.assertThat; -@SpringBootTest(classes = WireMockConfigurationCustomizerTests.AppConfiguration.class) +@SpringBootTest(classes = WireMockConfigurationCustomizerTest.AppConfiguration.class) @EnableWireMock({ @ConfigureWireMock( name = "user-service", property = "user-service.url", - configurationCustomizers = WireMockConfigurationCustomizerTests.SampleConfigurationCustomizer.class + configurationCustomizers = WireMockConfigurationCustomizerTest.SampleConfigurationCustomizer.class ), @ConfigureWireMock( name = "todo-service", property = "todo-service.url", - configurationCustomizers = WireMockConfigurationCustomizerTests.SampleConfigurationCustomizer.class + configurationCustomizers = WireMockConfigurationCustomizerTest.SampleConfigurationCustomizer.class ), }) -class WireMockConfigurationCustomizerTests { +class WireMockConfigurationCustomizerTest { private static final int USER_SERVICE_PORT = TestSocketUtils.findAvailableTcpPort(); private static final int TODO_SERVICE_PORT = TestSocketUtils.findAvailableTcpPort(); static class SampleConfigurationCustomizer implements WireMockConfigurationCustomizer { - SampleConfigurationCustomizer(String foo) { - } - @Override public void customize(WireMockConfiguration configuration, ConfigureWireMock options) { if (options.name().equals("user-service")) {