use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterResponseTest method testAddHeader.
@Test
public void testAddHeader() {
HttpRequest request = newRequest(URI.create("http://localhost:8080/echo"), HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterResponse response = new JdiscFilterResponse(HttpResponse.newInstance(HttpResponse.Status.OK));
response.addHeader("header1", "value1");
Assert.assertEquals(response.getHeader("header1"), "value1");
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterResponseTest method testAttributes.
@Test
public void testAttributes() {
HttpRequest request = newRequest(URI.create("http://localhost:8080/echo"), HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterResponse response = new JdiscFilterResponse(HttpResponse.newInstance(HttpResponse.Status.OK));
response.setAttribute("attr_1", "value1");
Assert.assertEquals(response.getAttribute("attr_1"), "value1");
List<String> list = Collections.list(response.getAttributeNames());
Assert.assertEquals(list.get(0), "attr_1");
response.removeAttribute("attr_1");
Assert.assertNull(response.getAttribute("attr_1"));
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterResponseTest method testGetSetStatus.
@Test
public void testGetSetStatus() {
HttpRequest request = newRequest(URI.create("http://localhost:8080/echo"), HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
DiscFilterResponse response = new JdiscFilterResponse(HttpResponse.newInstance(HttpResponse.Status.OK));
Assert.assertEquals(response.getStatus(), HttpResponse.Status.OK);
response.setStatus(HttpResponse.Status.REQUEST_TIMEOUT);
Assert.assertEquals(response.getStatus(), HttpResponse.Status.REQUEST_TIMEOUT);
}
use of com.yahoo.jdisc.http.HttpRequest in project vespa by vespa-engine.
the class DiscFilterResponseTest method testGetParentResponse.
@Test
public void testGetParentResponse() {
URI uri = URI.create("http://example.com/test");
HttpRequest httpReq = newRequest(uri, HttpRequest.Method.GET, HttpRequest.Version.HTTP_1_1);
HttpResponse httpResp = newResponse(httpReq, 200);
DiscFilterResponse response = new JdiscFilterResponse(httpResp);
Assert.assertSame(response.getParentResponse(), httpResp);
}
use of com.yahoo.jdisc.http.HttpRequest 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));
}
Aggregations