Creating multiple WireMockServer within a single test

73 Views Asked by At

My controller accesses 2 services on different ports for full operation. When it comes to 1 service, everything works well. But as soon as I try to create a second WireMockServer, it apparently recreates the old one, such that in any case there is only 1 working WireMockServer left.

Thus, I get the error: "404 Not Found: No response could be served as there are no stub mappings in this Wire Mockinstance.", because first there is a call to the first WireMockServer, which has already been overwritten by the second.

The question is, how do I organize two WireMockServers to work together?

I was thinking of creating a separate class to create a WireMockServer for the prototype area, but I'm not sure if this would work the way I need it, since the context is the same, right?

@ClassRule
public static WireMockServer wireMockServer = new WireMockServer(8084);
@ClassRule
public static WireMockServer wireMockServer2 = new WireMockServer(8081);

static class Initializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
    public void initialize(@NotNull ConfigurableApplicationContext context) {
        if (!wireMockServer.isRunning()) {
            wireMockServer.start();
            configureFor("localhost", 8084);
        }
        if (!wireMockServer2.isRunning()) {
            wireMockServer2.start();
            configureFor("localhost", 8081);
        }
    }
}
0

There are 0 best solutions below