Search code examples
javajunit5wiremock

Tomakehurst Wiremock. Tries to connect to 8080. Connection refused


@Test
    void resourceTo_Wired_ClientCall() {

        wireMockServer = new WireMockServer(options().port(10021));
        wireMockServer.start();

            final MappingBuilder stubBuilder = get(urlMatching("http://demo1096495.mockable.io/client1"));

            stubFor(stubBuilder
                    .willReturn(aResponse()
                            .withStatus(200)
                            .withHeader("Content-Type", "application/json")
                            .withBody("{\"something\":\"test-wired\"}")));
            ;

Got error:

org.apache.http.conn.HttpHostConnectException: Connect to localhost:8080 [localhost/127.0.0.1] failed: Connection refused (Connection refused)

What is missed of any?

P.S. I use WireMockServer with junit 5 and spring boot. with junit 4 and WireMockRule all works well.

 testCompile "com.github.tomakehurst:wiremock-jre8:2.24.1"

Solution

  • UPDATE:

    https://github.com/tomakehurst/wiremock/issues/369

    added: WireMock.configureFor("localhost", 10021);

    before wireMockServer.start();

    Then that error is gone. It passed to next lines.

    P.S. Got some new thing..but that is different issue.