Search in sources :

Example 1 with ConnectionManagerAwareHttpClient

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);
}
Also used : HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) EmptyInputStream(org.apache.http.impl.io.EmptyInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) AmazonHttpClient(com.amazonaws.http.AmazonHttpClient) HttpContext(org.apache.http.protocol.HttpContext) BasicHttpResponse(org.apache.http.message.BasicHttpResponse) HttpResponse(org.apache.http.HttpResponse) BasicHttpEntity(org.apache.http.entity.BasicHttpEntity) IOException(java.io.IOException) ConnectionManagerAwareHttpClient(com.amazonaws.http.apache.client.impl.ConnectionManagerAwareHttpClient) ClientConfiguration(com.amazonaws.ClientConfiguration) BasicStatusLine(org.apache.http.message.BasicStatusLine)

Aggregations

ClientConfiguration (com.amazonaws.ClientConfiguration)1 AmazonHttpClient (com.amazonaws.http.AmazonHttpClient)1 ConnectionManagerAwareHttpClient (com.amazonaws.http.apache.client.impl.ConnectionManagerAwareHttpClient)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpResponse (org.apache.http.HttpResponse)1 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)1 BasicHttpEntity (org.apache.http.entity.BasicHttpEntity)1 EmptyInputStream (org.apache.http.impl.io.EmptyInputStream)1 BasicHttpResponse (org.apache.http.message.BasicHttpResponse)1 BasicStatusLine (org.apache.http.message.BasicStatusLine)1 HttpContext (org.apache.http.protocol.HttpContext)1