Search in sources :

Example 21 with ErrorResponseBody

use of com.nike.riposte.server.error.handler.ErrorResponseBody in project riposte by Nike-Inc.

the class RiposteApiExceptionHandlerTest method prepareFrameworkResponseUsesErrorResponseBodyNettyAdapterWrapper.

@Test
public void prepareFrameworkResponseUsesErrorResponseBodyNettyAdapterWrapper() {
    RiposteApiExceptionHandler myAdapter = new RiposteApiExceptionHandler(projectApiErrors, validListenerList, utils);
    DefaultErrorContractDTO errorContract = new DefaultErrorContractDTO(UUID.randomUUID().toString(), Arrays.asList(projectApiErrors.getUnauthorizedApiError(), projectApiErrors.getMalformedRequestApiError()));
    ErrorResponseBody result = myAdapter.prepareFrameworkRepresentation(errorContract, 42, null, null, null);
    assertThat(result, instanceOf(ErrorResponseBodyImpl.class));
    ErrorResponseBodyImpl adapterResult = (ErrorResponseBodyImpl) result;
    assertThat(adapterResult.error_id, is(errorContract.error_id));
    assertThat(adapterResult.errors, is(errorContract.errors));
}
Also used : ErrorResponseBodyImpl(com.nike.backstopper.model.riposte.ErrorResponseBodyImpl) DefaultErrorContractDTO(com.nike.backstopper.model.DefaultErrorContractDTO) ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) Test(org.junit.Test)

Example 22 with ErrorResponseBody

use of com.nike.riposte.server.error.handler.ErrorResponseBody in project riposte by Nike-Inc.

the class ErrorResponseInfoImplTest method constructorWithIndividualArgsSetsValues.

@Test
public void constructorWithIndividualArgsSetsValues() {
    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();
    ErrorResponseInfoImpl adapter = new ErrorResponseInfoImpl(bodyMock, httpStatusCode, headers);
    assertThat(adapter.errorResponseBody, sameInstance(bodyMock));
    assertThat(adapter.httpStatusCode, is(httpStatusCode));
    assertThat(adapter.headersToAddToResponse, is(headers));
}
Also used : ErrorResponseBody(com.nike.riposte.server.error.handler.ErrorResponseBody) List(java.util.List) Test(org.junit.Test)

Example 23 with ErrorResponseBody

use of com.nike.riposte.server.error.handler.ErrorResponseBody 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 24 with ErrorResponseBody

use of com.nike.riposte.server.error.handler.ErrorResponseBody 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

ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)24 Test (org.junit.Test)18 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)6 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)6 ErrorResponseInfo (com.nike.riposte.server.error.handler.ErrorResponseInfo)6 FullResponseInfo (com.nike.riposte.server.http.impl.FullResponseInfo)6 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)5 RequestInfo (com.nike.riposte.server.http.RequestInfo)5 List (java.util.List)5 ErrorResponseInfo (com.nike.backstopper.handler.ErrorResponseInfo)4 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)4 RequestInfoForLogging (com.nike.backstopper.handler.RequestInfoForLogging)3 DefaultErrorContractDTO (com.nike.backstopper.model.DefaultErrorContractDTO)2 ErrorResponseBodyImpl (com.nike.backstopper.model.riposte.ErrorResponseBodyImpl)2 ErrorResponseInfoImpl (com.nike.backstopper.model.riposte.ErrorResponseInfoImpl)2 ChannelAttributes (com.nike.riposte.server.channelpipeline.ChannelAttributes)2 RiposteErrorHandler (com.nike.riposte.server.error.handler.RiposteErrorHandler)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2