最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

java - Wiremock verify lost ThreadLocal Context in quarkus 3.19.1 and wiremock 3.0.1 - Stack Overflow

programmeradmin4浏览0评论

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: .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:

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: .java

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: .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/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/robyp1/app-quarkus-wiremock/blob/main/src/test/java//acme/wiremock/WireMockServerManager.java

Share Improve this question edited Mar 24 at 21:45 robyp7 asked Mar 24 at 20:49 robyp7robyp7 4872 gold badges9 silver badges28 bronze badges 4
  • 3.0.1 is a very old version of WireMock. Have you tried upgrading to the latest - 3.12.1? – Tom Commented Mar 25 at 12:21
  • @Tom i update to 3.12.1 but it doesnt work ..same problem – robyp7 Commented Mar 25 at 20:28
  • You're mixing static and instance calls to the WireMock DSL, which isn't usually a good idea. I suggest you use wireMockClient.verifyThat(...) rather than the static verify(). You could simplify things further (assuming WireMockServerManager is your test base class) by making the server protected and calling the DSL on it directly, removing the client. – Tom Commented Mar 27 at 9:47
  • Hi @Tom, you re right! Thanks it works! – robyp7 Commented Mar 31 at 20:26
Add a comment  | 

1 Answer 1

Reset to default 0

Thanks to Tom i resolved using:

wireMockClient.verifyThat(...)

发布评论

评论列表(0)

  1. 暂无评论