// 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 java.util.concurrent.atomic.AtomicReference;
import org.apache.http.client.methods.HttpPost;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;
    
    @Test
    public void testFindParam() {
        JsonRequestList requests = client.findRequests("param[foo]=bar");
        assertEquals(1, requests.size());
        assertEquals("/test2", requests.get(0).path);
    }
    
    @Test
    public void testFindParams() {
        JsonRequestList requests = client.findRequests("param[foo]=bar1&param[foo]=bar2");
        assertEquals(1, requests.size());
        assertEquals("/test3", requests.get(0).path);
    }
    
    @Test
    public void testFindHeader() {
        JsonRequestList requests = client.findRequests("header[X-FOO]=bar"); // test case insensitivity
        assertEquals(1, requests.size());
        assertEquals("/test5", requests.get(0).path);
    }
    
    @Test
    public void testFindHeaders() {
        JsonRequestList requests = client.findRequests("header[X-Foo]=bar1&header[X-Foo]=bar2");
        assertEquals(1, requests.size());
        assertEquals("/test6", requests.get(0).path);
    }

    @Test
// 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/FindRequestTest.java
import static org.junit.Assert.assertEquals;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.http.client.methods.HttpPost;
import org.junit.Before;
import org.junit.Test;
import au.com.sensis.stubby.test.model.JsonRequestList;
import au.com.sensis.stubby.test.support.TestBase;

    
    @Test
    public void testFindParam() {
        JsonRequestList requests = client.findRequests("param[foo]=bar");
        assertEquals(1, requests.size());
        assertEquals("/test2", requests.get(0).path);
    }
    
    @Test
    public void testFindParams() {
        JsonRequestList requests = client.findRequests("param[foo]=bar1&param[foo]=bar2");
        assertEquals(1, requests.size());
        assertEquals("/test3", requests.get(0).path);
    }
    
    @Test
    public void testFindHeader() {
        JsonRequestList requests = client.findRequests("header[X-FOO]=bar"); // test case insensitivity
        assertEquals(1, requests.size());
        assertEquals("/test5", requests.get(0).path);
    }
    
    @Test
    public void testFindHeaders() {
        JsonRequestList requests = client.findRequests("header[X-Foo]=bar1&header[X-Foo]=bar2");
        assertEquals(1, requests.size());
        assertEquals("/test6", requests.get(0).path);
    }

    @Test
    public void testWait_noResults() {