Search in sources :

Example 1 with ErrorResponseInfo

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));
}
Also used : ErrorResponseInfo(com.nike.backstopper.handler.ErrorResponseInfo) RequestInfoForLogging(com.nike.backstopper.handler.RequestInfoForLogging) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) RequestInfo(com.nike.riposte.server.http.RequestInfo) Test(org.junit.Test)

Example 2 with ErrorResponseInfo

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));
}
Also used : RequestInfoForLogging(com.nike.backstopper.handler.RequestInfoForLogging) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) RequestInfo(com.nike.riposte.server.http.RequestInfo) ErrorResponseInfo(com.nike.backstopper.handler.ErrorResponseInfo) List(java.util.List) ErrorResponseInfoImpl(com.nike.backstopper.model.riposte.ErrorResponseInfoImpl) Test(org.junit.Test)

Example 3 with ErrorResponseInfo

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));
}
Also used : ErrorResponseInfo(com.nike.backstopper.handler.ErrorResponseInfo) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) List(java.util.List) Test(org.junit.Test)

Example 4 with ErrorResponseInfo

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));
}
Also used : RequestInfoForLogging(com.nike.backstopper.handler.RequestInfoForLogging) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) RequestInfo(com.nike.riposte.server.http.RequestInfo) ErrorResponseInfo(com.nike.backstopper.handler.ErrorResponseInfo) List(java.util.List) ErrorResponseInfoImpl(com.nike.backstopper.model.riposte.ErrorResponseInfoImpl) Test(org.junit.Test)

Aggregations

ErrorResponseInfo (com.nike.backstopper.handler.ErrorResponseInfo)4 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)4 Test (org.junit.Test)4 RequestInfoForLogging (com.nike.backstopper.handler.RequestInfoForLogging)3 RequestInfo (com.nike.riposte.server.http.RequestInfo)3 List (java.util.List)3 ErrorResponseInfoImpl (com.nike.backstopper.model.riposte.ErrorResponseInfoImpl)2