// Path: javabank-core/src/main/java/org/mbtest/javabank/http/imposters/Imposter.java
// public class Imposter extends HashMap {
//     private static final String PORT = "port";
//     private static final String PROTOCOL = "protocol";
//     private static final String STUBS = "stubs";
// 
//     public Imposter() {
//         this.put(PROTOCOL, "http");
//         this.put(STUBS, newArrayList());
//     }
// 
//     public static Imposter fromJSON(JSONObject json) {
//         Imposter imposter = new Imposter();
//         imposter.putAll(json);
// 
//         return imposter;
//     }
// 
//     public static Imposter anImposter() {
//         return new Imposter();
//     }
// 
//     public Imposter onPort(int port) {
//         this.put(PORT, port);
//         return this;
//     }
// 
//     public Imposter addStub(Stub stub) {
//         getStubs().add(stub);
//         return this;
//     }
// 
//     public Imposter withStub(Stub stub) {
//         this.remove(STUBS);
//         this.put(STUBS, newArrayList());
//         addStub(stub);
//         return this;
//     }
// 
//     public List<Stub> getStubs() {
//         return ((List) get(STUBS));
//     }
// 
//     public Stub getStub(int index) {
//         return getStubs().get(index);
//     }
// 
//     public JSONObject toJSON() {
//         return new JSONObject(this);
//     }
// 
//     public String toString() {
//         return toJSON().toJSONString();
//     }
// 
//     public int getPort() {
//         return Integer.valueOf(String.valueOf(get(PORT)));
//     }
// }


import org.json.JSONArray;
import org.json.simple.parser.ParseException;
import org.mbtest.javabank.http.imposters.Imposter;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
    public Client(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public Client(String host, int port) {
        this.baseUrl = String.format("http://%s:%d", host, port);
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public boolean isMountebankRunning() {
        try {
            HttpResponse<JsonNode> response = Unirest.get(baseUrl).asJson();
            return response.getStatus() == 200;
        } catch (UnirestException e) {
            return false;
        }
    }

    public boolean isMountebankAllowingInjection() {
        try {
            HttpResponse<JsonNode> response = Unirest.get(baseUrl + "/config").asJson();
            return response.getBody().getObject().getJSONObject("options").getBoolean("allowInjection");
        } catch (UnirestException e) {
            return false;
        }
    }

// Path: javabank-core/src/main/java/org/mbtest/javabank/http/imposters/Imposter.java
// public class Imposter extends HashMap {
//     private static final String PORT = "port";
//     private static final String PROTOCOL = "protocol";
//     private static final String STUBS = "stubs";
// 
//     public Imposter() {
//         this.put(PROTOCOL, "http");
//         this.put(STUBS, newArrayList());
//     }
// 
//     public static Imposter fromJSON(JSONObject json) {
//         Imposter imposter = new Imposter();
//         imposter.putAll(json);
// 
//         return imposter;
//     }
// 
//     public static Imposter anImposter() {
//         return new Imposter();
//     }
// 
//     public Imposter onPort(int port) {
//         this.put(PORT, port);
//         return this;
//     }
// 
//     public Imposter addStub(Stub stub) {
//         getStubs().add(stub);
//         return this;
//     }
// 
//     public Imposter withStub(Stub stub) {
//         this.remove(STUBS);
//         this.put(STUBS, newArrayList());
//         addStub(stub);
//         return this;
//     }
// 
//     public List<Stub> getStubs() {
//         return ((List) get(STUBS));
//     }
// 
//     public Stub getStub(int index) {
//         return getStubs().get(index);
//     }
// 
//     public JSONObject toJSON() {
//         return new JSONObject(this);
//     }
// 
//     public String toString() {
//         return toJSON().toJSONString();
//     }
// 
//     public int getPort() {
//         return Integer.valueOf(String.valueOf(get(PORT)));
//     }
// }


// Path: javabank-client/src/main/java/org/mbtest/javabank/Client.java
import org.json.JSONArray;
import org.json.simple.parser.ParseException;
import org.mbtest.javabank.http.imposters.Imposter;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

    public Client(String baseUrl) {
        this.baseUrl = baseUrl;
    }

    public Client(String host, int port) {
        this.baseUrl = String.format("http://%s:%d", host, port);
    }

    public String getBaseUrl() {
        return baseUrl;
    }

    public boolean isMountebankRunning() {
        try {
            HttpResponse<JsonNode> response = Unirest.get(baseUrl).asJson();
            return response.getStatus() == 200;
        } catch (UnirestException e) {
            return false;
        }
    }

    public boolean isMountebankAllowingInjection() {
        try {
            HttpResponse<JsonNode> response = Unirest.get(baseUrl + "/config").asJson();
            return response.getBody().getObject().getJSONObject("options").getBoolean("allowInjection");
        } catch (UnirestException e) {
            return false;
        }
    }

    public int createImposter(Imposter imposter) {