HttpTestClient httpTestClient = HttpTestClient.withBaseUrl(baseUrl);
for (Map.Entry<String, String> cookie : when.getCookies().entrySet()) {
httpTestClient = httpTestClient.withCookie(cookie.getKey(), cookie.getValue());
}
HttpRequest httpRequest = httpTestClient.http(when.getMethod(), when.getPath());
ImmutableMap<String, String> cookies = when.getCookies();
if (!cookies.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (Map.Entry<String, String> entry : cookies.entrySet()) {
sb.append(entry.getKey()).append("=\"").append(entry.getValue().replace("\"", "\\\"")).append("\"; ");
}
sb.setLength(sb.length() - 2);
httpRequest.header("Cookie", sb.toString());
}
if (!Strings.isNullOrEmpty(when.getBody())) {
httpRequest.contentType("application/json");
httpRequest.send(when.getBody());
System.out.println(when.getBody());
}
System.out.println();
int code = httpRequest.code();
System.out.println("<< RESPONSE");
System.out.println(code);
System.out.println();
String body = httpRequest.body(Charsets.UTF_8.name());
System.out.println(body);
System.out.println();
assertThat(code).isEqualTo(when.getThen().getExpectedCode());
if (isJSON(when.getThen().getExpected())) {