Also shared here: https://github.com/tomakehurst/wiremock/issues/625
I am writing an integration test to make sure that my application that interacts with the REST API handles unsuccessful requests appropriately. For this, I want to simulate a scenario where GET requests are made twice at the HTTP endpoint. The first time a request is not executed with a response status code of 500; the second time the request was completed successfully with the response status code 200. Consider the following example:
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()
.dynamicHttpsPort());
@Test
public void testRetryScenario(){
stubFor(get(urlEqualTo("/my/resource"))
.withHeader("Accept", equalTo("text/xml"))
.willReturn(aResponse()
.withStatus(500)
.withHeader("Content-Type", "text/xml")
.withBody("<response>Some content</response>")));
stubFor(get(urlEqualTo("/my/resource"))
.withHeader("Accept", equalTo("text/xml"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody("<response>Some content</response>")));
doSomething();
Thread.sleep(5000);
verify(exactly(2), getRequestedFor(urlEqualTo("/my/resource")));
}
StubMapping - , doSomething() , 500, , 200?