WireMok

I have discovered WireMock

If you have an HTTP Client in Java, You can mock/inject any type of response into that Client, and try-out special scenarios like time-outs, different status-codes, etc… and see how your code behaves….


HttpRequestUtil cut ;

String host = "http://localhost:8888";
String endPoint = "/customsearch/v1?key";
String url = host+endPoint;

stubFor(get(urlEqualTo(endPoint))
.willReturn(aResponse()
.withHeader("Content-Type", "text/plain")
.withBody("Hello world!")));

String response = cut.doGet(url);

cut = new HttpRequestUtil(time20000ms);

stubFor(get(urlEqualTo(endPoint)).willReturn(
aResponse()
.withStatus(200)
.withFixedDelay(time20000ms)));

String response = cut.doGet(url);
//java.util.concurrent.TimeoutException: No response received after 20000

One thought on “WireMok

Leave a comment