Search in sources :

Example 1 with BindingRepository

use of com.yahoo.jdisc.application.BindingRepository in project vespa by vespa-engine.

the class FilterTestCase method requireThatResponseFilterIsRunOnBoundPath.

@Test
public void requireThatResponseFilterIsRunOnBoundPath() throws Exception {
    final ResponseFilter filter = mock(ResponseFilterMockBase.class);
    final BindingRepository<RequestFilter> requestFilters = null;
    final BindingRepository<ResponseFilter> responseFilters = new BindingRepository<>();
    responseFilters.bind("http://*/filtered/*", filter);
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("/filtered/status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    verify(filter, times(1)).filter(any(Response.class), any(Request.class));
    assertThat(testDriver.close(), is(true));
}
Also used : HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 2 with BindingRepository

use of com.yahoo.jdisc.application.BindingRepository in project vespa by vespa-engine.

the class FilterTestCase method requireThatRequestFilterIsRunOnBoundPath.

@Test
public void requireThatRequestFilterIsRunOnBoundPath() throws Exception {
    final RequestFilter filter = mock(RequestFilterMockBase.class);
    final BindingRepository<RequestFilter> requestFilters = new BindingRepository<>();
    requestFilters.bind("http://*/filtered/*", filter);
    final BindingRepository<ResponseFilter> responseFilters = null;
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("/filtered/status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    verify(filter, times(1)).filter(any(HttpRequest.class), any(ResponseHandler.class));
    assertThat(testDriver.close(), is(true));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 3 with BindingRepository

use of com.yahoo.jdisc.application.BindingRepository in project vespa by vespa-engine.

the class FilterTestCase method requireThatRequestFilterAndResponseFilterCanBindToSamePath.

@Test
public void requireThatRequestFilterAndResponseFilterCanBindToSamePath() throws Exception {
    final String uriPattern = "http://*/*";
    final BindingRepository<RequestFilter> requestFilters = new BindingRepository<>();
    final RequestFilter requestFilter = mock(RequestFilterMockBase.class);
    requestFilters.bind(uriPattern, requestFilter);
    final BindingRepository<ResponseFilter> responseFilters = new BindingRepository<>();
    final ResponseFilter responseFilter = mock(ResponseFilterMockBase.class);
    responseFilters.bind(uriPattern, responseFilter);
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("/status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    verify(requestFilter, times(1)).filter(any(HttpRequest.class), any(ResponseHandler.class));
    verify(responseFilter, times(1)).filter(any(Response.class), any(Request.class));
    assertThat(testDriver.close(), is(true));
}
Also used : HttpRequest(com.yahoo.jdisc.http.HttpRequest) HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) ResponseHandler(com.yahoo.jdisc.handler.ResponseHandler) BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 4 with BindingRepository

use of com.yahoo.jdisc.application.BindingRepository in project vespa by vespa-engine.

the class FilterTestCase method requireThatRequestFilterChangesAreSeenByRequestHandler.

@Test
public void requireThatRequestFilterChangesAreSeenByRequestHandler() throws Exception {
    final RequestFilter filter = new HeaderRequestFilter("foo", "bar");
    final BindingRepository<RequestFilter> requestFilters = new BindingRepository<>();
    requestFilters.bind("http://*/*", filter);
    final BindingRepository<ResponseFilter> responseFilters = null;
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    assertThat(requestHandler.getHeaderMap().get("foo").get(0), is("bar"));
    assertThat(testDriver.close(), is(true));
}
Also used : BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 5 with BindingRepository

use of com.yahoo.jdisc.application.BindingRepository in project vespa by vespa-engine.

the class FilterTestCase method requireThatResponseFilterIsNotRunOnUnboundPath.

@Test
public void requireThatResponseFilterIsNotRunOnUnboundPath() throws Exception {
    final ResponseFilter filter = mock(ResponseFilterMockBase.class);
    final BindingRepository<RequestFilter> requestFilters = null;
    final BindingRepository<ResponseFilter> responseFilters = new BindingRepository<>();
    responseFilters.bind("http://*/filtered/*", filter);
    final MyRequestHandler requestHandler = new MyRequestHandler();
    final TestDriver testDriver = newDriver(requestHandler, requestFilters, responseFilters);
    testDriver.client().get("/status.html");
    assertThat(requestHandler.awaitInvocation(), is(true));
    verify(filter, never()).filter(any(Response.class), any(Request.class));
    assertThat(testDriver.close(), is(true));
}
Also used : HttpResponse(com.yahoo.jdisc.http.HttpResponse) Response(com.yahoo.jdisc.Response) BindingRepository(com.yahoo.jdisc.application.BindingRepository) ResponseFilter(com.yahoo.jdisc.http.filter.ResponseFilter) HttpRequest(com.yahoo.jdisc.http.HttpRequest) Request(com.yahoo.jdisc.Request) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Aggregations

BindingRepository (com.yahoo.jdisc.application.BindingRepository)6 RequestFilter (com.yahoo.jdisc.http.filter.RequestFilter)6 ResponseFilter (com.yahoo.jdisc.http.filter.ResponseFilter)6 Test (org.testng.annotations.Test)6 HttpRequest (com.yahoo.jdisc.http.HttpRequest)5 Request (com.yahoo.jdisc.Request)3 Response (com.yahoo.jdisc.Response)3 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)3 HttpResponse (com.yahoo.jdisc.http.HttpResponse)3