use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method doChannelRead_delegates_to_handleFilterLogic_with_last_chunk_method_references_when_msg_is_LastHttpContent.
@DataProvider(value = { "CONTINUE", "DO_NOT_FIRE_CONTINUE_EVENT" }, splitBy = "\\|")
@Test
public void doChannelRead_delegates_to_handleFilterLogic_with_last_chunk_method_references_when_msg_is_LastHttpContent(PipelineContinuationBehavior expectedPipelineContinuationBehavior) throws Exception {
// given
doReturn(expectedPipelineContinuationBehavior).when(handlerSpy).handleFilterLogic(any(), any(), any(), any(), any());
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, lastChunkMsgMock);
// then
assertThat(result).isEqualTo(expectedPipelineContinuationBehavior);
ArgumentCaptor<BiFunction> normalFilterCallCaptor = ArgumentCaptor.forClass(BiFunction.class);
ArgumentCaptor<BiFunction> shortCircuitFilterCallCaptor = ArgumentCaptor.forClass(BiFunction.class);
verify(handlerSpy).handleFilterLogic(eq(ctxMock), eq(lastChunkMsgMock), eq(state), normalFilterCallCaptor.capture(), shortCircuitFilterCallCaptor.capture());
BiFunction<RequestAndResponseFilter, RequestInfo, RequestInfo> normalFilterCall = normalFilterCallCaptor.getValue();
BiFunction<RequestAndResponseFilter, RequestInfo, Pair<RequestInfo, Optional<ResponseInfo<?>>>> shortCircuitFilterCall = shortCircuitFilterCallCaptor.getValue();
RequestAndResponseFilter filterForNormalCallMock = mock(RequestAndResponseFilter.class);
normalFilterCall.apply(filterForNormalCallMock, requestInfoMock);
verify(filterForNormalCallMock).filterRequestLastChunkWithFullPayload(requestInfoMock, ctxMock);
RequestAndResponseFilter filterForShortCircuitCallMock = mock(RequestAndResponseFilter.class);
shortCircuitFilterCall.apply(filterForShortCircuitCallMock, requestInfoMock);
verify(filterForShortCircuitCallMock).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_short_circuits_as_expected_if_filter_returns_valid_response.
@DataProvider(value = { "true | 0 | true", "true | 0 | false", "true | 1 | true", "true | 1 | false", "false | 0 | true", "false | 0 | false", "false | 1 | true", "false | 1 | false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_short_circuits_as_expected_if_filter_returns_valid_response(boolean isFirstChunk, int shortCircuitingFilterIndex, boolean filterReturnsModifiedRequestInfo) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
RequestAndResponseFilter shortCircuitingFilter = filtersList.get(shortCircuitingFilterIndex);
doReturn(true).when(shortCircuitingFilter).isShortCircuitRequestFilter();
RequestInfo<?> modifiedRequestInfoMock = mock(RequestInfo.class);
RequestInfo<?> returnedRequestInfo = (filterReturnsModifiedRequestInfo) ? modifiedRequestInfoMock : null;
ResponseInfo<?> returnedResponseInfoMock = mock(ResponseInfo.class);
doReturn(Pair.of(returnedRequestInfo, Optional.of(returnedResponseInfoMock))).when(shortCircuitingFilter).filterRequestFirstChunkWithOptionalShortCircuitResponse(any(), any());
doReturn(Pair.of(returnedRequestInfo, Optional.of(returnedResponseInfoMock))).when(shortCircuitingFilter).filterRequestLastChunkWithOptionalShortCircuitResponse(any(), any());
// when
PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.httpState, args.normalFilterCall, args.shortCircuitFilterCall);
// then
// Pipeline stops for the given msg event.
assertThat(result).isEqualTo(DO_NOT_FIRE_CONTINUE_EVENT);
// The filter's short-circuit-capable method was called.
if (isFirstChunk)
verify(shortCircuitingFilter).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
else
verify(shortCircuitingFilter).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
// The state is updated with the correct RequestInfo depending on what the filter returned.
if (filterReturnsModifiedRequestInfo)
assertThat(state.getRequestInfo()).isSameAs(modifiedRequestInfoMock);
else
assertThat(state.getRequestInfo()).isSameAs(requestInfoMock);
// The state is updated with the ResponseInfo returned by the filter.
assertThat(state.getResponseInfo()).isSameAs(returnedResponseInfoMock);
// The short circuiting "we're all done, return the response to the caller" event is fired down the pipeline.
verify(ctxMock).fireChannelRead(LastOutboundMessageSendFullResponseInfo.INSTANCE);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RoutingHandlerTest method doChannelRead_does_nothing_if_msg_is_not_HttpRequest.
@Test
public void doChannelRead_does_nothing_if_msg_is_not_HttpRequest() {
// given
String pathTemplate = "/some/path/with/{id}";
Collection<String> pathTemplates = new ArrayList<String>() {
{
add(pathTemplate);
}
};
doReturn(pathTemplates).when(matcherMock).matchingPathTemplates();
HttpObject msg = mock(HttpObject.class);
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
// then
verify(handlerSpy).doChannelRead(ctxMock, msg);
verifyNoMoreInteractions(handlerSpy);
verifyNoMoreInteractions(requestInfoMock);
verifyNoMoreInteractions(stateMock);
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestContentValidationHandlerTest method doChannelRead_does_nothing_if_endpoint_does_not_want_to_validate.
@Test
public void doChannelRead_does_nothing_if_endpoint_does_not_want_to_validate() throws Exception {
// given
doReturn(false).when(endpointMock).isValidateRequestContent(any());
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
// then
verifyNoMoreInteractions(requestValidatorMock);
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestContentValidationHandlerTest method doChannelRead_calls_request_getContent_method_if_endpoint_wants_validation.
@Test
public void doChannelRead_calls_request_getContent_method_if_endpoint_wants_validation() throws Exception {
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
// then
verify(requestInfoMock).getContent();
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Aggregations