use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RequestInfoImplTest method setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null.
@Test
public void setupContentDeserializer_and_getContent_sets_content_to_null_if_raw_content_bytes_is_null() throws IOException {
// given
RequestInfo<TestContentObject> requestInfo = (RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
assertThat(requestInfo.getRawContentBytes(), nullValue());
// when
requestInfo.setupContentDeserializer(new ObjectMapper(), new TypeReference<TestContentObject>() {
});
// then
assertThat(requestInfo.getContent(), nullValue());
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class NonblockingEndpointExecutionHandlerTest method beforeMethod.
@Before
public void beforeMethod() {
stateMock = mock(HttpProcessingState.class);
proxyRouterStateMock = mock(ProxyRouterProcessingState.class);
ctxMock = mock(ChannelHandlerContext.class);
channelMock = mock(Channel.class);
stateAttrMock = mock(Attribute.class);
proxyRouterStateAttrMock = mock(Attribute.class);
requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
endpointMock = mock(StandardEndpoint.class);
longRunningTaskExecutorMock = mock(Executor.class);
responseFuture = new CompletableFuture<>();
stateWorkChainFutureSpy = spy(CompletableFuture.completedFuture(null));
eventLoopMock = mock(EventLoop.class);
eventExecutorMock = mock(EventExecutor.class);
doReturn(channelMock).when(ctxMock).channel();
doReturn(stateAttrMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(stateMock).when(stateAttrMock).get();
doReturn(false).when(stateMock).isRequestHandled();
doReturn(proxyRouterStateAttrMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(proxyRouterStateMock).when(proxyRouterStateAttrMock).get();
doReturn(endpointMock).when(stateMock).getEndpointForExecution();
doReturn(requestInfo).when(stateMock).getRequestInfo();
doReturn(responseFuture).when(endpointMock).execute(any(RequestInfo.class), any(Executor.class), any(ChannelHandlerContext.class));
doReturn(eventLoopMock).when(channelMock).eventLoop();
doReturn(eventExecutorMock).when(ctxMock).executor();
doReturn(true).when(eventExecutorMock).inEventLoop();
doReturn(true).when(channelMock).isActive();
doAnswer(invocation -> {
CompletableFuture actualFutureForAttaching = (CompletableFuture) invocation.callRealMethod();
futureThatWillBeAttachedToSpy = spy(actualFutureForAttaching);
return futureThatWillBeAttachedToSpy;
}).when(stateWorkChainFutureSpy).thenCompose(any(Function.class));
doReturn(stateWorkChainFutureSpy).when(stateMock).getPreEndpointExecutionWorkChain();
handlerSpy = spy(new NonblockingEndpointExecutionHandler(longRunningTaskExecutorMock, defaultCompletableFutureTimeoutMillis));
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RiposteApiExceptionHandlerTest method maybeHandleErrorExplosionThrowsUnexpectedMajorErrorHandlingError.
// Note the difference between UnexpectedMajor**Exception**HandlingError and UnexpectedMajor**Error**HandlingError. I know, I know, confusing and annoying. Adapters can be like that.
@Test(expected = UnexpectedMajorErrorHandlingError.class)
public void maybeHandleErrorExplosionThrowsUnexpectedMajorErrorHandlingError() throws UnexpectedMajorExceptionHandlingError, UnexpectedMajorErrorHandlingError {
UnexpectedMajorExceptionHandlingError innerExplosion = new UnexpectedMajorExceptionHandlingError("intentional kaboom", new Exception());
doThrow(innerExplosion).when(adapterSpy).maybeHandleException(any(Throwable.class), any(RequestInfoForLogging.class));
RequestInfo requestInfoMock = mock(RequestInfo.class);
adapterSpy.maybeHandleError(new Exception(), requestInfoMock);
}
use of com.nike.riposte.server.http.RequestInfo in project riposte by Nike-Inc.
the class RiposteApiExceptionHandlerTest method maybeHandleErrorFromNettyInterfaceReturnsNullIfBackstopperMaybeHandleExceptionReturnsNull.
@Test
public void maybeHandleErrorFromNettyInterfaceReturnsNullIfBackstopperMaybeHandleExceptionReturnsNull() throws UnexpectedMajorExceptionHandlingError, UnexpectedMajorErrorHandlingError {
doReturn(null).when(adapterSpy).maybeHandleException(any(Throwable.class), any(RequestInfoForLogging.class));
RequestInfo requestInfoMock = mock(RequestInfo.class);
assertThat(adapterSpy.maybeHandleError(new Exception(), requestInfoMock), nullValue());
}
Aggregations