use of com.nike.backstopper.handler.ErrorResponseInfo in project riposte by Nike-Inc.
the class RiposteUnhandledExceptionHandlerTest method handleErrorFromNettyInterfaceWrapsRequestInfoWithAdapterBeforeContinuing.
@Test
public void handleErrorFromNettyInterfaceWrapsRequestInfoWithAdapterBeforeContinuing() {
com.nike.backstopper.handler.ErrorResponseInfo<ErrorResponseBody> backstopperResponse = new ErrorResponseInfo<>(42, mock(ErrorResponseBody.class), Collections.emptyMap());
doReturn(backstopperResponse).when(adapterSpy).handleException(any(Throwable.class), any(RequestInfoForLogging.class));
RequestInfo requestInfoMock = mock(RequestInfo.class);
adapterSpy.handleError(new Exception(), requestInfoMock);
ArgumentCaptor<RequestInfoForLogging> requestInfoForLoggingArgumentCaptor = ArgumentCaptor.forClass(RequestInfoForLogging.class);
verify(adapterSpy).handleException(any(Throwable.class), requestInfoForLoggingArgumentCaptor.capture());
RequestInfoForLogging passedArg = requestInfoForLoggingArgumentCaptor.getValue();
assertThat(passedArg, instanceOf(RequestInfoForLoggingRiposteAdapter.class));
RequestInfo embeddedRequestInfoInWrapper = (RequestInfo) Whitebox.getInternalState(passedArg, "request");
assertThat(embeddedRequestInfoInWrapper, sameInstance(requestInfoMock));
}
use of com.nike.backstopper.handler.ErrorResponseInfo in project riposte by Nike-Inc.
the class RiposteApiExceptionHandlerTest method maybeHandleErrorFromNettyInterfaceReturnsWrapperAroundBackstopperMaybeHandleExceptionReturnValue.
@Test
public void maybeHandleErrorFromNettyInterfaceReturnsWrapperAroundBackstopperMaybeHandleExceptionReturnValue() throws UnexpectedMajorExceptionHandlingError, UnexpectedMajorErrorHandlingError {
ErrorResponseBody errorResponseBodyMock = mock(ErrorResponseBody.class);
Map<String, List<String>> headersMap = MapBuilder.<String, List<String>>builder().put("headerName", Arrays.asList("hval1", "hval2")).build();
com.nike.backstopper.handler.ErrorResponseInfo<ErrorResponseBody> backstopperResponse = new ErrorResponseInfo<>(42, errorResponseBodyMock, headersMap);
doReturn(backstopperResponse).when(adapterSpy).maybeHandleException(any(Throwable.class), any(RequestInfoForLogging.class));
com.nike.riposte.server.error.handler.ErrorResponseInfo riposteErrorResponseInfo = adapterSpy.maybeHandleError(new Exception(), mock(RequestInfo.class));
assertThat(riposteErrorResponseInfo, instanceOf(ErrorResponseInfoImpl.class));
assertThat(riposteErrorResponseInfo.getErrorHttpStatusCode(), is(backstopperResponse.httpStatusCode));
assertThat(riposteErrorResponseInfo.getErrorResponseBody(), is(errorResponseBodyMock));
assertThat(riposteErrorResponseInfo.getExtraHeadersToAddToResponse(), is(headersMap));
}
use of com.nike.backstopper.handler.ErrorResponseInfo in project riposte by Nike-Inc.
the class ErrorResponseInfoImplTest method constructorWithErrorResponseInfoArgsSetsValues.
@Test
public void constructorWithErrorResponseInfoArgsSetsValues() {
ErrorResponseBody bodyMock = mock(ErrorResponseBody.class);
int httpStatusCode = 42;
Map<String, List<String>> headers = MapBuilder.<String, List<String>>builder().put("someHeader", Arrays.asList("hval1", "hval2")).build();
ErrorResponseInfo<ErrorResponseBody> backstopperErrorResponseInfo = new ErrorResponseInfo<>(httpStatusCode, bodyMock, headers);
ErrorResponseInfoImpl adapter = new ErrorResponseInfoImpl(backstopperErrorResponseInfo);
assertThat(adapter.errorResponseBody, sameInstance(bodyMock));
assertThat(adapter.httpStatusCode, is(httpStatusCode));
assertThat(adapter.headersToAddToResponse, is(headers));
}
use of com.nike.backstopper.handler.ErrorResponseInfo in project riposte by Nike-Inc.
the class RiposteUnhandledExceptionHandlerTest method handleErrorFromNettyInterfaceReturnsWrapperAroundBackstopperHandleExceptionReturnValue.
@Test
public void handleErrorFromNettyInterfaceReturnsWrapperAroundBackstopperHandleExceptionReturnValue() {
ErrorResponseBody errorResponseBodyMock = mock(ErrorResponseBody.class);
Map<String, List<String>> headersMap = MapBuilder.<String, List<String>>builder().put("headerName", Arrays.asList("hval1", "hval2")).build();
com.nike.backstopper.handler.ErrorResponseInfo<ErrorResponseBody> backstopperResponse = new ErrorResponseInfo<>(42, errorResponseBodyMock, headersMap);
doReturn(backstopperResponse).when(adapterSpy).handleException(any(Throwable.class), any(RequestInfoForLogging.class));
com.nike.riposte.server.error.handler.ErrorResponseInfo riposteErrorResponseInfo = adapterSpy.handleError(new Exception(), mock(RequestInfo.class));
assertThat(riposteErrorResponseInfo, instanceOf(ErrorResponseInfoImpl.class));
assertThat(riposteErrorResponseInfo.getErrorHttpStatusCode(), is(backstopperResponse.httpStatusCode));
assertThat(riposteErrorResponseInfo.getErrorResponseBody(), is(errorResponseBodyMock));
assertThat(riposteErrorResponseInfo.getExtraHeadersToAddToResponse(), is(headersMap));
}
Aggregations