// Path: src/test/java/me/magnet/consultant/HttpUtils.java
// public static StatusLine createStatus(int status, String phrase) {
// 	return new BasicStatusLine(new ProtocolVersion("http", 1, 1), status, phrase);
// }
// 
// Path: src/test/java/me/magnet/consultant/HttpUtils.java
// public static StringEntity toJson(Map<String, String> entries) {
// 	Encoder encoder = Base64.getEncoder();
// 	try {
// 		return new StringEntity("[" + entries.entrySet().stream()
// 				.map(entry -> {
// 					String value = Optional.ofNullable(entry.getValue())
// 							.map(entryValue -> "\"" + encoder.encodeToString(entryValue.getBytes()) + "\"")
// 							.orElse("null");
// 
// 					return "{\"Key\":\"" + entry.getKey() + "\",\"Value\":" + value + "}";
// 				})
// 				.collect(Collectors.joining(",")) + "]");
// 	}
// 	catch (IOException e) {
// 		throw new RuntimeException(e);
// 	}
// }
// 
// Path: src/main/java/me/magnet/consultant/Consultant.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public static class Agent {
// 
// 	@JsonProperty("Config")
// 	private Config config;
// 
// 	public Config getConfig() {
// 		return config;
// 	}
// 
// 	void setConfig(Config config) {
// 		this.config = config;
// 	}
// 
// }
// 
// Path: src/main/java/me/magnet/consultant/Consultant.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public static class Config {
// 
// 	@JsonProperty("Datacenter")
// 	private String datacenter;
// 
// 	@JsonProperty("NodeName")
// 	private String nodeName;
// 
// 	public String getDatacenter() {
// 		return datacenter;
// 	}
// 
// 	public String getNodeName() {
// 		return nodeName;
// 	}
// 
// 	void setDatacenter(String datacenter) {
// 		this.datacenter = datacenter;
// 	}
// 
// 	void setNodeName(String nodeName) {
// 		this.nodeName = nodeName;
// 	}
// 
// }


import static me.magnet.consultant.HttpUtils.createStatus;
import static me.magnet.consultant.HttpUtils.toJson;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.SettableFuture;
import me.magnet.consultant.Consultant.Builder.Agent;
import me.magnet.consultant.Consultant.Builder.Config;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.message.BasicHeader;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
	}

	@Test(timeout = 5_000)
	public void verifyInitialConfigLoad() throws Exception {
		httpBuilder.onGet("/v1/kv/config/oauth/?recurse=true", request -> {
			CloseableHttpResponse response = mock(CloseableHttpResponse.class);
			when(response.getFirstHeader(eq("X-Consul-Index"))).thenReturn(new BasicHeader("X-Consul-Index", "1000"));
			when(response.getStatusLine()).thenReturn(createStatus(200, "OK"));
			when(response.getEntity()).thenReturn(toJson(ImmutableMap.of("config/oauth/some.key", "some-value")));
			return response;
		});

		SettableFuture<Properties> future = SettableFuture.create();

		consultant = Consultant.builder()
				.usingHttpClient(httpBuilder.create())
				.withConsulHost("http://localhost")
				.identifyAs("oauth", "eu-central", "web-1", "master")
				.onValidConfig(future::set)
				.build();

		Properties properties = future.get();
		assertEquals("some-value", properties.getProperty("some.key"));
	}

	@Test(timeout = 5_000, expected = TimeoutException.class)
	public void verifyThatInvalidConfigIsNotPublished() throws Exception {
		httpBuilder.onGet("/v1/kv/config/oauth/?recurse=true", request -> {
			CloseableHttpResponse response = mock(CloseableHttpResponse.class);
			when(response.getFirstHeader(eq("X-Consul-Index"))).thenReturn(new BasicHeader("X-Consul-Index", "1000"));
// Path: src/test/java/me/magnet/consultant/HttpUtils.java
// public static StatusLine createStatus(int status, String phrase) {
// 	return new BasicStatusLine(new ProtocolVersion("http", 1, 1), status, phrase);
// }
// 
// Path: src/test/java/me/magnet/consultant/HttpUtils.java
// public static StringEntity toJson(Map<String, String> entries) {
// 	Encoder encoder = Base64.getEncoder();
// 	try {
// 		return new StringEntity("[" + entries.entrySet().stream()
// 				.map(entry -> {
// 					String value = Optional.ofNullable(entry.getValue())
// 							.map(entryValue -> "\"" + encoder.encodeToString(entryValue.getBytes()) + "\"")
// 							.orElse("null");
// 
// 					return "{\"Key\":\"" + entry.getKey() + "\",\"Value\":" + value + "}";
// 				})
// 				.collect(Collectors.joining(",")) + "]");
// 	}
// 	catch (IOException e) {
// 		throw new RuntimeException(e);
// 	}
// }
// 
// Path: src/main/java/me/magnet/consultant/Consultant.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public static class Agent {
// 
// 	@JsonProperty("Config")
// 	private Config config;
// 
// 	public Config getConfig() {
// 		return config;
// 	}
// 
// 	void setConfig(Config config) {
// 		this.config = config;
// 	}
// 
// }
// 
// Path: src/main/java/me/magnet/consultant/Consultant.java
// @JsonIgnoreProperties(ignoreUnknown = true)
// public static class Config {
// 
// 	@JsonProperty("Datacenter")
// 	private String datacenter;
// 
// 	@JsonProperty("NodeName")
// 	private String nodeName;
// 
// 	public String getDatacenter() {
// 		return datacenter;
// 	}
// 
// 	public String getNodeName() {
// 		return nodeName;
// 	}
// 
// 	void setDatacenter(String datacenter) {
// 		this.datacenter = datacenter;
// 	}
// 
// 	void setNodeName(String nodeName) {
// 		this.nodeName = nodeName;
// 	}
// 
// }


// Path: src/test/java/me/magnet/consultant/ConsultantTest.java
import static me.magnet.consultant.HttpUtils.createStatus;
import static me.magnet.consultant.HttpUtils.toJson;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.SettableFuture;
import me.magnet.consultant.Consultant.Builder.Agent;
import me.magnet.consultant.Consultant.Builder.Config;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.tuple.Triple;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.message.BasicHeader;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

	}

	@Test(timeout = 5_000)
	public void verifyInitialConfigLoad() throws Exception {
		httpBuilder.onGet("/v1/kv/config/oauth/?recurse=true", request -> {
			CloseableHttpResponse response = mock(CloseableHttpResponse.class);
			when(response.getFirstHeader(eq("X-Consul-Index"))).thenReturn(new BasicHeader("X-Consul-Index", "1000"));
			when(response.getStatusLine()).thenReturn(createStatus(200, "OK"));
			when(response.getEntity()).thenReturn(toJson(ImmutableMap.of("config/oauth/some.key", "some-value")));
			return response;
		});

		SettableFuture<Properties> future = SettableFuture.create();

		consultant = Consultant.builder()
				.usingHttpClient(httpBuilder.create())
				.withConsulHost("http://localhost")
				.identifyAs("oauth", "eu-central", "web-1", "master")
				.onValidConfig(future::set)
				.build();

		Properties properties = future.get();
		assertEquals("some-value", properties.getProperty("some.key"));
	}

	@Test(timeout = 5_000, expected = TimeoutException.class)
	public void verifyThatInvalidConfigIsNotPublished() throws Exception {
		httpBuilder.onGet("/v1/kv/config/oauth/?recurse=true", request -> {
			CloseableHttpResponse response = mock(CloseableHttpResponse.class);
			when(response.getFirstHeader(eq("X-Consul-Index"))).thenReturn(new BasicHeader("X-Consul-Index", "1000"));
			when(response.getStatusLine()).thenReturn(createStatus(200, "OK"));