@Test(timeout = 60000)
@DirtiesContext
public void testCreateReport_ForwardHttpRequests() throws Exception {
final String geotiffURL = "http://server.com/sampleGeoTiff.tif";
final MockClientHttpRequest request = new MockClientHttpRequest();
ClientHttpResponse response = new MockClientHttpResponse(Files.toByteArray(getFile("sampleGeoTiff.tif")), HttpStatus.OK);
request.setResponse(response);
requestFactory.registerHandler(new Predicate<URI>() {
@Override
public boolean apply(@Nullable URI input) {
return input != null && input.toString().equals(geotiffURL);
}
}, new TestHttpClientFactory.Handler() {
@Override
public MockClientHttpRequest handleRequest(URI uri, HttpMethod httpMethod) throws IOException, Exception {
return request;
}
});
doCreateAndPollAndGetReport(new Function<MockHttpServletRequest, MockHttpServletResponse>() {
@Nullable
@Override
public MockHttpServletResponse apply(@Nullable MockHttpServletRequest servletCreateRequest) {
try {
final MockHttpServletResponse servletCreateResponse = new MockHttpServletResponse();
servletCreateRequest.addHeader("Cookies", "CookieValue");
servletCreateRequest.addHeader("Cookies", "CookieValue2");
servletCreateRequest.addHeader("Header2", "h2");
JSONObject rawRequestData = new JSONObject(loadRequestDataAsString());
rawRequestData.getJSONObject("attributes").getJSONObject("imageMap").getJSONArray("layers").getJSONObject(0).
put("url", geotiffURL);
String requestData = rawRequestData.toString(2);
servlet.createReport("png", requestData, servletCreateRequest, servletCreateResponse);
return servletCreateResponse;
} catch (Exception e) {
throw new AssertionError(e);
}
}
}, false);
assertEquals(1, request.getHeaders().size());
assertArrayEquals(new Object[]{"CookieValue", "CookieValue2"}, request.getHeaders().get("Cookies").toArray());
}