use of com.amazonaws.http.apache.client.impl.ConnectionManagerAwareHttpClient in project aws-xray-sdk-java by aws.
the class TracingHandlerTest method mockHttpClient.
private void mockHttpClient(Object client, String responseContent) {
AmazonHttpClient amazonHttpClient = new AmazonHttpClient(new ClientConfiguration());
ConnectionManagerAwareHttpClient apacheHttpClient = Mockito.mock(ConnectionManagerAwareHttpClient.class);
HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
BasicHttpEntity responseBody = new BasicHttpEntity();
InputStream in = EmptyInputStream.INSTANCE;
if (null != responseContent && !responseContent.isEmpty()) {
in = new ByteArrayInputStream(responseContent.getBytes(StandardCharsets.UTF_8));
}
responseBody.setContent(in);
httpResponse.setEntity(responseBody);
try {
Mockito.doReturn(httpResponse).when(apacheHttpClient).execute(Mockito.any(HttpUriRequest.class), Mockito.any(HttpContext.class));
} catch (IOException e) {
// Ignore
}
Whitebox.setInternalState(amazonHttpClient, "httpClient", apacheHttpClient);
Whitebox.setInternalState(client, "client", amazonHttpClient);
}
Aggregations