// Path: harahachibu/src/main/java/uk/co/flax/harahachibu/services/data/ElasticsearchClusterStats.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class ElasticsearchClusterStats {
// 
// 	@JsonProperty("timestamp")
// 	private final long timestamp;
// 
// 	@JsonProperty("cluster_name")
// 	private final String clusterName;
// 
// 	@JsonProperty("status")
// 	private final String status;
// 
// 	@JsonProperty(value = "nodes")
// 	private final ElasticsearchClusterNodes nodes;
// 
// 	public ElasticsearchClusterStats(@JsonProperty("timestamp") long timestamp,
// 									 @JsonProperty("cluster_name") String clusterName,
// 									 @JsonProperty("status") String status,
// 									 @JsonProperty("nodes") ElasticsearchClusterNodes nodes) {
// 		this.timestamp = timestamp;
// 		this.clusterName = clusterName;
// 		this.status = status;
// 		this.nodes = nodes;
// 	}
// 
// 	public long getTimestamp() {
// 		return timestamp;
// 	}
// 
// 	public String getClusterName() {
// 		return clusterName;
// 	}
// 
// 	public String getStatus() {
// 		return status;
// 	}
// 
// 	public ElasticsearchClusterNodes getNodes() {
// 		return nodes;
// 	}
// 
// 	public long getFilesystemFreeBytes() {
// 		ElasticsearchClusterFilesystem fs = getFilesystem();
// 		if (fs != null) {
// 			return fs.getFreeBytes();
// 		}
// 		return 0;
// 	}
// 
// 	public long getFilesystemAvailableBytes() {
// 		ElasticsearchClusterFilesystem fs = getFilesystem();
// 		if (fs != null) {
// 			return fs.getAvailableBytes();
// 		}
// 		return 0;
// 	}
// 
// 	public long getFilesystemTotalBytes() {
// 		ElasticsearchClusterFilesystem fs = getFilesystem();
// 		if (fs != null) {
// 			return fs.getTotalBytes();
// 		}
// 		return 0;
// 	}
// 
// 	private ElasticsearchClusterFilesystem getFilesystem() {
// 		if (nodes != null) {
// 			return nodes.getFileSystem();
// 		}
// 		return null;
// 	}
// 
// }


import com.codahale.metrics.MetricRegistry;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.lifecycle.setup.LifecycleEnvironment;
import io.dropwizard.setup.Environment;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockserver.client.server.MockServerClient;
import org.mockserver.model.Header;
import org.mockserver.model.JsonBody;
import org.mockserver.verify.VerificationTimes;
import uk.co.flax.harahachibu.services.data.ElasticsearchClusterStats;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.Client;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;
						.withHeaders(new Header("Content-Type", "application/json"))
						.withStatusCode(HttpServletResponse.SC_OK));

		esClient.getClusterStats();
	}

	@Test
	public void returnsClusterStats() throws Exception {
		mockServer.when(request().withPath(ElasticsearchClient.CLUSTER_STATS_ENDPOINT))
				.respond(response()
						.withBody(new JsonBody(clusterStatsJson))
						.withHeaders(new Header("Content-Type", "application/json"))
						.withStatusCode(HttpServletResponse.SC_OK));

		ElasticsearchClusterStats clusterStats = esClient.getClusterStats();
		assertThat(clusterStats).isNotNull();
		assertThat(clusterStats.getStatus()).isEqualTo("red");
		assertThat(clusterStats.getNodes().getFileSystem().getTotalBytes()).isEqualTo(206289465344L);
		assertThat(clusterStats.getNodes().getFileSystem().getFreeBytes()).isEqualTo(132861665280L);
		assertThat(clusterStats.getNodes().getFileSystem().getAvailableBytes()).isEqualTo(122359132160L);
	}

	@Test
	public void serverCalledOnceInCacheTime() throws Exception {
		mockServer.when(request().withPath(ElasticsearchClient.CLUSTER_STATS_ENDPOINT))
				.respond(response()
						.withBody(new JsonBody(clusterStatsJson))
						.withHeaders(new Header("Content-Type", "application/json"))
						.withStatusCode(HttpServletResponse.SC_OK));

// Path: harahachibu/src/main/java/uk/co/flax/harahachibu/services/data/ElasticsearchClusterStats.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public class ElasticsearchClusterStats {
// 
// 	@JsonProperty("timestamp")
// 	private final long timestamp;
// 
// 	@JsonProperty("cluster_name")
// 	private final String clusterName;
// 
// 	@JsonProperty("status")
// 	private final String status;
// 
// 	@JsonProperty(value = "nodes")
// 	private final ElasticsearchClusterNodes nodes;
// 
// 	public ElasticsearchClusterStats(@JsonProperty("timestamp") long timestamp,
// 									 @JsonProperty("cluster_name") String clusterName,
// 									 @JsonProperty("status") String status,
// 									 @JsonProperty("nodes") ElasticsearchClusterNodes nodes) {
// 		this.timestamp = timestamp;
// 		this.clusterName = clusterName;
// 		this.status = status;
// 		this.nodes = nodes;
// 	}
// 
// 	public long getTimestamp() {
// 		return timestamp;
// 	}
// 
// 	public String getClusterName() {
// 		return clusterName;
// 	}
// 
// 	public String getStatus() {
// 		return status;
// 	}
// 
// 	public ElasticsearchClusterNodes getNodes() {
// 		return nodes;
// 	}
// 
// 	public long getFilesystemFreeBytes() {
// 		ElasticsearchClusterFilesystem fs = getFilesystem();
// 		if (fs != null) {
// 			return fs.getFreeBytes();
// 		}
// 		return 0;
// 	}
// 
// 	public long getFilesystemAvailableBytes() {
// 		ElasticsearchClusterFilesystem fs = getFilesystem();
// 		if (fs != null) {
// 			return fs.getAvailableBytes();
// 		}
// 		return 0;
// 	}
// 
// 	public long getFilesystemTotalBytes() {
// 		ElasticsearchClusterFilesystem fs = getFilesystem();
// 		if (fs != null) {
// 			return fs.getTotalBytes();
// 		}
// 		return 0;
// 	}
// 
// 	private ElasticsearchClusterFilesystem getFilesystem() {
// 		if (nodes != null) {
// 			return nodes.getFileSystem();
// 		}
// 		return null;
// 	}
// 
// }


// Path: harahachibu/src/test/java/uk/co/flax/harahachibu/services/impl/ElasticsearchClientTest.java
import com.codahale.metrics.MetricRegistry;
import io.dropwizard.client.JerseyClientBuilder;
import io.dropwizard.lifecycle.setup.LifecycleEnvironment;
import io.dropwizard.setup.Environment;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockserver.client.server.MockServerClient;
import org.mockserver.model.Header;
import org.mockserver.model.JsonBody;
import org.mockserver.verify.VerificationTimes;
import uk.co.flax.harahachibu.services.data.ElasticsearchClusterStats;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.client.Client;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.*;
import static org.mockserver.integration.ClientAndServer.startClientAndServer;
import static org.mockserver.model.HttpRequest.request;
import static org.mockserver.model.HttpResponse.response;

						.withHeaders(new Header("Content-Type", "application/json"))
						.withStatusCode(HttpServletResponse.SC_OK));

		esClient.getClusterStats();
	}

	@Test
	public void returnsClusterStats() throws Exception {
		mockServer.when(request().withPath(ElasticsearchClient.CLUSTER_STATS_ENDPOINT))
				.respond(response()
						.withBody(new JsonBody(clusterStatsJson))
						.withHeaders(new Header("Content-Type", "application/json"))
						.withStatusCode(HttpServletResponse.SC_OK));

		ElasticsearchClusterStats clusterStats = esClient.getClusterStats();
		assertThat(clusterStats).isNotNull();
		assertThat(clusterStats.getStatus()).isEqualTo("red");
		assertThat(clusterStats.getNodes().getFileSystem().getTotalBytes()).isEqualTo(206289465344L);
		assertThat(clusterStats.getNodes().getFileSystem().getFreeBytes()).isEqualTo(132861665280L);
		assertThat(clusterStats.getNodes().getFileSystem().getAvailableBytes()).isEqualTo(122359132160L);
	}

	@Test
	public void serverCalledOnceInCacheTime() throws Exception {
		mockServer.when(request().withPath(ElasticsearchClient.CLUSTER_STATS_ENDPOINT))
				.respond(response()
						.withBody(new JsonBody(clusterStatsJson))
						.withHeaders(new Header("Content-Type", "application/json"))
						.withStatusCode(HttpServletResponse.SC_OK));

		ElasticsearchClusterStats clusterStats = esClient.getClusterStats();