Search in sources :

Example 46 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 47 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 48 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 49 with PipelineContinuationBehavior

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

the class OpenChannelLimitHandlerTest method doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels.

@DataProvider(value = { "null   |   false", "-1     |   false", "0      |   true", "1      |   true" }, splitBy = "\\|")
@Test
public void doChannelRead_throws_TooManyOpenChannelsException_or_not_depending_on_the_number_of_open_channels(Integer numOpenChannelsDiffFromMaxThreshold, boolean expectTooManyOpenChannelsException) {
    // given
    Integer numOpenChannels = (numOpenChannelsDiffFromMaxThreshold == null) ? null : maxOpenChannelsThreshold + numOpenChannelsDiffFromMaxThreshold;
    doReturn(numOpenChannels).when(tooManyOpenConnectionsAttributeMock).get();
    // when
    Throwable ex = null;
    PipelineContinuationBehavior result = null;
    try {
        result = handler.doChannelRead(ctxMock, msg);
    } catch (Throwable t) {
        ex = t;
    }
    // then
    if (expectTooManyOpenChannelsException) {
        assertThat(ex).isInstanceOf(TooManyOpenChannelsException.class);
    } else {
        assertThat(ex).isNull();
        assertThat(result).isEqualTo(CONTINUE);
    }
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) Assertions.catchThrowable(org.assertj.core.api.Assertions.catchThrowable) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 50 with PipelineContinuationBehavior

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

the class ExceptionHandlingHandlerTest method doChannelRead_should_call_processUnhandledError_and_set_response_on_state_and_return_CONTINUE_if_request_has_not_been_handled.

@Test
public void doChannelRead_should_call_processUnhandledError_and_set_response_on_state_and_return_CONTINUE_if_request_has_not_been_handled() throws Exception {
    // given
    ExceptionHandlingHandler handlerSpy = spy(handler);
    ResponseInfo<ErrorResponseBody> errorResponseMock = mock(ResponseInfo.class);
    Object msg = new Object();
    doReturn(errorResponseMock).when(handlerSpy).processUnhandledError(eq(state), eq(msg), any(Throwable.class));
    assertThat(state.isRequestHandled(), is(false));
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    verify(handlerSpy).processUnhandledError(eq(state), eq(msg), any(Throwable.class));
    assertThat(state.getResponseInfo(), is(errorResponseMock));
    assertThat(result, is(PipelineContinuationBehavior.CONTINUE));
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) Test(org.junit.Test)

Aggregations

PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)75 Test (org.junit.Test)73 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)20 RequestInfo (com.nike.riposte.server.http.RequestInfo)5 Span (com.nike.wingtips.Span)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)4 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)4 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)4 ChannelFuture (io.netty.channel.ChannelFuture)4 HttpObject (io.netty.handler.codec.http.HttpObject)4 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)4 Pair (com.nike.internal.util.Pair)3 HttpContent (io.netty.handler.codec.http.HttpContent)3 ChannelAttributes (com.nike.riposte.server.channelpipeline.ChannelAttributes)2 OutboundMessage (com.nike.riposte.server.channelpipeline.message.OutboundMessage)2 OutboundMessageSendHeadersChunkFromResponseInfo (com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo)2 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)2 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)2