Search in sources :

Example 21 with Response

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));
}
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) ContentChannel(com.yahoo.jdisc.handler.ContentChannel) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 22 with Response

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));
}
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) RequestFilter(com.yahoo.jdisc.http.filter.RequestFilter) Test(org.testng.annotations.Test)

Example 23 with Response

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"));
}
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)

Example 24 with Response

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());
}
Also used : Response(com.yahoo.jdisc.Response) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) Test(org.junit.Test)

Example 25 with Response

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());
}
Also used : Response(com.yahoo.jdisc.Response) ClientTestDriver(com.yahoo.messagebus.jdisc.test.ClientTestDriver) SimpleMessage(com.yahoo.messagebus.test.SimpleMessage) SimpleReply(com.yahoo.messagebus.test.SimpleReply) Test(org.junit.Test)

Aggregations

Response (com.yahoo.jdisc.Response)52 Test (org.junit.Test)39 Request (com.yahoo.jdisc.Request)17 SimpleMessage (com.yahoo.messagebus.test.SimpleMessage)14 ContainerBuilder (com.yahoo.jdisc.application.ContainerBuilder)11 ContentChannel (com.yahoo.jdisc.handler.ContentChannel)11 TestDriver (com.yahoo.jdisc.test.TestDriver)10 ClientTestDriver (com.yahoo.messagebus.jdisc.test.ClientTestDriver)7 ResponseHandler (com.yahoo.jdisc.handler.ResponseHandler)6 SimpleReply (com.yahoo.messagebus.test.SimpleReply)6 ByteBuffer (java.nio.ByteBuffer)6 ServerTestDriver (com.yahoo.messagebus.jdisc.test.ServerTestDriver)5 Chain (com.yahoo.component.chain.Chain)3 HttpRequest (com.yahoo.jdisc.http.HttpRequest)3 HttpResponse (com.yahoo.jdisc.http.HttpResponse)3 NonWorkingRequest (com.yahoo.jdisc.test.NonWorkingRequest)3 Reply (com.yahoo.messagebus.Reply)3 Processor (com.yahoo.processing.Processor)3 Callable (java.util.concurrent.Callable)3 Test (org.testng.annotations.Test)3