@Test
public void testExecutionEntityEclosingRequestCustomExpectationVerifier() throws Exception {
final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
final ConnectionReuseStrategy connReuseStrategy = Mockito.mock(ConnectionReuseStrategy.class);
final HttpResponseFactory responseFactory = Mockito.mock(HttpResponseFactory.class);
final HttpRequestHandlerMapper handlerResolver = Mockito.mock(HttpRequestHandlerMapper.class);
final HttpExpectationVerifier expectationVerifier = new HttpExpectationVerifier() {
public void verify(
final HttpRequest request,
final HttpResponse response,
final HttpContext context) throws HttpException {
response.setStatusCode(HttpStatus.SC_UNAUTHORIZED);
}
};
final HttpService httpservice = new HttpService(
httprocessor,
connReuseStrategy,
responseFactory,
handlerResolver,
expectationVerifier);
final HttpCoreContext context = HttpCoreContext.create();
final HttpServerConnection conn = Mockito.mock(HttpServerConnection.class);
final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
request.addHeader(HTTP.EXPECT_DIRECTIVE, HTTP.EXPECT_CONTINUE);
final InputStream instream = Mockito.mock(InputStream.class);
final InputStreamEntity entity = new InputStreamEntity(instream, -1);
request.setEntity(entity);
Mockito.when(conn.receiveRequestHeader()).thenReturn(request);
final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 100, "Continue");
Mockito.when(responseFactory.newHttpResponse(HttpVersion.HTTP_1_1, 100, context)).thenReturn(response);
Mockito.when(connReuseStrategy.keepAlive(response, context)).thenReturn(Boolean.FALSE);
httpservice.handleRequest(conn, context);
Assert.assertSame(conn, context.getConnection());