com.nike.backstopper.handler.ApiExceptionHandlerUtils Java Examples

The following examples show how to use com.nike.backstopper.handler.ApiExceptionHandlerUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OneOffSpringWebFluxFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@UseDataProvider("typeMismatchExceptionScenarioDataProvider")
@Test
public void handleFluxExceptions_handles_ResponseStatusException_with_TypeMismatchException_cause_as_expected(
    TypeMismatchExceptionScenario scenario
) {
    // given
    ResponseStatusException ex = new ResponseStatusException(
        scenario.status, "Some ResponseStatusException reason", scenario.tmeCause
    );
    List<Pair<String, String>> expectedExtraDetailsForLogging = new ArrayList<>();
    ApiExceptionHandlerUtils.DEFAULT_IMPL.addBaseExceptionMessageToExtraDetailsForLogging(
        ex, expectedExtraDetailsForLogging
    );
    expectedExtraDetailsForLogging.addAll(scenario.expectedExtraDetailsForLogging);

    // when
    ApiExceptionHandlerListenerResult result = listener.handleSpringMvcOrWebfluxSpecificFrameworkExceptions(ex);

    // then
    validateResponse(
        result,
        true,
        singleton(scenario.expectedApiError),
        expectedExtraDetailsForLogging
    );
}
 
Example #2
Source File: RiposteApiExceptionHandlerTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void constructorWorksIfPassedValidValues() {
    // when
    RiposteApiExceptionHandler
        myAdapter = new RiposteApiExceptionHandler(projectApiErrors, validListenerList, utils);

    // then
    List<ApiExceptionHandlerListener> actualListeners =
        (List<ApiExceptionHandlerListener>) Whitebox.getInternalState(myAdapter, "apiExceptionHandlerListenerList");
    ProjectApiErrors actualProjectApiErrors =
        (ProjectApiErrors) Whitebox.getInternalState(myAdapter, "projectApiErrors");
    ApiExceptionHandlerUtils actualUtils = (ApiExceptionHandlerUtils) Whitebox.getInternalState(myAdapter, "utils");
    assertThat(actualListeners, is(validListenerList));
    assertThat(actualProjectApiErrors, is(projectApiErrors));
    assertThat(actualUtils, is(utils));
}
 
Example #3
Source File: ServerConfig.java    From riposte with Apache License 2.0 6 votes vote down vote up
/**
 * @return The error handler that should be used for this application for handling unknown/unexpected/unhandled
 * errors. Known/handled errors will be processed by {@link #riposteErrorHandler()}.
 *
 * <p>NOTE: The default implementation returned if you don't override this method is a very basic Backstopper impl -
 * it will not know about your application's {@link ProjectApiErrors} and will instead create a dummy {@link
 * ProjectApiErrors} that only supports the {@link com.nike.backstopper.apierror.sample.SampleCoreApiError} values.
 * This method should be overridden for most real applications to return a real implementation tailored for your
 * app. In practice this usually means copy/pasting this method and simply supplying the correct {@link
 * ProjectApiErrors} for the app. The rest is usually fine for defaults.
 */
default @NotNull RiposteUnhandledErrorHandler riposteUnhandledErrorHandler() {
    ProjectApiErrors projectApiErrors = new SampleProjectApiErrorsBase() {
        @Override
        protected List<ApiError> getProjectSpecificApiErrors() {
            return null;
        }

        @Override
        protected ProjectSpecificErrorCodeRange getProjectSpecificErrorCodeRange() {
            return null;
        }
    };
    return BackstopperRiposteConfigHelper
        .defaultUnhandledErrorHandler(projectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL);
}
 
Example #4
Source File: ServerConfig.java    From riposte with Apache License 2.0 6 votes vote down vote up
/**
 * @return The error handler that should be used for this application for handling known errors. For things that
 * fall through the cracks they will be handled by {@link #riposteUnhandledErrorHandler()}.
 *
 * <p>NOTE: The default implementation returned if you don't override this method is a very basic Backstopper impl -
 * it will not know about your application's {@link ProjectApiErrors} and will instead create a dummy {@link
 * ProjectApiErrors} that only supports the {@link com.nike.backstopper.apierror.sample.SampleCoreApiError} values.
 * This method should be overridden for most real applications to return a real implementation tailored for your
 * app. In practice this usually means copy/pasting this method and simply supplying the correct {@link
 * ProjectApiErrors} for the app. The rest is usually fine for defaults.
 */
default @NotNull RiposteErrorHandler riposteErrorHandler() {
    ProjectApiErrors projectApiErrors = new SampleProjectApiErrorsBase() {
        @Override
        protected List<ApiError> getProjectSpecificApiErrors() {
            return null;
        }

        @Override
        protected ProjectSpecificErrorCodeRange getProjectSpecificErrorCodeRange() {
            return null;
        }
    };
    return BackstopperRiposteConfigHelper
        .defaultErrorHandler(projectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL);
}
 
Example #5
Source File: Jersey1ApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeMethod() {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    when(mockRequest.getRequestURI()).thenReturn("/fake/path");
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getQueryString()).thenReturn("queryString");

    listenerList = new ApiExceptionHandlerListenerList(
        Jersey1BackstopperConfigHelper.defaultApiExceptionHandlerListeners(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    unhandledSpy = spy(new Jersey1UnhandledExceptionHandler(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    handlerSpy = spy(new Jersey1ApiExceptionHandler(
        testProjectApiErrors,
        listenerList,
        ApiExceptionHandlerUtils.DEFAULT_IMPL, unhandledSpy));
    Whitebox.setInternalState(handlerSpy, "request", mockRequest);
    Whitebox.setInternalState(handlerSpy, "response", mock(HttpServletResponse.class));
}
 
Example #6
Source File: Jersey2ApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeMethod() {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    when(mockRequest.getRequestURI()).thenReturn("/fake/path");
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getQueryString()).thenReturn("queryString");

    listenerList = new Jersey2ApiExceptionHandlerListenerList(
        Jersey2BackstopperConfigHelper.defaultApiExceptionHandlerListeners(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    unhandledSpy = spy(new JaxRsUnhandledExceptionHandler(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    handlerSpy = spy(new Jersey2ApiExceptionHandler(
        testProjectApiErrors,
        listenerList,
        ApiExceptionHandlerUtils.DEFAULT_IMPL, unhandledSpy));
    Whitebox.setInternalState(handlerSpy, "request", mockRequest);
    Whitebox.setInternalState(handlerSpy, "response", mock(HttpServletResponse.class));
}
 
Example #7
Source File: BackstopperSpringWebFluxComponentTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public SpringWebfluxUnhandledExceptionHandler springWebfluxUnhandledExceptionHandler(
    ProjectApiErrors projectApiErrors,
    ApiExceptionHandlerUtils generalUtils,
    SpringWebfluxApiExceptionHandlerUtils springUtils,
    ObjectProvider<ViewResolver> viewResolversProvider,
    ServerCodecConfigurer serverCodecConfigurer
) {
    return new SpringWebfluxUnhandledExceptionHandler(
        projectApiErrors, generalUtils, springUtils, viewResolversProvider, serverCodecConfigurer
    ) {
        @Override
        public Mono<Void> handle(ServerWebExchange exchange, Throwable ex) {
            exceptionSeenByUnhandledBackstopperHandler = ex;
            return super.handle(exchange, ex);
        }
    };
}
 
Example #8
Source File: BackstopperSpringWebFluxComponentTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Bean
@Primary
public SpringWebfluxApiExceptionHandler springWebfluxApiExceptionHandler(
    ProjectApiErrors projectApiErrors,
    SpringWebFluxApiExceptionHandlerListenerList apiExceptionHandlerListeners,
    ApiExceptionHandlerUtils generalUtils,
    SpringWebfluxApiExceptionHandlerUtils springUtils,
    ObjectProvider<ViewResolver> viewResolversProvider,
    ServerCodecConfigurer serverCodecConfigurer
) {
    return new SpringWebfluxApiExceptionHandler(
        projectApiErrors, apiExceptionHandlerListeners, generalUtils, springUtils, viewResolversProvider,
        serverCodecConfigurer
    ) {
        @Override
        protected ApiExceptionHandlerListenerResult shouldHandleApiException(
            Throwable ex
        ) {
            exceptionSeenByNormalBackstopperHandler = ex;
            normalBackstopperHandlingResult = super.shouldHandleApiException(ex);
            return normalBackstopperHandlingResult;
        }
    };
}
 
Example #9
Source File: JaxRsApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeMethod() {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    when(mockRequest.getRequestURI()).thenReturn("/fake/path");
    when(mockRequest.getMethod()).thenReturn("GET");
    when(mockRequest.getQueryString()).thenReturn("queryString");

    listenerList = new JaxRsApiExceptionHandlerListenerList(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL);

    unhandledSpy = spy(new JaxRsUnhandledExceptionHandler(testProjectApiErrors, ApiExceptionHandlerUtils.DEFAULT_IMPL));

    handlerSpy = spy(new JaxRsApiExceptionHandler(
        testProjectApiErrors,
        listenerList,
        ApiExceptionHandlerUtils.DEFAULT_IMPL, unhandledSpy));
    Whitebox.setInternalState(handlerSpy, "request", mockRequest);
    Whitebox.setInternalState(handlerSpy, "response", mock(HttpServletResponse.class));
}
 
Example #10
Source File: BackstopperRiposteConfigHelper.java    From riposte with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link RiposteErrorHandler} that uses the given {@link ProjectApiErrors}, and {@link
 * #defaultHandlerListeners(ProjectApiErrors, ApiExceptionHandlerUtils)} for the error handler listeners.
 */
public static @NotNull RiposteErrorHandler defaultErrorHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils utils
) {
    return new RiposteApiExceptionHandler(
        projectApiErrors,
        defaultHandlerListeners(projectApiErrors, utils),
        utils
    );
}
 
Example #11
Source File: SpringWebfluxUnhandledExceptionHandlerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    generalUtils = ApiExceptionHandlerUtils.DEFAULT_IMPL;
    testProjectApiErrors = ProjectApiErrorsForTesting.withProjectSpecificData(null, null);
    springUtilsMock = mock(SpringWebfluxApiExceptionHandlerUtils.class);
    viewResolversProviderMock = mock(ObjectProvider.class);
    serverCodecConfigurerMock = mock(ServerCodecConfigurer.class);
    messageReaders = Arrays.asList(mock(HttpMessageReader.class), mock(HttpMessageReader.class));
    messageWriters = Arrays.asList(mock(HttpMessageWriter.class), mock(HttpMessageWriter.class));
    viewResolvers = Arrays.asList(mock(ViewResolver.class), mock(ViewResolver.class));
    serverWebExchangeMock = mock(ServerWebExchange.class);
    serverHttpRequestMock = mock(ServerHttpRequest.class);
    serverHttpResponseMock = mock(ServerHttpResponse.class);
    serverHttpResponseHeadersMock = mock(HttpHeaders.class);
    uri = URI.create("http://localhost:8080/foo/bar?someQuery=someValue");
    exMock = mock(Throwable.class);

    doAnswer(invocation -> viewResolvers.stream()).when(viewResolversProviderMock).orderedStream();
    doReturn(messageReaders).when(serverCodecConfigurerMock).getReaders();
    doReturn(messageWriters).when(serverCodecConfigurerMock).getWriters();

    doReturn(serverHttpRequestMock).when(serverWebExchangeMock).getRequest();
    doReturn(uri).when(serverHttpRequestMock).getURI();

    doReturn(serverHttpResponseMock).when(serverWebExchangeMock).getResponse();
    doReturn(serverHttpResponseHeadersMock).when(serverHttpResponseMock).getHeaders();

    handlerSpy = spy(new SpringWebfluxUnhandledExceptionHandler(
        testProjectApiErrors, generalUtils, springUtilsMock, viewResolversProviderMock, serverCodecConfigurerMock
    ));
}
 
Example #12
Source File: BackstopperRiposteConfigGuiceModule.java    From riposte with Apache License 2.0 5 votes vote down vote up
/**
 * @return The basic set of handler listeners that are appropriate for most Riposte applications.
 */
@Provides
@Singleton
@SuppressWarnings("unused")
public List<ApiExceptionHandlerListener> apiExceptionHandlerListeners(ProjectApiErrors projectApiErrors,
                                                                      ApiExceptionHandlerUtils utils) {
    return BackstopperRiposteConfigHelper.defaultHandlerListeners(projectApiErrors, utils);
}
 
Example #13
Source File: BackstopperRiposteConfigHelper.java    From riposte with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the default list of {@link ApiExceptionHandlerListener}s that should work for most applications without
 * any further additions.
 */
public static @NotNull List<ApiExceptionHandlerListener> defaultHandlerListeners(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils utils
) {
    return Arrays.asList(new GenericApiExceptionHandlerListener(),
                         new ServersideValidationErrorHandlerListener(projectApiErrors, utils),
                         new ClientDataValidationErrorHandlerListener(projectApiErrors, utils),
                         new DownstreamNetworkExceptionHandlerListener(projectApiErrors),
                         new BackstopperRiposteFrameworkErrorHandlerListener(projectApiErrors));
}
 
Example #14
Source File: BackstopperRiposteConfigHelper.java    From riposte with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a {@link RiposteUnhandledErrorHandler} that uses the given {@link ProjectApiErrors}.
 */
public static @NotNull RiposteUnhandledErrorHandler defaultUnhandledErrorHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils utils
) {
    return new RiposteUnhandledExceptionHandler(projectApiErrors, utils);
}
 
Example #15
Source File: OneOffSpringWebFluxFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "400    |   GENERIC_BAD_REQUEST",
    "401    |   UNAUTHORIZED",
    "403    |   FORBIDDEN",
    "404    |   NOT_FOUND",
    "405    |   METHOD_NOT_ALLOWED",
    "406    |   NO_ACCEPTABLE_REPRESENTATION",
    "415    |   UNSUPPORTED_MEDIA_TYPE",
    "429    |   TOO_MANY_REQUESTS",
    "500    |   GENERIC_SERVICE_ERROR",
    "503    |   TEMPORARY_SERVICE_PROBLEM",
}, splitBy = "\\|")
@Test
public void handleFluxExceptions_handles_generic_ResponseStatusException_by_returning_ApiError_from_project_if_status_code_is_known(
    int desiredStatusCode, BarebonesCoreApiErrorForTesting expectedError
) {
    // given
    ResponseStatusException ex = new ResponseStatusException(
        HttpStatus.resolve(desiredStatusCode), "Some ResponseStatusException reason"
    );
    List<Pair<String, String>> expectedExtraDetailsForLogging = new ArrayList<>();
    ApiExceptionHandlerUtils.DEFAULT_IMPL.addBaseExceptionMessageToExtraDetailsForLogging(
        ex, expectedExtraDetailsForLogging
    );

    // when
    ApiExceptionHandlerListenerResult result = listener.handleSpringMvcOrWebfluxSpecificFrameworkExceptions(ex);

    // then
    validateResponse(
        result,
        true,
        singleton(expectedError),
        expectedExtraDetailsForLogging
    );
}
 
Example #16
Source File: BackstopperRiposteFrameworkErrorHandlerListener.java    From riposte with Apache License 2.0 5 votes vote down vote up
@SafeVarargs
protected final @NotNull List<Pair<String, String>> withBaseExceptionMessage(
    @NotNull Throwable ex, @Nullable Pair<String, String>... extraLogMessages
) {
    List<Pair<String, String>> logPairs = new ArrayList<>();
    ApiExceptionHandlerUtils.DEFAULT_IMPL.addBaseExceptionMessageToExtraDetailsForLogging(ex, logPairs);
    if (extraLogMessages != null) {
        logPairs.addAll(Arrays.asList(extraLogMessages));
    }
    return logPairs;
}
 
Example #17
Source File: RiposteUnhandledExceptionHandler.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Inject
public RiposteUnhandledExceptionHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils utils
) {
    super(projectApiErrors, utils);
    singletonGenericServiceError = Collections.singleton(projectApiErrors.getGenericServiceError());
    genericServiceErrorHttpStatusCode = projectApiErrors.getGenericServiceError().getHttpStatusCode();
}
 
Example #18
Source File: Jersey1SampleConfigHelper.java    From backstopper with Apache License 2.0 5 votes vote down vote up
public static Jersey1ApiExceptionHandler generateJerseyApiExceptionHandler() {
    ApiExceptionHandlerUtils utils = ApiExceptionHandlerUtils.DEFAULT_IMPL;
    Jersey1BackstopperConfigHelper.ApiExceptionHandlerListenerList
        listeners = new Jersey1BackstopperConfigHelper.ApiExceptionHandlerListenerList(
        Jersey1BackstopperConfigHelper.defaultApiExceptionHandlerListeners(projectApiErrors, utils)
    );
    Jersey1UnhandledExceptionHandler unhandledExceptionHandler =
        new Jersey1UnhandledExceptionHandler(projectApiErrors, utils);

    return new Jersey1ApiExceptionHandler(
        projectApiErrors, listeners, utils, unhandledExceptionHandler
    );
}
 
Example #19
Source File: SpringApiExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public SpringApiExceptionHandler(ProjectApiErrors projectApiErrors,
                                 ApiExceptionHandlerListenerList apiExceptionHandlerListeners,
                                 ApiExceptionHandlerUtils generalUtils,
                                 SpringApiExceptionHandlerUtils springUtils) {
    super(projectApiErrors, apiExceptionHandlerListeners.listeners, generalUtils);
    this.springUtils = springUtils;
}
 
Example #20
Source File: OneOffSpringWebFluxFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "400    |   Request body is missing             |   MISSING_EXPECTED_CONTENT",
    "400    |   Request body is missing blahblah    |   MISSING_EXPECTED_CONTENT",
    "401    |   Request body is missing             |   UNAUTHORIZED",
    "400    |   Request body is                     |   GENERIC_BAD_REQUEST",
    "400    |   Some random reason                  |   GENERIC_BAD_REQUEST",
}, splitBy = "\\|")
@Test
public void handleFluxExceptions_returns_MISSING_EXPECTED_CONTENT_for_ResponseStatusException_with_special_reason_string_beginning(
    int statusCode, String exReasonString, BarebonesCoreApiErrorForTesting expectedError
) {
    // given
    ResponseStatusException ex = new ResponseStatusException(HttpStatus.resolve(statusCode), exReasonString);
    List<Pair<String, String>> expectedExtraDetailsForLogging = new ArrayList<>();
    ApiExceptionHandlerUtils.DEFAULT_IMPL.addBaseExceptionMessageToExtraDetailsForLogging(
        ex, expectedExtraDetailsForLogging
    );

    // when
    ApiExceptionHandlerListenerResult result = listener.handleSpringMvcOrWebfluxSpecificFrameworkExceptions(ex);

    // then
    validateResponse(
        result,
        true,
        singleton(expectedError),
        expectedExtraDetailsForLogging
    );
}
 
Example #21
Source File: OneOffSpringWebFluxFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void constructor_sets_projectApiErrors_and_utils_to_passed_in_args() {
    // given
    ProjectApiErrors projectErrorsMock = mock(ProjectApiErrors.class);
    ApiExceptionHandlerUtils utilsMock = mock(ApiExceptionHandlerUtils.class);

    // when
    OneOffSpringWebFluxFrameworkExceptionHandlerListener
        impl = new OneOffSpringWebFluxFrameworkExceptionHandlerListener(projectErrorsMock, utilsMock);

    // then
    assertThat(Whitebox.getInternalState(impl, "projectApiErrors")).isSameAs(projectErrorsMock);
    assertThat(Whitebox.getInternalState(impl, "utils")).isSameAs(utilsMock);
}
 
Example #22
Source File: SpringWebfluxApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    projectApiErrorsMock = mock(ProjectApiErrors.class);
    listenerList = new SpringWebFluxApiExceptionHandlerListenerList(
        Arrays.asList(mock(ApiExceptionHandlerListener.class), mock(ApiExceptionHandlerListener.class))
    );
    generalUtils = ApiExceptionHandlerUtils.DEFAULT_IMPL;
    springUtilsMock = mock(SpringWebfluxApiExceptionHandlerUtils.class);
    viewResolversProviderMock = mock(ObjectProvider.class);
    serverCodecConfigurerMock = mock(ServerCodecConfigurer.class);
    messageReaders = Arrays.asList(mock(HttpMessageReader.class), mock(HttpMessageReader.class));
    messageWriters = Arrays.asList(mock(HttpMessageWriter.class), mock(HttpMessageWriter.class));
    viewResolvers = Arrays.asList(mock(ViewResolver.class), mock(ViewResolver.class));
    serverWebExchangeMock = mock(ServerWebExchange.class);
    serverHttpRequestMock = mock(ServerHttpRequest.class);
    serverHttpResponseMock = mock(ServerHttpResponse.class);
    serverHttpResponseHeadersMock = mock(HttpHeaders.class);
    uri = URI.create("http://localhost:8080/foo/bar?someQuery=someValue");
    exMock = mock(Throwable.class);

    doAnswer(invocation -> viewResolvers.stream()).when(viewResolversProviderMock).orderedStream();
    doReturn(messageReaders).when(serverCodecConfigurerMock).getReaders();
    doReturn(messageWriters).when(serverCodecConfigurerMock).getWriters();

    doReturn(serverHttpRequestMock).when(serverWebExchangeMock).getRequest();
    doReturn(uri).when(serverHttpRequestMock).getURI();

    doReturn(serverHttpResponseMock).when(serverWebExchangeMock).getResponse();
    doReturn(serverHttpResponseHeadersMock).when(serverHttpResponseMock).getHeaders();

    handlerSpy = spy(new SpringWebfluxApiExceptionHandler(
        projectApiErrorsMock, listenerList, generalUtils, springUtilsMock, viewResolversProviderMock,
        serverCodecConfigurerMock
    ));
}
 
Example #23
Source File: SpringWebfluxApiExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public SpringWebfluxApiExceptionHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull SpringWebFluxApiExceptionHandlerListenerList apiExceptionHandlerListeners,
    @NotNull ApiExceptionHandlerUtils generalUtils,
    @NotNull SpringWebfluxApiExceptionHandlerUtils springUtils,
    @NotNull ObjectProvider<ViewResolver> viewResolversProvider,
    @NotNull ServerCodecConfigurer serverCodecConfigurer
) {
    super(projectApiErrors, apiExceptionHandlerListeners.listeners, generalUtils);

    //noinspection ConstantConditions
    if (springUtils == null) {
        throw new NullPointerException("springUtils cannot be null.");
    }

    //noinspection ConstantConditions
    if (viewResolversProvider == null) {
        throw new NullPointerException("viewResolversProvider cannot be null.");
    }

    //noinspection ConstantConditions
    if (serverCodecConfigurer == null) {
        throw new NullPointerException("serverCodecConfigurer cannot be null.");
    }

    this.springUtils = springUtils;
    this.viewResolvers = viewResolversProvider.orderedStream().collect(Collectors.toList());
    this.messageReaders = serverCodecConfigurer.getReaders();
    this.messageWriters = serverCodecConfigurer.getWriters();
}
 
Example #24
Source File: SpringWebfluxUnhandledExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public SpringWebfluxUnhandledExceptionHandler(
    @NotNull ProjectApiErrors projectApiErrors,
    @NotNull ApiExceptionHandlerUtils generalUtils,
    @NotNull SpringWebfluxApiExceptionHandlerUtils springUtils,
    @NotNull ObjectProvider<ViewResolver> viewResolversProvider,
    @NotNull ServerCodecConfigurer serverCodecConfigurer
) {
    super(projectApiErrors, generalUtils);

    //noinspection ConstantConditions
    if (springUtils == null) {
        throw new NullPointerException("springUtils cannot be null.");
    }
    
    //noinspection ConstantConditions
    if (viewResolversProvider == null) {
        throw new NullPointerException("viewResolversProvider cannot be null.");
    }

    //noinspection ConstantConditions
    if (serverCodecConfigurer == null) {
        throw new NullPointerException("serverCodecConfigurer cannot be null.");
    }

    this.singletonGenericServiceError = Collections.singleton(projectApiErrors.getGenericServiceError());
    this.genericServiceErrorHttpStatusCode = projectApiErrors.getGenericServiceError().getHttpStatusCode();

    this.springUtils = springUtils;
    this.viewResolvers = viewResolversProvider.orderedStream().collect(Collectors.toList());
    this.messageReaders = serverCodecConfigurer.getReaders();
    this.messageWriters = serverCodecConfigurer.getWriters();
}
 
Example #25
Source File: SpringUnhandledExceptionHandlerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    springUtilsSpy = spy(SpringApiExceptionHandlerUtils.DEFAULT_IMPL);
    generalUtils = ApiExceptionHandlerUtils.DEFAULT_IMPL;
    testProjectApiErrors = ProjectApiErrorsForTesting.withProjectSpecificData(null, null);
    handlerSpy = spy(new SpringUnhandledExceptionHandler(testProjectApiErrors, generalUtils, springUtilsSpy));
}
 
Example #26
Source File: SpringApiExceptionHandlerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeMethod() {
    projectApiErrorsMock = mock(ProjectApiErrors.class);
    listenerList = new ApiExceptionHandlerListenerList(Collections.<ApiExceptionHandlerListener>emptyList());
    generalUtils = ApiExceptionHandlerUtils.DEFAULT_IMPL;
    springUtils = SpringApiExceptionHandlerUtils.DEFAULT_IMPL;
    handlerSpy = spy(new SpringApiExceptionHandler(projectApiErrorsMock, listenerList, generalUtils, springUtils));
}
 
Example #27
Source File: OneOffSpringWebMvcFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void constructor_throws_IllegalArgumentException_if_passed_null_projectApiErrors() {
    // when
    Throwable ex = Assertions.catchThrowable(
        () -> new OneOffSpringWebMvcFrameworkExceptionHandlerListener(null, ApiExceptionHandlerUtils.DEFAULT_IMPL)
    );

    // then
    assertThat(ex).isInstanceOf(IllegalArgumentException.class);
}
 
Example #28
Source File: OneOffSpringWebMvcFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void constructor_sets_projectApiErrors_and_utils_to_passed_in_args() {
    // given
    ProjectApiErrors projectErrorsMock = mock(ProjectApiErrors.class);
    ApiExceptionHandlerUtils utilsMock = mock(ApiExceptionHandlerUtils.class);

    // when
    OneOffSpringWebMvcFrameworkExceptionHandlerListener
        impl = new OneOffSpringWebMvcFrameworkExceptionHandlerListener(projectErrorsMock, utilsMock);

    // then
    assertThat(impl.projectApiErrors).isSameAs(projectErrorsMock);
    assertThat(impl.utils).isSameAs(utilsMock);
}
 
Example #29
Source File: OneOffSpringCommonFrameworkExceptionHandlerListener.java    From backstopper with Apache License 2.0 5 votes vote down vote up
/**
 * @param projectApiErrors The {@link ProjectApiErrors} that should be used by this instance when finding {@link
 *                         ApiError}s. Cannot be null.
 * @param utils            The {@link ApiExceptionHandlerUtils} that should be used by this instance. You can pass
 *                         in {@link ApiExceptionHandlerUtils#DEFAULT_IMPL} if you don't need custom logic.
 */
public OneOffSpringCommonFrameworkExceptionHandlerListener(ProjectApiErrors projectApiErrors,
                                                           ApiExceptionHandlerUtils utils) {
    if (projectApiErrors == null) {
        throw new IllegalArgumentException("ProjectApiErrors cannot be null");
    }

    if (utils == null) {
        throw new IllegalArgumentException("ApiExceptionHandlerUtils cannot be null.");
    }

    this.projectApiErrors = projectApiErrors;
    this.utils = utils;
}
 
Example #30
Source File: SpringUnhandledExceptionHandler.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Inject
public SpringUnhandledExceptionHandler(ProjectApiErrors projectApiErrors,
                                       ApiExceptionHandlerUtils generalUtils,
                                       SpringApiExceptionHandlerUtils springUtils) {
    super(projectApiErrors, generalUtils);
    this.springUtils = springUtils;
    this.singletonGenericServiceError = Collections.singleton(projectApiErrors.getGenericServiceError());
    this.genericServiceErrorHttpStatusCode = projectApiErrors.getGenericServiceError().getHttpStatusCode();
}