Search in sources :

Example 16 with DataProvider

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());
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 17 with DataProvider

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);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 18 with DataProvider

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);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) OutboundMessageSendHeadersChunkFromResponseInfo(com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo) OutboundMessage(com.nike.riposte.server.channelpipeline.message.OutboundMessage) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 19 with DataProvider

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);
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) BiFunction(java.util.function.BiFunction) RequestAndResponseFilter(com.nike.riposte.server.http.filter.RequestAndResponseFilter) RequestInfo(com.nike.riposte.server.http.RequestInfo) Pair(com.nike.internal.util.Pair) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 20 with DataProvider

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);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)88 Test (org.junit.Test)85 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)20 Span (com.nike.wingtips.Span)19 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)19 Matchers.anyString (org.mockito.Matchers.anyString)11 HttpMethod (io.netty.handler.codec.http.HttpMethod)9 Endpoint (com.nike.riposte.server.http.Endpoint)8 Timer (com.codahale.metrics.Timer)7 StandardEndpoint (com.nike.riposte.server.http.StandardEndpoint)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 RequestInfo (com.nike.riposte.server.http.RequestInfo)5 Charset (java.nio.charset.Charset)5 CompletableFuture (java.util.concurrent.CompletableFuture)5 Meter (com.codahale.metrics.Meter)4 Response (com.ning.http.client.Response)4 ExtractableResponse (io.restassured.response.ExtractableResponse)4 Deque (java.util.Deque)4 Optional (java.util.Optional)4