use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestContentDeserializerHandlerTest method doChannelRead_uses_default_deserializer_if_custom_endpoint_one_is_null.
@Test
public void doChannelRead_uses_default_deserializer_if_custom_endpoint_one_is_null() throws Exception {
// given
doReturn(null).when(endpointMock).customRequestContentDeserializer(any());
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
// then
verify(requestInfoSpy).setupContentDeserializer(defaultHandlerDeserializerMock, contentTypeRef);
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestContentDeserializerHandlerTest method doChannelRead_does_nothing_if_endpoint_is_null.
@Test
public void doChannelRead_does_nothing_if_endpoint_is_null() throws Exception {
// given
doReturn(null).when(stateMock).getEndpointForExecution();
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
// then
verify(stateMock).getEndpointForExecution();
verify(stateMock).getRequestInfo();
verifyNoMoreInteractions(stateMock);
verifyNoMoreInteractions(endpointMock);
verifyNoMoreInteractions(requestInfoSpy);
assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_not_short_circuiting_and_return_null.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_not_short_circuiting_and_return_null(boolean isFirstChunk) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
filtersList.forEach(filter -> doReturn(false).when(filter).isShortCircuitRequestFilter());
// when
PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.httpState, args.normalFilterCall, args.shortCircuitFilterCall);
// then
assertThat(result).isEqualTo(CONTINUE);
filtersList.forEach(filter -> {
if (isFirstChunk)
verify(filter).filterRequestFirstChunkNoPayload(requestInfoMock, ctxMock);
else
verify(filter).filterRequestLastChunkWithFullPayload(requestInfoMock, ctxMock);
});
assertThat(state.getRequestInfo()).isSameAs(requestInfoMock);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_filters_when_filters_are_mixed_type_and_do_not_short_circuit.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_filters_when_filters_are_mixed_type_and_do_not_short_circuit(boolean isFirstChunk) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
doReturn(true).when(filtersList.get(0)).isShortCircuitRequestFilter();
doReturn(false).when(filtersList.get(1)).isShortCircuitRequestFilter();
RequestInfo<?> firstFilterResult = mock(RequestInfo.class);
RequestInfo<?> secondFilterResult = mock(RequestInfo.class);
// Do a mix of empty Optional vs null for the response to hit branch coverage (both indicate no short circuiting response)
doReturn(Pair.of(firstFilterResult, Optional.empty())).when(filter1Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(any(), any());
doReturn(Pair.of(firstFilterResult, null)).when(filter1Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(any(), any());
doReturn(secondFilterResult).when(filter2Mock).filterRequestFirstChunkNoPayload(any(), any());
doReturn(secondFilterResult).when(filter2Mock).filterRequestLastChunkWithFullPayload(any(), any());
// when
PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.httpState, args.normalFilterCall, args.shortCircuitFilterCall);
// then
assertThat(result).isEqualTo(CONTINUE);
// First filter should have been passed the original request.
if (isFirstChunk)
verify(filter1Mock).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
else
verify(filter1Mock).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
// Second filter should have been passed the result of the first filter.
if (isFirstChunk)
verify(filter2Mock).filterRequestFirstChunkNoPayload(firstFilterResult, ctxMock);
else
verify(filter2Mock).filterRequestLastChunkWithFullPayload(firstFilterResult, ctxMock);
// The state should have been updated with the result of the second filter.
assertThat(state.getRequestInfo()).isSameAs(secondFilterResult);
}
use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_short_circuiting_and_return_null.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_short_circuiting_and_return_null(boolean isFirstChunk) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
filtersList.forEach(filter -> doReturn(true).when(filter).isShortCircuitRequestFilter());
// when
PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.httpState, args.normalFilterCall, args.shortCircuitFilterCall);
// then
assertThat(result).isEqualTo(CONTINUE);
filtersList.forEach(filter -> {
if (isFirstChunk)
verify(filter).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
else
verify(filter).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
});
assertThat(state.getRequestInfo()).isSameAs(requestInfoMock);
}
Aggregations