use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class FilterTestCase method requireThatRequestFilterCanTerminateChain.
@Test
public void requireThatRequestFilterCanTerminateChain() throws Exception {
final RequestFilter requestFilter1 = new RespondForbiddenFilter();
final RequestFilter requestFilter2 = mock(RequestFilter.class);
final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter1, requestFilter2);
final HttpRequest request = null;
final ResponseHandler responseHandler = mock(ResponseHandler.class);
when(responseHandler.handleResponse(any(Response.class))).thenReturn(mock(ContentChannel.class));
requestFilterChain.filter(request, responseHandler);
verify(requestFilter2, never()).filter(any(HttpRequest.class), any(ResponseHandler.class));
final ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
verify(responseHandler).handleResponse(responseCaptor.capture());
assertThat(responseCaptor.getValue().getStatus(), is(Response.Status.FORBIDDEN));
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class FilterTestCase method requireThatRequestFilterChainCallsFilterWithOriginalResponseHandler.
@Test
public void requireThatRequestFilterChainCallsFilterWithOriginalResponseHandler() throws Exception {
final RequestFilter requestFilter = mock(RequestFilter.class);
final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter);
final HttpRequest request = null;
final ResponseHandler responseHandler = mock(ResponseHandler.class);
requestFilterChain.filter(request, responseHandler);
// Check that the filter is called with the same response handler argument as the chain was,
// in a manner that allows the handler object to be wrapped.
final ArgumentCaptor<ResponseHandler> responseHandlerCaptor = ArgumentCaptor.forClass(ResponseHandler.class);
verify(requestFilter).filter(any(HttpRequest.class), responseHandlerCaptor.capture());
verify(responseHandler, never()).handleResponse(any(Response.class));
responseHandlerCaptor.getValue().handleResponse(mock(Response.class));
verify(responseHandler, times(1)).handleResponse(any(Response.class));
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class FilterTestCase method requireThatResponseFilterChainIsRun.
@Test
public void requireThatResponseFilterChainIsRun() {
final ResponseFilter responseFilter1 = new ResponseHeaderFilter("foo", "bar");
final ResponseFilter responseFilter2 = mock(ResponseFilter.class);
final int statusCode = Response.Status.BAD_GATEWAY;
final Response response = new Response(statusCode);
final Request request = null;
ResponseFilterChain.newInstance(responseFilter1, responseFilter2).filter(response, request);
final ArgumentCaptor<Response> responseCaptor = ArgumentCaptor.forClass(Response.class);
verify(responseFilter2).filter(responseCaptor.capture(), any(Request.class));
assertThat(responseCaptor.getValue().getStatus(), is(statusCode));
assertThat(responseCaptor.getValue().headers().getFirst("foo"), is("bar"));
assertThat(response.getStatus(), is(statusCode));
assertThat(response.headers().getFirst("foo"), is("bar"));
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class MbusClientTestCase method requireThatRequestResponseWorks.
@Test
public void requireThatRequestResponseWorks() {
ClientTestDriver driver = ClientTestDriver.newInstance();
MyResponseHandler responseHandler = MyResponseHandler.newInstance();
assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
Response response = responseHandler.awaitResponse();
assertNotNull(response);
assertEquals(Response.Status.OK, response.getStatus());
assertTrue(driver.close());
}
use of com.yahoo.jdisc.Response in project vespa by vespa-engine.
the class MbusClientTestCase method requireThatResponseIsMbus.
@Test
public void requireThatResponseIsMbus() {
ClientTestDriver driver = ClientTestDriver.newInstance();
MyResponseHandler responseHandler = MyResponseHandler.newInstance();
assertTrue(driver.sendMessage(new SimpleMessage("foo"), responseHandler));
assertTrue(driver.awaitMessageAndSendReply(new EmptyReply()));
Response response = responseHandler.awaitResponse();
assertTrue(response instanceof MbusResponse);
Reply reply = ((MbusResponse) response).getReply();
assertTrue(reply instanceof EmptyReply);
assertTrue(driver.close());
}
Aggregations