Search in sources :

Example 1 with ResponseHeaderFilter

use of com.yahoo.jdisc.http.filter.ResponseHeaderFilter 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"));
}
Also used : HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request) ResponseHeaderFilter(com.yahoo.jdisc.http.filter.ResponseHeaderFilter) Test(org.testng.annotations.Test)

Aggregations

Request (com.yahoo.jdisc.Request)1 Response (com.yahoo.jdisc.Response)1 HttpRequest (com.yahoo.jdisc.http.HttpRequest)1 HttpResponse (com.yahoo.jdisc.http.HttpResponse)1 ResponseFilter (com.yahoo.jdisc.http.filter.ResponseFilter)1 ResponseHeaderFilter (com.yahoo.jdisc.http.filter.ResponseHeaderFilter)1 Test (org.testng.annotations.Test)1