// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/MessageBuilder.java
// public class MessageBuilder {
// 
//     private Client client;
//     private JsonExchange exchange;
// 
//     public MessageBuilder(Client client) {
//         this.client = client;
//         this.exchange = new JsonExchange();
//     }
//  
//     public MessageBuilder setDelay(Long delay) {
//         exchange.delay = delay;
//         return this;
//     }
//     
//     public MessageBuilder setScript(String script) {
//         exchange.script = script;
//         return this;
//     }
//     
//     public MessageBuilder setRequestMethod(String method) {
//         exchange.request().method = method;
//         return this;
//     }
// 
//     public MessageBuilder setRequestPath(String path) {
//         exchange.request().path = path;
//         return this;
//     }
// 
//     public MessageBuilder setResponseStatus(Integer status) {
//         exchange.response().status = status;
//         return this;
//     }
// 
//     public MessageBuilder setResponseBody(Object body) {
//         exchange.response().body = body;
//         return this;
//     }
//     
//     public MessageBuilder setRequestBody(Object body) {
//         exchange.request().body = body;
//         return this;
//     }
// 
//     public MessageBuilder addRequestParam(String name, String value) {
//         exchange.request().addParam(name, value);
//         return this;
//     }
// 
//     public MessageBuilder setRequestParam(String name, String value) {
//         exchange.request().setParam(name, value);
//         return this;
//     }
// 
//     public MessageBuilder setRequestHeader(String name, String value) {
//         exchange.request().setHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder addRequestHeader(String name, String value) {
//         exchange.request().addHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder setResponseHeader(String name, String value) {
//         exchange.response().setHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder addResponseHeader(String name, String value) {
//         exchange.response().addHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder stub() {
//         client.postMessage(exchange); 
//         return this;
//     }
// 
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//     
// }
// 
// 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 org.junit.Test;
import au.com.sensis.stubby.test.client.MessageBuilder;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.test.support.TestBase;
package au.com.sensis.stubby.test;




/*
 * When two identical request patterns are stubbed, the previous one should be deleted
 * and the new one inserted at the start of the list.
 */
public class DuplicateRequestPatternTest extends TestBase {

    private void assertSame(MessageBuilder... messages) {
        int status = 1; // use status code to identify requests
        for (MessageBuilder message : messages) {
            message.setResponseStatus(status).stub();

// Path: functional-test/src/main/java/au/com/sensis/stubby/test/client/MessageBuilder.java
// public class MessageBuilder {
// 
//     private Client client;
//     private JsonExchange exchange;
// 
//     public MessageBuilder(Client client) {
//         this.client = client;
//         this.exchange = new JsonExchange();
//     }
//  
//     public MessageBuilder setDelay(Long delay) {
//         exchange.delay = delay;
//         return this;
//     }
//     
//     public MessageBuilder setScript(String script) {
//         exchange.script = script;
//         return this;
//     }
//     
//     public MessageBuilder setRequestMethod(String method) {
//         exchange.request().method = method;
//         return this;
//     }
// 
//     public MessageBuilder setRequestPath(String path) {
//         exchange.request().path = path;
//         return this;
//     }
// 
//     public MessageBuilder setResponseStatus(Integer status) {
//         exchange.response().status = status;
//         return this;
//     }
// 
//     public MessageBuilder setResponseBody(Object body) {
//         exchange.response().body = body;
//         return this;
//     }
//     
//     public MessageBuilder setRequestBody(Object body) {
//         exchange.request().body = body;
//         return this;
//     }
// 
//     public MessageBuilder addRequestParam(String name, String value) {
//         exchange.request().addParam(name, value);
//         return this;
//     }
// 
//     public MessageBuilder setRequestParam(String name, String value) {
//         exchange.request().setParam(name, value);
//         return this;
//     }
// 
//     public MessageBuilder setRequestHeader(String name, String value) {
//         exchange.request().setHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder addRequestHeader(String name, String value) {
//         exchange.request().addHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder setResponseHeader(String name, String value) {
//         exchange.response().setHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder addResponseHeader(String name, String value) {
//         exchange.response().addHeader(name, value);
//         return this;
//     }
// 
//     public MessageBuilder stub() {
//         client.postMessage(exchange); 
//         return this;
//     }
// 
// }
// 
// Path: functional-test/src/main/java/au/com/sensis/stubby/test/model/JsonStubbedExchangeList.java
// @SuppressWarnings("serial")
// public class JsonStubbedExchangeList extends ArrayList<JsonStubbedExchange> {
//     
// }
// 
// 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/DuplicateRequestPatternTest.java
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import au.com.sensis.stubby.test.client.MessageBuilder;
import au.com.sensis.stubby.test.model.JsonStubbedExchangeList;
import au.com.sensis.stubby.test.support.TestBase;

package au.com.sensis.stubby.test;




/*
 * When two identical request patterns are stubbed, the previous one should be deleted
 * and the new one inserted at the start of the list.
 */
public class DuplicateRequestPatternTest extends TestBase {

    private void assertSame(MessageBuilder... messages) {
        int status = 1; // use status code to identify requests
        for (MessageBuilder message : messages) {
            message.setResponseStatus(status).stub();

            JsonStubbedExchangeList responses = responses();