use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class ChannelPipelineFinalizerHandlerTest method finalizeChannelPipeline_does_not_add_idle_channel_timeout_handler_to_pipeline_if_workerChannelIdleTimeoutMillis_is_not_greater_than_0_or_idle_timeout_handler_already_exists.
@DataProvider(value = { "0 | false", "-42 | false", "42 | true" }, splitBy = "\\|")
@Test
public void finalizeChannelPipeline_does_not_add_idle_channel_timeout_handler_to_pipeline_if_workerChannelIdleTimeoutMillis_is_not_greater_than_0_or_idle_timeout_handler_already_exists(long timeoutVal, boolean idleTimeoutHandlerAlreadyExists) throws JsonProcessingException {
// given
Whitebox.setInternalState(handler, "workerChannelIdleTimeoutMillis", timeoutVal);
LastOutboundMessage msg = mock(LastOutboundMessage.class);
if (idleTimeoutHandlerAlreadyExists)
doReturn(mock(ChannelHandler.class)).when(pipelineMock).get(IDLE_CHANNEL_TIMEOUT_HANDLER_NAME);
// when
handler.finalizeChannelPipeline(ctxMock, msg, state, null);
// then
verify(pipelineMock, never()).addFirst(anyString(), anyObject());
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class RequestInfoSetterHandlerTest method doChannelRead_releases_content_and_returns_do_not_fire_when_state_is_null_or_response_already_sent.
@DataProvider(value = { "true | false", "false | true", "true | true" }, splitBy = "\\|")
@Test
public void doChannelRead_releases_content_and_returns_do_not_fire_when_state_is_null_or_response_already_sent(boolean stateIsNull, boolean responseAlreadySent) {
// given
if (stateIsNull)
doReturn(null).when(stateAttrMock).get();
if (responseAlreadySent) {
doReturn(true).when(stateMock).isResponseSendingLastChunkSent();
}
// when
PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, httpContentMock);
// then
verify(httpContentMock).release();
assertThat(result).isEqualTo(PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT);
}
use of com.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class ResponseFilterHandlerTest method doChannelRead_delegates_to_executeResponseFilters_and_returns_CONTINUE_if_msg_is_first_chunk_of_response.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void doChannelRead_delegates_to_executeResponseFilters_and_returns_CONTINUE_if_msg_is_first_chunk_of_response(boolean chunkedResponse) throws Exception {
// given
OutboundMessage msg = (chunkedResponse) ? mock(OutboundMessageSendHeadersChunkFromResponseInfo.class) : mock(LastOutboundMessageSendFullResponseInfo.class);
doNothing().when(handlerSpy).executeResponseFilters(any());
// when
PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
// then
assertThat(result).isEqualTo(CONTINUE);
verify(handlerSpy).executeResponseFilters(ctxMock);
}
use of com.tngtech.java.junit.dataprovider.DataProvider 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());
// 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), 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.tngtech.java.junit.dataprovider.DataProvider in project riposte by Nike-Inc.
the class RequestFilterHandlerTest method handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_non_short_circuiting_filters.
@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_requestInfo_returned_by_non_short_circuiting_filters(boolean isFirstChunk) {
// given
HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
RequestInfo<?> firstFilterResult = mock(RequestInfo.class);
RequestInfo<?> secondFilterResult = mock(RequestInfo.class);
doReturn(firstFilterResult).when(filter1Mock).filterRequestFirstChunkNoPayload(any(), any());
doReturn(firstFilterResult).when(filter1Mock).filterRequestLastChunkWithFullPayload(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.normalFilterCall, args.shortCircuitFilterCall);
// then
assertThat(result).isEqualTo(CONTINUE);
// First filter should have been passed the original request.
if (isFirstChunk)
verify(filter1Mock).filterRequestFirstChunkNoPayload(requestInfoMock, ctxMock);
else
verify(filter1Mock).filterRequestLastChunkWithFullPayload(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);
}
Aggregations