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);
}
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);
}
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);
}
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);
}
}
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));
}
Aggregations