// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
// 
//     public String name;
//     public String value;
// 
//     public JsonPair() { } // for Jackson
// 
//     public JsonPair(String name, String value) {
//         this.name = name;
//         this.value = value;
//     }
// 
//     @Override
//     public int hashCode() {
//         return HashCodeBuilder.reflectionHashCode(this);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         return EqualsBuilder.reflectionEquals(this, obj);
//     }
// 
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
// 
//     public String method;
//     public String path;
//     public JsonPairList params;
//     
//     public void setParam(String name, String value) {
//         if (params == null) {
//             params = new JsonPairList();
//         }
//         params.set(name, value);
//     }
// 
//     public void addParam(String name, String value) {
//         if (params == null) {
//             params = new JsonPairList();
//         }
//         params.add(name, value);
//     }
//     
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//     
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
// 
//     private static final String P_TEST_SERVER = "test.server"; // server to test against
// 
//     protected Client client;
// 
//     @Before
//     public void before() {
//         String testServer = System.getProperty(P_TEST_SERVER);
// 
//         client = new Client(testServer);
//         client.reset();
//     }
// 
//     @After
//     public void after() {
//         client.close();
//     }
// 
//     protected void postFile(String filename) {
//         String path = "/tests/" + filename;
//         InputStream resource = getClass().getResourceAsStream(path);
//         if (resource != null) {
//             try {
//                 client.postMessage(IOUtils.toString(resource));
//             } catch (IOException e) {
//                 throw new RuntimeException("Error posting file", e);
//             }
//         } else {
//             throw new RuntimeException("Resource not found: " + path);
//         }
//     }
// 
//     protected String makeUri(String path) {
//         return client.makeUri(path);
//     }
// 
//     protected void close(HttpResponse response) {
//         HttpClientUtils.closeQuietly(response);
//     }
// 
//     protected GenericClientResponse execute(HttpUriRequest request) {
//         return client.execute(request);
//     }
// 
//     protected Client client() {
//         return client;
//     }
// 
//     protected JsonStubbedExchangeList responses() {
//         return client.getResponses();
//     }
// 
//     protected void assertOk(GenericClientResponse response) {
//         assertStatus(HttpStatus.SC_OK, response);
//     }
//     
//     protected void assertNotFound(GenericClientResponse response) {
//         assertStatus(HttpStatus.SC_NOT_FOUND, response);
//     }
// 
//     protected void assertStatus(int status, GenericClientResponse response) {
//         Assert.assertEquals(status, response.getStatus());
//     }
// 
//     protected MessageBuilder builder() {
//         return new MessageBuilder(client);
//     }
//         
//     protected void assertHasHeader(JsonMessage request, String name, String value) {
//         for (JsonPair header : request.headers) {
//             if (header.name.equalsIgnoreCase(name)
//                     && header.value.equals(value)) {
//                 return;
//             }
//         }
//         fail();
//     }
//     
//     protected void assumeNotTravisCi() {
//         assumeFalse("Running as Travis CI", isTravisCi());
//     }
//     
//     protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
//         return "true".equals(System.getenv("TRAVIS"));
//     }
// 
//     protected void assertTimeTaken(long started, long ended, long expected) {
//         double tolerance = 500; // 1/2 second tolerance
// 
//         if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
//             assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
//         }
//     }
// 
//     protected long now() {
//         return System.currentTimeMillis();
//     }
// 
// }


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;
        assertEquals(2, requests.size());
        assertEquals("/test/2", requests.get(0).path);
        assertEquals("/test/1", requests.get(1).path);
    }
    
    @Test
    public void testGetRequestNotFound() {
        client.executeGet("/test/1");
        
        assertEquals(200, client.executeGet("/_control/requests/0").getStatus());
        assertEquals(404, client.executeGet("/_control/requests/1").getStatus());
    }
    
    @Test
    public void testDeleteRequests() {
        client.executeGet("/test/1");
        assertEquals(1, client.getRequests().size());
        
        client.deleteRequests();
        assertEquals(0, client.getRequests().size());
    }
    
    @Test
    public void testRequestDetails() {
        HttpPost post = new HttpPost(client.makeUri("/test/path?foo=bar1&foo=bar2"));
        post.addHeader("X-Foo", "bar1");
        post.addHeader("X-Foo", "bar2");
        post.setEntity(new StringEntity("Testing content", ContentType.TEXT_PLAIN));
        client.execute(post);

// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonPair.java
// public class JsonPair {
// 
//     public String name;
//     public String value;
// 
//     public JsonPair() { } // for Jackson
// 
//     public JsonPair(String name, String value) {
//         this.name = name;
//         this.value = value;
//     }
// 
//     @Override
//     public int hashCode() {
//         return HashCodeBuilder.reflectionHashCode(this);
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         return EqualsBuilder.reflectionEquals(this, obj);
//     }
// 
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequest.java
// public class JsonRequest extends JsonMessage {
// 
//     public String method;
//     public String path;
//     public JsonPairList params;
//     
//     public void setParam(String name, String value) {
//         if (params == null) {
//             params = new JsonPairList();
//         }
//         params.set(name, value);
//     }
// 
//     public void addParam(String name, String value) {
//         if (params == null) {
//             params = new JsonPairList();
//         }
//         params.add(name, value);
//     }
//     
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonRequestList.java
// @SuppressWarnings("serial")
// public class JsonRequestList extends ArrayList<JsonRequest> {
//     
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/support/TestBase.java
// public abstract class TestBase {
// 
//     private static final String P_TEST_SERVER = "test.server"; // server to test against
// 
//     protected Client client;
// 
//     @Before
//     public void before() {
//         String testServer = System.getProperty(P_TEST_SERVER);
// 
//         client = new Client(testServer);
//         client.reset();
//     }
// 
//     @After
//     public void after() {
//         client.close();
//     }
// 
//     protected void postFile(String filename) {
//         String path = "/tests/" + filename;
//         InputStream resource = getClass().getResourceAsStream(path);
//         if (resource != null) {
//             try {
//                 client.postMessage(IOUtils.toString(resource));
//             } catch (IOException e) {
//                 throw new RuntimeException("Error posting file", e);
//             }
//         } else {
//             throw new RuntimeException("Resource not found: " + path);
//         }
//     }
// 
//     protected String makeUri(String path) {
//         return client.makeUri(path);
//     }
// 
//     protected void close(HttpResponse response) {
//         HttpClientUtils.closeQuietly(response);
//     }
// 
//     protected GenericClientResponse execute(HttpUriRequest request) {
//         return client.execute(request);
//     }
// 
//     protected Client client() {
//         return client;
//     }
// 
//     protected JsonStubbedExchangeList responses() {
//         return client.getResponses();
//     }
// 
//     protected void assertOk(GenericClientResponse response) {
//         assertStatus(HttpStatus.SC_OK, response);
//     }
//     
//     protected void assertNotFound(GenericClientResponse response) {
//         assertStatus(HttpStatus.SC_NOT_FOUND, response);
//     }
// 
//     protected void assertStatus(int status, GenericClientResponse response) {
//         Assert.assertEquals(status, response.getStatus());
//     }
// 
//     protected MessageBuilder builder() {
//         return new MessageBuilder(client);
//     }
//         
//     protected void assertHasHeader(JsonMessage request, String name, String value) {
//         for (JsonPair header : request.headers) {
//             if (header.name.equalsIgnoreCase(name)
//                     && header.value.equals(value)) {
//                 return;
//             }
//         }
//         fail();
//     }
//     
//     protected void assumeNotTravisCi() {
//         assumeFalse("Running as Travis CI", isTravisCi());
//     }
//     
//     protected boolean isTravisCi() { // set when running under Travis CI (travis-ci.org)
//         return "true".equals(System.getenv("TRAVIS"));
//     }
// 
//     protected void assertTimeTaken(long started, long ended, long expected) {
//         double tolerance = 500; // 1/2 second tolerance
// 
//         if (!isTravisCi()) { // don't assert timing if running on Travis-CI (it's quite slow...)
//             assertEquals(expected, Math.abs(ended - started), tolerance); // assert delay within tolerance
//         }
//     }
// 
//     protected long now() {
//         return System.currentTimeMillis();
//     }
// 
// }


// Path: functional-test/src/main/java/au/com/sensis/stubby/test/ControlRequestTest.java
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonPair;
import au.com.sensis.stubby.test.model.JsonRequest;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;

        assertEquals(2, requests.size());
        assertEquals("/test/2", requests.get(0).path);
        assertEquals("/test/1", requests.get(1).path);
    }
    
    @Test
    public void testGetRequestNotFound() {
        client.executeGet("/test/1");
        
        assertEquals(200, client.executeGet("/_control/requests/0").getStatus());
        assertEquals(404, client.executeGet("/_control/requests/1").getStatus());
    }
    
    @Test
    public void testDeleteRequests() {
        client.executeGet("/test/1");
        assertEquals(1, client.getRequests().size());
        
        client.deleteRequests();
        assertEquals(0, client.getRequests().size());
    }
    
    @Test
    public void testRequestDetails() {
        HttpPost post = new HttpPost(client.makeUri("/test/path?foo=bar1&foo=bar2"));
        post.addHeader("X-Foo", "bar1");
        post.addHeader("X-Foo", "bar2");
        post.setEntity(new StringEntity("Testing content", ContentType.TEXT_PLAIN));
        client.execute(post);

        JsonRequest request = client.getRequest(0);