javaquarkuswiremockquarkus-reactivewiremock-standalone

Wiremock verify lost ThreadLocal Context in quarkus 3.19.1 and wiremock 3.0.1


I have a question about wiremock

AppResourceTest.class in the link below doesn't work as i expectedwith wiremock-standalone.

I start Wiremock server inside a QuarkusTestResourceLifecycleManager custom implementations, and I expose a Wiremock as injection property in all test classes annotated with @QuarkusTestResource(value = WiremockTestResourceConfigurableLifecycleManager.class).

All works fine, but there is a problem: when i called Wiremock.verify, seems that the InheritableThreadLocal has never returned the host and port i set previously ,but always the defaults.

The error is "Caused by: org.apache.hc.client5.http.HttpHostConnectException: Connect to http://localhost:8080 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: no further information".

Otherwise, if i use WireMock.configureFor(wireMockClient); my test works.

How can solve it? Is it a bug?

Thanks

You can find my code here: https://github.com/robyp1/app-quarkus-wiremock

my issue is here:

 @Test
void getDrivers() {
    assert  wireMockClient != null;
    logger.info(wireMockClient.toString());

    wireMockClient.register(WireMock.get("/api/2010/drivers").willReturn(
            WireMock.aResponse().withStatus(200).withBody(jsonResponse)));

    final Response response = given()
            .when().get("/drivers")
            .then()
            .statusCode(200)
            .assertThat()
            .statusCode(SC_OK)
            .contentType(ContentType.JSON)
            .extract().as(Response.class);

    //FIXME : if i add this, verify works! InnerThreadLocal not work, why? 
    //WireMock.configureFor(wireMockClient);

    verify(1,
            WireMock.getRequestedFor(WireMock.urlPathEqualTo("/api/2010/drivers")));
    logger.info("resp:{}", response ); //throw error!
}

But WireMock.configureFor(wireMockClient) has already executed before unit test start in the class WireMockServerManager: https://github.com/robyp1/app-quarkus-wiremock/blob/main/src/test/java/org/acme/wiremock/WireMockServerManager.java


Solution

  • Thanks to Tom i resolved using:

    wireMockClient.verifyThat(...)