use of com.yahoo.jdisc.http.HttpRequest 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.http.HttpRequest in project vespa by vespa-engine.
the class FilterTestCase method requireThatRequestFilterChainCallsFilterWithOriginalRequest.
@Test
public void requireThatRequestFilterChainCallsFilterWithOriginalRequest() throws Exception {
final RequestFilter requestFilter = mock(RequestFilter.class);
final RequestFilter requestFilterChain = RequestFilterChain.newInstance(requestFilter);
final HttpRequest request = mock(HttpRequest.class);
final ResponseHandler responseHandler = null;
requestFilterChain.filter(request, responseHandler);
// Check that the filter is called with the same request argument as the chain was,
// in a manner that allows the request object to be wrapped.
final ArgumentCaptor<HttpRequest> requestCaptor = ArgumentCaptor.forClass(HttpRequest.class);
verify(requestFilter).filter(requestCaptor.capture(), any(ResponseHandler.class));
verify(request, never()).getUri();
requestCaptor.getValue().getUri();
verify(request, times(1)).getUri();
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testRemoveAttribute.
@Test
public void testRemoveAttribute() {
URI uri = URI.create("http://localhost:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
request.setAttribute("some_attr", "some_value");
Assert.assertEquals(request.containsAttribute("some_attr"), true);
request.removeAttribute("some_attr");
Assert.assertEquals(request.containsAttribute("some_attr"), false);
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testGetIntHeader.
@Test
public void testGetIntHeader() {
URI uri = URI.create("http://localhost:8080/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
Assert.assertEquals(-1, request.getIntHeader("int_header"));
request.addHeader("int_header", String.valueOf(5));
Assert.assertEquals(5, request.getIntHeader("int_header"));
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterRequestTest method testClearCookies.
@Test
public void testClearCookies() throws Exception {
URI uri = URI.create("http://example.yahoo.com/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
httpReq.headers().put(HttpHeaders.Names.COOKIE, "XYZ=value");
DiscFilterRequest request = new JdiscFilterRequest(httpReq);
request.clearCookies();
Assert.assertNull(request.getHeader(HttpHeaders.Names.COOKIE));
}
Aggregations