@Test public void sendShouldWrapHttpClientResponse() throws IOException { HttpResponse clientResponse = mock(HttpResponse.class); HttpEntity httpEntity = mock(HttpEntity.class); InputStream inputStream = mock(InputStream.class); StatusLine statusLine = new BasicStatusLine(mock(ProtocolVersion.class), 123, "reason"); Header contentType = new BasicHeader("somename", "contentType"); Header contentEncoding = new BasicHeader("somename", "contentEncoding"); when(httpEntity.getContent()).thenReturn(inputStream); when(client.execute(request)).thenReturn(clientResponse); HttpChannel.Response response = toTest.send(); assertNull(response.getContentType()); assertNull(response.getContentEncoding()); assertSame(EmptyInputStream.INSTANCE, response.getEntity()); when(clientResponse.getStatusLine()).thenReturn(statusLine); when(clientResponse.getFirstHeader("Content-Type")).thenReturn(contentType); when(clientResponse.getFirstHeader("Content-Encoding")).thenReturn(contentEncoding); when(clientResponse.getEntity()).thenReturn(httpEntity); assertSame(inputStream, response.getEntity()); assertEquals("contentType", response.getContentType()); assertEquals("contentEncoding", response.getContentEncoding()); assertEquals(123, response.getStatusCode()); assertEquals("reason", response.getStatusMessage()); response.close(); verify(httpEntity).consumeContent(); verify(request).abort(); }
public Response send() throws IOException { return new HttpClientResponse(request, client.execute(request)); }
HttpClientHttpChannel implements HttpChannel { public Response send() throws IOException { return new HttpClientResponse(request, client.execute(request)); } }
HttpClientHttpChannel implements HttpChannel { public Response send() throws IOException { return new HttpClientResponse(request, client.execute(request)); } HttpClientHttpChannel(HttpClient client, HttpUriRequest request); }
HttpClientHttpChannel implements HttpChannel { public Response send() throws IOException { return new HttpClientResponse(request, client.execute(request)); } HttpClientHttpChannel(HttpClient client, HttpUriRequest request); void setConnectionTimeout(int timeout); void setSocketTimeout(int timeout); void setHeader(String name, String value); void addHeader(String name, String value); void setContentType(String value); void setAccept(String value); void writeEntityWith(HttpEntityWriter httpEntityWriter); Response send(); }
HttpClientHttpChannel implements HttpChannel { public Response send() throws IOException { return new HttpClientResponse(request, client.execute(request)); } HttpClientHttpChannel(HttpClient client, HttpUriRequest request); void setConnectionTimeout(int timeout); void setSocketTimeout(int timeout); void setHeader(String name, String value); void addHeader(String name, String value); void setContentType(String value); void setAccept(String value); void writeEntityWith(HttpEntityWriter httpEntityWriter); Response send();  }