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
- 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
1 Answer
Reset to default 0Thanks to Tom i resolved using:
wireMockClient.verifyThat(...)