Created
October 21, 2022 02:17
-
-
Save wenqiglantz/c141c0cdd24056e67c4f20b81114d90e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class WireMockInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> { | |
| @Override | |
| public void initialize(ConfigurableApplicationContext applicationContext) { | |
| WireMockServer wireMockServer = | |
| new WireMockServer(new WireMockConfiguration().dynamicPort()); | |
| wireMockServer.start(); | |
| applicationContext.addApplicationListener(applicationEvent -> { | |
| if (applicationEvent instanceof ContextClosedEvent) { | |
| wireMockServer.stop(); | |
| } | |
| }); | |
| applicationContext.getBeanFactory() | |
| .registerSingleton("wireMockServer", wireMockServer); | |
| TestPropertyValues | |
| .of(Map.of("customer-service.urls.base-url", wireMockServer.baseUrl())) | |
| .applyTo(applicationContext); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment