### Question:
MappingTypeElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { final Response response = client.getLowLevelClient().performRequest(new Request(HttpGet.METHOD_NAME, CLUSTER_HEALTH_ENDPOINT)); final String body = EntityUtils.toString(response.getEntity()); final Map jsonMap = new ObjectMapper().readValue(body, Map.class); if (jsonMap.containsKey("status")) { final String status = jsonMap.get("status").toString(); if ("yellow".equals(status) || "green".equals(status)) { ret = true; } else { LOGGER.warn("Cluster status not healthy: {}", status); } } else { LOGGER.warn("No status in _cluster/health response - {}", body); } } catch (ResponseException e) { LOGGER.warn("Caught ResponseException calling {}: {}", CLUSTER_HEALTH_ENDPOINT, e.getResponse().getStatusLine()); } catch (IOException e) { LOGGER.error("Caught IOException calling _cluster/health: {}", e.getMessage()); } return ret; } MappingTypeElasticsearchConnector(RestHighLevelClient client); @Override boolean isAvailable(); @Override boolean indexExists(String index); @Override boolean createIndex(String index); @Override void storeItems(String index, Collection<QueryVersionReport> reports); @Override void close();  }### Answer:
@Test public void isAvailableReturnsFalse_whenStatusIsBad() { mockServerClient.when(request().withPath(ElasticsearchConnector.CLUSTER_HEALTH_ENDPOINT)) .respond(response().withStatusCode(500).withReasonPhrase("Server error")); assertThat(connector.isAvailable()).isFalse(); }
@Test public void isAvailableReturnsFalse_whenNoStatusInBody() { mockServerClient.when(request().withPath(ElasticsearchConnector.CLUSTER_HEALTH_ENDPOINT)) .respond(response().withStatusCode(200).withBody("{}", MediaType.JSON_UTF_8)); assertThat(connector.isAvailable()).isFalse(); }
@Test public void isAvailableReturnsFalse_whenStatusRed() { mockServerClient.when(request().withPath(ElasticsearchConnector.CLUSTER_HEALTH_ENDPOINT)) .respond(response().withStatusCode(200).withBody("{ \"status\": \"red\" }", MediaType.JSON_UTF_8)); assertThat(connector.isAvailable()).isFalse(); }
@Test public void isAvailableReturnsTrue_whenStatusYellow() { mockServerClient.when(request().withPath(ElasticsearchConnector.CLUSTER_HEALTH_ENDPOINT)) .respond(response().withStatusCode(200).withBody("{ \"status\": \"yellow\" }", MediaType.JSON_UTF_8)); assertThat(connector.isAvailable()).isTrue(); }
@Test public void isAvailableReturnsTrue_whenStatusGreen() { mockServerClient.when(request().withPath(ElasticsearchConnector.CLUSTER_HEALTH_ENDPOINT)) .respond(response().withStatusCode(200).withBody("{ \"status\": \"green\" }", MediaType.JSON_UTF_8)); assertThat(connector.isAvailable()).isTrue(); }