Search in sources :

Example 86 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestContentDeserializerHandlerTest method doChannelRead_does_nothing_if_requestContentType_is_null.

@Test
public void doChannelRead_does_nothing_if_requestContentType_is_null() throws Exception {
    // given
    doReturn(null).when(endpointMock).requestContentType();
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
    // then
    verify(stateMock).getEndpointForExecution();
    verify(stateMock).getRequestInfo();
    verifyNoMoreInteractions(stateMock);
    verify(endpointMock).requestContentType();
    verify(requestInfoSpy).isCompleteRequestWithAllChunks();
    verifyNoMoreInteractions(endpointMock);
    verifyNoMoreInteractions(requestInfoSpy);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 87 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestContentDeserializerHandlerTest method doChannelRead_uses_TypeReference_from_endpoint_requestContentType_method.

@Test
public void doChannelRead_uses_TypeReference_from_endpoint_requestContentType_method() throws Exception {
    // given
    TypeReference<String> customTypeReference = new TypeReference<String>() {
    };
    doReturn(customTypeReference).when(endpointMock).requestContentType();
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
    // then
    ArgumentCaptor<TypeReference> typeRefArgumentCaptor = ArgumentCaptor.forClass(TypeReference.class);
    verify(requestInfoSpy).setupContentDeserializer(eq(defaultHandlerDeserializerMock), typeRefArgumentCaptor.capture());
    TypeReference<String> actualTypeRef = typeRefArgumentCaptor.getValue();
    assertThat(actualTypeRef).isSameAs(customTypeReference);
    assertThat(actualTypeRef).isNotSameAs(contentTypeRef);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test)

Example 88 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestContentDeserializerHandlerTest method doChannelRead_does_nothing_if_msg_is_not_LastHttpContent.

@Test
public void doChannelRead_does_nothing_if_msg_is_not_LastHttpContent() throws Exception {
    // given
    Object wrongMsgType = new Object();
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, wrongMsgType);
    // then
    verifyNoInteractions(ctxMock);
    verifyNoInteractions(stateMock);
    verifyNoInteractions(endpointMock);
    verifyNoInteractions(requestInfoSpy);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Test(org.junit.Test)

Example 89 with PipelineContinuationBehavior

use of com.nike.riposte.server.handler.base.PipelineContinuationBehavior in project riposte by Nike-Inc.

the class RequestContentDeserializerHandlerTest method doChannelRead_uses_custom_deserializer_if_custom_endpoint_one_is_not_null.

@Test
public void doChannelRead_uses_custom_deserializer_if_custom_endpoint_one_is_not_null() throws Exception {
    // given
    ObjectMapper customDeserializerMock = mock(ObjectMapper.class);
    doReturn(customDeserializerMock).when(endpointMock).customRequestContentDeserializer(any());
    // when
    PipelineContinuationBehavior result = handler.doChannelRead(ctxMock, msg);
    // then
    verify(requestInfoSpy).setupContentDeserializer(customDeserializerMock, contentTypeRef);
    assertThat(result).isEqualTo(PipelineContinuationBehavior.CONTINUE);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 90 with PipelineContinuationBehavior

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_mixed_type_and_return_null.

@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void handleFilterLogic_executes_all_filters_and_uses_original_request_when_filters_are_mixed_type_and_return_null(boolean isFirstChunk) {
    // given
    HandleFilterLogicMethodCallArgs args = new HandleFilterLogicMethodCallArgs(isFirstChunk);
    doReturn(true).when(filtersList.get(0)).isShortCircuitRequestFilter();
    doReturn(false).when(filtersList.get(1)).isShortCircuitRequestFilter();
    // when
    PipelineContinuationBehavior result = handlerSpy.handleFilterLogic(ctxMock, args.msg, args.httpState, args.normalFilterCall, args.shortCircuitFilterCall);
    // then
    assertThat(result).isEqualTo(CONTINUE);
    filtersList.forEach(filter -> {
        boolean shortCircuiting = filter.isShortCircuitRequestFilter();
        if (isFirstChunk) {
            if (shortCircuiting)
                verify(filter).filterRequestFirstChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
            else
                verify(filter).filterRequestFirstChunkNoPayload(requestInfoMock, ctxMock);
        } else {
            if (shortCircuiting)
                verify(filter).filterRequestLastChunkWithOptionalShortCircuitResponse(requestInfoMock, ctxMock);
            else
                verify(filter).filterRequestLastChunkWithFullPayload(requestInfoMock, ctxMock);
        }
    });
    assertThat(state.getRequestInfo()).isSameAs(requestInfoMock);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Aggregations

PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)92 Test (org.junit.Test)90 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)26 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)11 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 RequestInfo (com.nike.riposte.server.http.RequestInfo)7 Span (com.nike.wingtips.Span)6 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)5 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)5 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)5 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)5 HttpRequest (io.netty.handler.codec.http.HttpRequest)5 Pair (com.nike.internal.util.Pair)4 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)4 ChannelFuture (io.netty.channel.ChannelFuture)4 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)4 InvalidRipostePipelineException (com.nike.riposte.server.error.exception.InvalidRipostePipelineException)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3