use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.
the class TestHttpRequestExecutor method testBasicExecution.
@Test
public void testBasicExecution() throws Exception {
final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
final HttpRequestExecutor executor = new HttpRequestExecutor();
final HttpCoreContext context = HttpCoreContext.create();
final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
executor.preProcess(request, httprocessor, context);
Mockito.verify(httprocessor).process(request, request.getEntity(), context);
Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(200, "OK"));
final ClassicHttpResponse response = executor.execute(request, conn, context);
Mockito.verify(conn).sendRequestHeader(request);
Mockito.verify(conn).flush();
Mockito.verify(conn).receiveResponseHeader();
Mockito.verify(conn).receiveResponseEntity(response);
executor.postProcess(response, httprocessor, context);
Mockito.verify(httprocessor).process(response, response.getEntity(), context);
Assertions.assertSame(request, context.getRequest());
Assertions.assertSame(response, context.getResponse());
}
use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.
the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequestWithExpectContinueFailure.
@Test
public void testExecutionEntityEnclosingRequestWithExpectContinueFailure() throws Exception {
final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
final HttpRequestExecutor executor = new HttpRequestExecutor();
final HttpCoreContext context = HttpCoreContext.create();
final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
final HttpEntity entity = Mockito.mock(HttpEntity.class);
request.setEntity(entity);
executor.preProcess(request, httprocessor, context);
Mockito.verify(httprocessor).process(request, request.getEntity(), context);
Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(402, "OK"));
Mockito.when(conn.isDataAvailable(ArgumentMatchers.any(Timeout.class))).thenReturn(Boolean.TRUE);
final ClassicHttpResponse response = executor.execute(request, conn, context);
Mockito.verify(conn).sendRequestHeader(request);
Mockito.verify(conn, Mockito.never()).sendRequestEntity(request);
Mockito.verify(conn).terminateRequest(request);
Mockito.verify(conn, Mockito.times(2)).flush();
Mockito.verify(conn).isDataAvailable(Timeout.ofMilliseconds(3000));
Mockito.verify(conn).receiveResponseHeader();
Mockito.verify(conn).receiveResponseEntity(response);
executor.postProcess(response, httprocessor, context);
Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.
the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequest.
@Test
public void testExecutionEntityEnclosingRequest() throws Exception {
final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
final HttpRequestExecutor executor = new HttpRequestExecutor();
final HttpCoreContext context = HttpCoreContext.create();
final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
final HttpEntity entity = Mockito.mock(HttpEntity.class);
request.setEntity(entity);
executor.preProcess(request, httprocessor, context);
Mockito.verify(httprocessor).process(request, request.getEntity(), context);
Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(200, "OK"));
final ClassicHttpResponse response = executor.execute(request, conn, context);
Mockito.verify(conn).sendRequestHeader(request);
Mockito.verify(conn).sendRequestEntity(request);
Mockito.verify(conn).flush();
Mockito.verify(conn).receiveResponseHeader();
Mockito.verify(conn).receiveResponseEntity(response);
executor.postProcess(response, httprocessor, context);
Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.
the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequestWithExpectContinueSuccess.
@Test
public void testExecutionEntityEnclosingRequestWithExpectContinueSuccess() throws Exception {
final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
final HttpRequestExecutor executor = new HttpRequestExecutor();
final HttpCoreContext context = HttpCoreContext.create();
final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
final HttpEntity entity = Mockito.mock(HttpEntity.class);
request.setEntity(entity);
executor.preProcess(request, httprocessor, context);
Mockito.verify(httprocessor).process(request, request.getEntity(), context);
Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(100, "Continue"), new BasicClassicHttpResponse(200, "OK"));
Mockito.when(conn.isDataAvailable(ArgumentMatchers.any(Timeout.class))).thenReturn(Boolean.TRUE);
final ClassicHttpResponse response = executor.execute(request, conn, context);
Mockito.verify(conn).sendRequestHeader(request);
Mockito.verify(conn).sendRequestEntity(request);
Mockito.verify(conn, Mockito.times(2)).flush();
Mockito.verify(conn).isDataAvailable(Timeout.ofMilliseconds(3000));
Mockito.verify(conn, Mockito.times(2)).receiveResponseHeader();
Mockito.verify(conn).receiveResponseEntity(response);
executor.postProcess(response, httprocessor, context);
Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
use of org.apache.hc.core5.http.protocol.HttpProcessor in project httpcomponents-core by apache.
the class TestHttpRequestExecutor method testExecutionEntityEnclosingRequestWithExpectContinueNoResponse.
@Test
public void testExecutionEntityEnclosingRequestWithExpectContinueNoResponse() throws Exception {
final HttpProcessor httprocessor = Mockito.mock(HttpProcessor.class);
final HttpClientConnection conn = Mockito.mock(HttpClientConnection.class);
final HttpRequestExecutor executor = new HttpRequestExecutor();
final HttpCoreContext context = HttpCoreContext.create();
final ClassicHttpRequest request = new BasicClassicHttpRequest(Method.POST, "/");
request.addHeader(HttpHeaders.EXPECT, HeaderElements.CONTINUE);
final HttpEntity entity = Mockito.mock(HttpEntity.class);
request.setEntity(entity);
executor.preProcess(request, httprocessor, context);
Mockito.verify(httprocessor).process(request, request.getEntity(), context);
Mockito.when(conn.receiveResponseHeader()).thenReturn(new BasicClassicHttpResponse(200, "OK"));
Mockito.when(conn.isDataAvailable(ArgumentMatchers.any(Timeout.class))).thenReturn(Boolean.FALSE);
final ClassicHttpResponse response = executor.execute(request, conn, context);
Mockito.verify(conn).sendRequestHeader(request);
Mockito.verify(conn).sendRequestEntity(request);
Mockito.verify(conn, Mockito.times(2)).flush();
Mockito.verify(conn).isDataAvailable(Timeout.ofMilliseconds(3000));
Mockito.verify(conn).receiveResponseHeader();
Mockito.verify(conn).receiveResponseEntity(response);
executor.postProcess(response, httprocessor, context);
Mockito.verify(httprocessor).process(response, response.getEntity(), context);
}
Aggregations