-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to customize configuration on
@ConfigureWireMock
annotat…
- Loading branch information
1 parent
4fd8a99
commit 54d0191
Showing
5 changed files
with
124 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
...ot/src/main/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.maciejwalkowiak.wiremock.spring; | ||
|
||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
|
||
/** | ||
* Customizes {@link WireMockConfiguration} programmatically. Can be registered with {@link ConfigureWireMock#configurationCustomizers()}. | ||
* Customizer must have public no-arg constructor. | ||
*/ | ||
public interface WireMockConfigurationCustomizer { | ||
|
||
void customize(WireMockConfiguration configuration, ConfigureWireMock options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...rc/test/java/com/maciejwalkowiak/wiremock/spring/WireMockConfigurationCustomizerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.maciejwalkowiak.wiremock.spring; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.util.TestSocketUtils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest(classes = WireMockConfigurationCustomizerTest.AppConfiguration.class) | ||
@EnableWireMock({ | ||
@ConfigureWireMock( | ||
name = "user-service", | ||
property = "user-service.url", | ||
configurationCustomizers = WireMockConfigurationCustomizerTest.SampleConfigurationCustomizer.class | ||
), | ||
@ConfigureWireMock( | ||
name = "todo-service", | ||
property = "todo-service.url", | ||
configurationCustomizers = WireMockConfigurationCustomizerTest.SampleConfigurationCustomizer.class | ||
), | ||
}) | ||
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 { | ||
|
||
@Override | ||
public void customize(WireMockConfiguration configuration, ConfigureWireMock options) { | ||
if (options.name().equals("user-service")) { | ||
configuration.port(USER_SERVICE_PORT); | ||
} else { | ||
configuration.port(TODO_SERVICE_PORT); | ||
} | ||
} | ||
} | ||
|
||
@SpringBootApplication | ||
static class AppConfiguration { | ||
|
||
} | ||
|
||
@InjectWireMock("user-service") | ||
private WireMockServer userService; | ||
|
||
@InjectWireMock("todo-service") | ||
private WireMockServer todoService; | ||
|
||
@Test | ||
void appliesConfigurationCustomizer() { | ||
assertThat(userService.port()).isEqualTo(USER_SERVICE_PORT); | ||
assertThat(todoService.port()).isEqualTo(TODO_SERVICE_PORT); | ||
} | ||
|
||
} |