HttpValidator implements ApiValidator { @Override public boolean isOk() { Request request = new Request.Builder() .url(endpoint) .build(); try { Response response = httpClient.newCall(request).execute(); return validateResponse(response); } catch (IOException e) { return false; } } HttpValidator(OkHttpClient httpClient, String endpoint); @Override boolean isOk(); String getEndpoint();  }
@Test public void is_not_ok_when_response_timeout() throws Exception { addRequestProcessingDelay((int) TimeUnit.SECONDS.toMillis(5)); stubFor(get(urlEqualTo("/ping")) .willReturn(aResponse() .withStatus(200)) ); boolean isOk = httpValidator.isOk(); assertFalse(isOk); }
@Test public void is_not_ok_when_host_not_found() throws Exception { httpValidator = new HttpValidator(okHttpClient, "http: boolean isOk = httpValidator.isOk(); assertFalse(isOk); }
@Test public void is_ok_when_response_is_200() throws Exception { stubFor(get(urlEqualTo("/ping")) .willReturn(aResponse() .withStatus(200)) ); boolean isOk = httpValidator.isOk(); assertTrue(isOk); }
@Test public void is_not_ok_when_response_is_500() throws Exception { stubFor(get(urlEqualTo("/ping")) .willReturn(aResponse() .withStatus(500)) ); boolean isOk = httpValidator.isOk(); assertFalse(isOk); }