com.nike.backstopper.apierror.ApiErrorBase Java Examples

The following examples show how to use com.nike.backstopper.apierror.ApiErrorBase. 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: ProjectApiErrorsTestBaseTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test
public void verifyGetStatusCodePriorityOrderMethodContainsAllRelevantCodes_throws_AssertionError_if_it_finds_bad_state() {
    // given
    final ProjectApiErrorsTestBase base = new ProjectApiErrorsTestBase() {
        @Override
        protected ProjectApiErrors getProjectApiErrors() {
            return ProjectApiErrorsForTesting.withProjectSpecificData(Arrays.<ApiError>asList(
                new ApiErrorBase("FOOBAR", 42, "foo", 123456)
            ), ProjectSpecificErrorCodeRange.ALLOW_ALL_ERROR_CODES);
        }
    };

    // when
    Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            base.verifyGetStatusCodePriorityOrderMethodContainsAllRelevantCodes();
        }
    });

    // then
    assertThat(ex)
        .isInstanceOf(AssertionError.class)
        .hasMessageContaining("getStatusCodePriorityOrder() did not contain HTTP Status Code: 123456");
}
 
Example #2
Source File: AbstractOktaStateHandler.java    From cerberus with Apache License 2.0 6 votes vote down vote up
/**
 * Handles all unknown states that are not specifically dealt with by the other state handlers and
 * reports a relevant API Error for the state
 *
 * @param typedUnknownResponse - Authentication response from the Completable Future
 */
public void handleUnknown(AuthenticationResponse typedUnknownResponse) {

  String status = typedUnknownResponse.getStatusString();
  String message =
      "MFA is required. Please confirm that you are enrolled in a supported MFA device.";
  if (STATUS_ERRORS.containsKey(status)) {
    message = STATUS_ERRORS.get(status);
  }

  throw ApiException.newBuilder()
      .withApiErrors(
          new ApiErrorBase(
              DefaultApiError.AUTH_FAILED.getName(),
              DefaultApiError.AUTH_FAILED.getErrorCode(),
              message,
              DefaultApiError.AUTH_FAILED.getHttpStatusCode()))
      .build();
}
 
Example #3
Source File: BackstopperRiposteFrameworkErrorHandlerListenerTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void constructor_sets_projectApiErrors_to_passed_in_arg() {
    // given
    ProjectApiErrors projectErrorsMock = mock(ProjectApiErrors.class);
    ApiError temporaryError = new ApiErrorBase("temp_error_for_test", 42, "temporary error", 503);
    ApiError malformedReqError = new ApiErrorBase("malformed_error_for_test", 52, "malformed error", 400);
    doReturn(temporaryError).when(projectErrorsMock).getTemporaryServiceProblemApiError();
    doReturn(malformedReqError).when(projectErrorsMock).getMalformedRequestApiError();

    // when
    BackstopperRiposteFrameworkErrorHandlerListener
        impl = new BackstopperRiposteFrameworkErrorHandlerListener(projectErrorsMock);

    // then
    assertThat(impl.projectApiErrors).isSameAs(projectErrorsMock);
}
 
Example #4
Source File: VerifyMiscellaneousFunctionalityComponentTest.java    From riposte with Apache License 2.0 6 votes vote down vote up
@Test
public void verify_proxy_router_response_modification_works_as_expected() throws IOException, InterruptedException {

    ExtractableResponse response =
        given()
            .baseUri("http://127.0.0.1")
            .port(serverConfig.endpointsPort())
            .basePath(ProxyRouterResponseModificationEndpoint.MATCHING_PATH)
            .log().all()
        .when()
            .get()
        .then()
            .log().headers()
            .extract();

    ApiError unmodifiedError = EmptyMetadataErrorThrower.ERROR_NO_METADATA;
    assertThat(response.statusCode()).isEqualTo(ProxyRouterResponseModificationEndpoint.MODIFIED_HTTP_STATUS_RESPONSE_CODE);
    assertThat(response.header(ProxyRouterResponseModificationEndpoint.ORIG_HTTP_STATUS_CODE_RESPONSE_HEADER_KEY))
        .isEqualTo(String.valueOf(unmodifiedError.getHttpStatusCode()));
    ApiError expectedModifiedError = new ApiErrorBase(unmodifiedError.getName(), unmodifiedError.getErrorCode(), unmodifiedError.getMessage(),
                                                      ProxyRouterResponseModificationEndpoint.MODIFIED_HTTP_STATUS_RESPONSE_CODE);
    verifyErrorReceived(response, expectedModifiedError);
    assertThat(response.asString()).doesNotContain("metadata");
}
 
Example #5
Source File: ApiExceptionHandlerListenerResultTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
private void verifyErrors(ApiExceptionHandlerListenerResult val, SortedApiErrorSet expectedErrors) {
    if (expectedErrors == null) {
        assertThat(val.errors)
            .isNotNull()
            .isEmpty();
    }
    else {
        assertThat(val.errors).isEqualTo(expectedErrors);
    }

    // verify mutability
    ApiError newError = new ApiErrorBase(UUID.randomUUID().toString(), "foo", "bar", 400);
    // and when
    val.errors.add(newError);
    // then
    assertThat(val.errors).contains(newError);
}
 
Example #6
Source File: ProjectApiErrorsTestBase.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void verifyErrorsAreInRangeShouldThrowExceptionIfListIncludesErrorOutOfRange() {
    ProjectApiErrorsForTesting.withProjectSpecificData(
        Collections.<ApiError>singletonList(new ApiErrorBase("blah", 1, "stuff", 400)),
        new ProjectSpecificErrorCodeRange() {
            @Override
            public boolean isInRange(ApiError error) {
                return "42".equals(error.getErrorCode());
            }

            @Override
            public String getName() {
                return "test error range";
            }
        }
    );
}
 
Example #7
Source File: ApiErrorUtilTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test
@DataProvider(value = {
        "false | true  | false",
        "false | false | false",
        "true  | false | false",
        "true  | true  | true"
}, splitBy = "\\|")
public void equals_null_other_class(boolean firstClassNull, boolean secondClassNull, boolean expectedValue) {
    // given
    ApiErrorBase apiError = new ApiErrorBase("name", 42, "errorMessage", 400);

    String otherClass = secondClassNull ? null : "";

    // then
    assertThat(isApiErrorEqual(firstClassNull ? null : apiError, otherClass)).isEqualTo(expectedValue);
}
 
Example #8
Source File: ApiErrorUtilTest.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test
public void generate_api_error_hashcode_generates_expected_hashcodes() {
    // given
    Map<String, Object> metadata = MapBuilder.<String, Object>builder().put("foo", UUID.randomUUID().toString()).build();
    ApiErrorBase apiErrorBase = new ApiErrorBase("name", 42, "errorMessag", 400, metadata);
    ApiErrorBase apiErrorBaseCopy = new ApiErrorBase("name", 42, "errorMessag", 400, metadata);

    // then
    assertThat(ApiErrorUtil.generateApiErrorHashCode(apiErrorBase))
            .isEqualTo(Objects.hash(
                    apiErrorBase.getName(),
                    apiErrorBase.getErrorCode(),
                    apiErrorBase.getMessage(),
                    apiErrorBase.getHttpStatusCode(),
                    apiErrorBase.getMetadata())
            );

    assertThat(apiErrorBase).isEqualTo(apiErrorBaseCopy);
    assertThat(ApiErrorUtil.generateApiErrorHashCode(apiErrorBase))
            .isEqualTo(ApiErrorUtil.generateApiErrorHashCode(apiErrorBaseCopy));
}
 
Example #9
Source File: ProjectApiErrorsTestBase.java    From backstopper with Apache License 2.0 6 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void verifyErrorsAreInRangeShouldThrowExceptionIfListIncludesErrorOutOfRange() {
    ProjectApiErrorsForTesting.withProjectSpecificData(
        Collections.<ApiError>singletonList(new ApiErrorBase("blah", 1, "stuff", 400)),
        new ProjectSpecificErrorCodeRange() {
            @Override
            public boolean isInRange(ApiError error) {
                return "42".equals(error.getErrorCode());
            }

            @Override
            public String getName() {
                return "test error range";
            }
        }
    );
}
 
Example #10
Source File: ApiErrorUtilTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
@DataProvider(value = {
        "true  | false | false | false | false | false ",
        "false | false | false | false | false | true  ",
        "false | true  | false | false | false | false ",
        "false | false | true  | false | false | false ",
        "false | false | false | true  | false | false ",
        "false | false | false | false | true  | false ",
}, splitBy = "\\|")
public void equals_returns_expected_result(boolean changeName, boolean changeErrorCode, boolean changeErrorMessage, boolean changeHttpStatusCode, boolean changeMetadata, boolean isEqual) {
    // given
    String name = "someName";
    int errorCode = 42;
    String message = "some error";
    int httpStatusCode = 400;
    Map<String, Object> metadata = MapBuilder.<String, Object>builder().put("foo", UUID.randomUUID().toString()).build();
    Map<String, Object> metadata2 = MapBuilder.<String, Object>builder().put("foo", UUID.randomUUID().toString()).build();

    ApiErrorBase aeb = new ApiErrorBase(name, errorCode, message, httpStatusCode, metadata);

    ApiErrorBase aeb2 = new ApiErrorBase(
            changeName ? "name2" : name,
            changeErrorCode ? 43 : errorCode,
            changeErrorMessage ? "message2" : message,
            changeHttpStatusCode ? 500 : httpStatusCode,
            changeMetadata ? metadata2 : metadata);

    // then
    assertThat(isApiErrorEqual(aeb, aeb2)).isEqualTo(isEqual);
}
 
Example #11
Source File: ProjectApiErrorsTestBase.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyErrorsAreInRangeShouldNotThrowExceptionIfListIncludesCoreApiErrorWrapper() {
    ApiError coreApiError = BarebonesCoreApiErrorForTesting.GENERIC_SERVICE_ERROR;
    final ApiError coreApiErrorWrapper = new ApiErrorBase("blah", coreApiError.getErrorCode(), coreApiError.getMessage(), coreApiError.getHttpStatusCode());
    ProjectApiErrors pae = ProjectApiErrorsForTesting.withProjectSpecificData(Collections.singletonList(coreApiErrorWrapper), null);

    assertThat(pae, notNullValue());
    assertThat(pae.getProjectApiErrors().contains(coreApiErrorWrapper), is(true));
}
 
Example #12
Source File: ProjectApiErrorsTestBase.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void verifyErrorsAreInRangeShouldNotThrowExceptionIfListIncludesCoreApiErrorWrapper() {
    ApiError coreApiError = BarebonesCoreApiErrorForTesting.GENERIC_SERVICE_ERROR;
    final ApiError coreApiErrorWrapper =
        new ApiErrorBase("blah", coreApiError.getErrorCode(), coreApiError.getMessage(),
                         coreApiError.getHttpStatusCode());
    ProjectApiErrors pae =
        ProjectApiErrorsForTesting.withProjectSpecificData(Collections.singletonList(coreApiErrorWrapper), null);

    assertThat(pae, notNullValue());
    assertThat(pae.getProjectApiErrors().contains(coreApiErrorWrapper), is(true));
}
 
Example #13
Source File: ApiErrorUtilTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void equals_same_object_is_true() {
    // given
    ApiErrorBase apiError = new ApiErrorBase("name", 42, "errorMessage", 400);

    // then
    assertThat(isApiErrorEqual(apiError, apiError)).isTrue();
}
 
Example #14
Source File: ProjectApiErrorsTestBaseTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldNotContainDuplicateNamedApiErrors_blows_up_if_it_finds_duplicate_ApiErrors() {
    // given
    final ProjectApiErrorsTestBase base = new ProjectApiErrorsTestBase() {
        @Override
        protected ProjectApiErrors getProjectApiErrors() {
            return ProjectApiErrorsForTesting.withProjectSpecificData(Arrays.<ApiError>asList(
                new ApiErrorBase("DUPNAME1", 42, "foo", 400),
                new ApiErrorBase("DUPNAME1", 4242, "bar", 500),
                new ApiErrorBase("DUPNAME2", 52, "foo2", 401),
                new ApiErrorBase("DUPNAME2", 5252, "bar2", 501),
                new ApiErrorBase("DUPNAME2", 525252, "baz", 900)
            ), ProjectSpecificErrorCodeRange.ALLOW_ALL_ERROR_CODES);
        }
    };

    // when
    Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            base.shouldNotContainDuplicateNamedApiErrors();
        }
    });

    // then
    assertThat(ex)
        .isInstanceOf(AssertionError.class)
        .hasMessageContaining("[DUPNAME1, 2], [DUPNAME2, 3]");
}
 
Example #15
Source File: ProjectApiErrorsTestBaseTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void allErrorsShouldBeCoreApiErrorsOrCoreApiErrorWrappersOrFallInProjectSpecificErrorRange_works_for_valid_cases() {
    // given
    final ApiError coreError = BarebonesCoreApiErrorForTesting.TYPE_CONVERSION_ERROR;
    final ApiError coreErrorWrapper = new ApiErrorBase(coreError, "FOOBAR");
    final String customErrorCode = UUID.randomUUID().toString();
    final ApiError validErrorInRange = new ApiErrorBase("WHEEE", customErrorCode, "whee message", 400);
    final ProjectSpecificErrorCodeRange restrictiveErrorCodeRange = new ProjectSpecificErrorCodeRange() {
        @Override
        public boolean isInRange(ApiError error) {
            return customErrorCode.equals(error.getErrorCode());
        }

        @Override
        public String getName() {
            return "RANGE_FOR_TESTING";
        }
    };
    final ProjectApiErrorsTestBase base = new ProjectApiErrorsTestBase() {
        @Override
        protected ProjectApiErrors getProjectApiErrors() {
            return ProjectApiErrorsForTesting.withProjectSpecificData(Arrays.asList(coreErrorWrapper, validErrorInRange),
                                                                      restrictiveErrorCodeRange);
        }
    };

    // when
    Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            base.allErrorsShouldBeCoreApiErrorsOrCoreApiErrorWrappersOrFallInProjectSpecificErrorRange();
        }
    });

    // then
    assertThat(ex).isNull();
}
 
Example #16
Source File: ProjectApiErrorsTestBaseTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@Test
public void allErrorsShouldBeCoreApiErrorsOrCoreApiErrorWrappersOrFallInProjectSpecificErrorRange_should_explode_if_there_are_non_core_errors_and_range_is_null() {
    // given
    final ApiError nonCoreError = new ApiErrorBase("FOO", UUID.randomUUID().toString(), "foo message", 500);
    final List<ApiError> coreErrors = Arrays.<ApiError>asList(BarebonesCoreApiErrorForTesting.values());
    final List<ApiError> allProjectErrors = new ArrayList<>(coreErrors);
    allProjectErrors.add(nonCoreError);
    final ProjectApiErrors projectApiErrorsMock = mock(ProjectApiErrors.class);
    final ProjectApiErrorsTestBase base = new ProjectApiErrorsTestBase() {
        @Override
        protected ProjectApiErrors getProjectApiErrors() {
            return projectApiErrorsMock;
        }
    };
    doReturn(null).when(projectApiErrorsMock).getProjectSpecificErrorCodeRange();
    doReturn(coreErrors).when(projectApiErrorsMock).getCoreApiErrors();
    doReturn(false).when(projectApiErrorsMock).isWrapperAroundCoreError(any(ApiError.class), any(List.class));
    doReturn(allProjectErrors).when(projectApiErrorsMock).getProjectApiErrors();

    // when
    Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            base.allErrorsShouldBeCoreApiErrorsOrCoreApiErrorWrappersOrFallInProjectSpecificErrorRange();
        }
    });

    // then
    assertThat(ex)
        .isInstanceOf(AssertionError.class)
        .hasMessageContaining(nonCoreError.getErrorCode());
}
 
Example #17
Source File: BackstopperRiposteFrameworkErrorHandlerListener.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Inject
public BackstopperRiposteFrameworkErrorHandlerListener(@NotNull ProjectApiErrors projectApiErrors) {
    //noinspection ConstantConditions
    if (projectApiErrors == null)
        throw new IllegalArgumentException("ProjectApiErrors cannot be null");

    this.projectApiErrors = projectApiErrors;

    CIRCUIT_BREAKER_GENERIC_API_ERROR =
        new ApiErrorBase(projectApiErrors.getTemporaryServiceProblemApiError(), "CIRCUIT_BREAKER");
    CIRCUIT_BREAKER_OPEN_API_ERROR =
        new ApiErrorBase(projectApiErrors.getTemporaryServiceProblemApiError(), "CIRCUIT_BREAKER_OPEN");
    CIRCUIT_BREAKER_TIMEOUT_API_ERROR =
        new ApiErrorBase(projectApiErrors.getTemporaryServiceProblemApiError(), "CIRCUIT_BREAKER_TIMEOUT");

    ApiError malformedReqError = projectApiErrors.getMalformedRequestApiError();
    // Too long line can keep generic malformed request ApiError error code, message, and HTTP status code (400),
    //      but we'll give it a new name for the logs and some cause metadata so the caller knows what went wrong.
    TOO_LONG_FRAME_LINE_API_ERROR_BASE = new ApiErrorWithMetadata(
        new ApiErrorBase(malformedReqError, "TOO_LONG_HTTP_LINE"),
        Pair.of("cause", TOO_LONG_FRAME_LINE_METADATA_MESSAGE)
    );
    // Too long headers should keep the error code and message of malformed request ApiError, but use 431 HTTP
    //      status code (see https://tools.ietf.org/html/rfc6585#page-4), and we'll give it a new name for the logs
    //      and some cause metadata so the caller knows what went wrong.
    TOO_LONG_FRAME_HEADER_API_ERROR_BASE = new ApiErrorWithMetadata(
        new ApiErrorBase(
            "TOO_LONG_HEADERS", malformedReqError.getErrorCode(), malformedReqError.getMessage(),
            431, malformedReqError.getMetadata()
        ),
        Pair.of("cause", TOO_LONG_FRAME_HEADER_METADATA_MESSAGE)
    );
}
 
Example #18
Source File: OneOffSpringWebFluxFrameworkExceptionHandlerListener.java    From backstopper with Apache License 2.0 5 votes vote down vote up
protected @NotNull ApiError generateGenericApiErrorForResponseStatusCode(int statusCode) {
    // Reuse the error code for the generic bad request ApiError, unless the status code is greater than or equal
    //      to 500. If status code >= 500, then use the generic service error status code instead.
    String errorCodeToUse = projectApiErrors.getGenericBadRequestApiError().getErrorCode();
    if (statusCode >= 500) {
        errorCodeToUse = projectApiErrors.getGenericServiceError().getErrorCode();
    }

    return new ApiErrorBase(
        "GENERIC_API_ERROR_FOR_RESPONSE_STATUS_CODE_" + statusCode,
        errorCodeToUse,
        "An error occurred that resulted in response status code " + statusCode,
        statusCode
    );
}
 
Example #19
Source File: BackstopperSpringWebFluxComponentTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "451",
    "506"
}, splitBy = "\\|")
@Test
public void verify_generic_ResponseStatusCode_exception_with_unknown_status_code_results_in_synthetic_ApiError(
    int unknownStatusCode
) {
    ExtractableResponse response =
        given()
            .baseUri("http://localhost")
            .port(SERVER_PORT)
            .log().all()
            .when()
            .header("desired-status-code", unknownStatusCode)
            .get(RESPONSE_STATUS_EX_FOR_SPECIFIC_STATUS_CODE_ENDPOINT)
            .then()
            .log().all()
            .extract();

    String expectedErrorCodeUsed = (unknownStatusCode >= 500)
                                   ? projectApiErrors.getGenericServiceError().getErrorCode()
                                   : projectApiErrors.getGenericBadRequestApiError().getErrorCode();

    ApiError expectedError = new ApiErrorBase(
        "GENERIC_API_ERROR_FOR_RESPONSE_STATUS_CODE_" + unknownStatusCode,
        expectedErrorCodeUsed,
        "An error occurred that resulted in response status code " + unknownStatusCode,
        unknownStatusCode
    );

    verifyErrorReceived(response, expectedError);
    ResponseStatusException ex = verifyResponseStatusExceptionSeenByBackstopper(
        ResponseStatusException.class, unknownStatusCode
    );
    verifyHandlingResult(
        expectedError,
        Pair.of("exception_message", quotesToApostrophes(ex.getMessage()))
    );
}
 
Example #20
Source File: OneOffSpringWebFluxFrameworkExceptionHandlerListenerTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "418",
    "509"
})
@Test
public void handleFluxExceptions_handles_generic_ResponseStatusException_by_returning_synthetic_ApiError_if_status_code_is_unknown(
    int desiredStatusCode
) {
    // given
    ResponseStatusException ex = new ResponseStatusException(
        HttpStatus.resolve(desiredStatusCode), "Some ResponseStatusException reason"
    );
    List<Pair<String, String>> expectedExtraDetailsForLogging = new ArrayList<>();
    ApiExceptionHandlerUtils.DEFAULT_IMPL.addBaseExceptionMessageToExtraDetailsForLogging(
        ex, expectedExtraDetailsForLogging
    );

    String expectedErrorCode = (desiredStatusCode >= 500)
                               ? testProjectApiErrors.getGenericServiceError().getErrorCode()
                               : testProjectApiErrors.getGenericBadRequestApiError().getErrorCode();

    ApiError expectedError = new ApiErrorBase(
        "GENERIC_API_ERROR_FOR_RESPONSE_STATUS_CODE_" + desiredStatusCode,
        expectedErrorCode,
        "An error occurred that resulted in response status code " + desiredStatusCode,
        desiredStatusCode
    );

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

    // then
    validateResponse(
        result,
        true,
        singleton(expectedError),
        expectedExtraDetailsForLogging
    );
}
 
Example #21
Source File: SpringWebfluxApiExceptionHandlerUtilsTest.java    From backstopper with Apache License 2.0 5 votes vote down vote up
@DataProvider(value = {
    "true   |   true",
    "true   |   false",
    "false  |   true",
    "false  |   false",
}, splitBy = "\\|")
@Test
public void serializeErrorContractToString_uses_JsonUtilWithDefaultErrorContractDTOSupport_to_serialize_error_contract(
    boolean errorCodeIsAnInt, boolean includeExtraMetadata
) {
    // given
    List<ApiError> apiErrors = Arrays.asList(
        new ApiErrorBase(
            "FOO",
            (errorCodeIsAnInt) ? "42" : "fortytwo",
            "foo message",
            400,
            (includeExtraMetadata)
            ? MapBuilder.builder("foo", (Object)"bar").put("baz", "bat").build()
            : null
        ),
        new ApiErrorBase(
            "BAR",
            (errorCodeIsAnInt) ? "123" : "blahblah",
            "bar message",
            400,
            (includeExtraMetadata)
            ? MapBuilder.builder("stuff", (Object)"things").put("yay", "whee").build()
            : null
        )
    );
    DefaultErrorContractDTO errorContract = new DefaultErrorContractDTO(UUID.randomUUID().toString(), apiErrors);

    // when
    String result = utilsSpy.serializeErrorContractToString(errorContract);

    // then
    assertThat(result).isEqualTo(JsonUtilWithDefaultErrorContractDTOSupport.writeValueAsString(errorContract));
}
 
Example #22
Source File: ProjectApiErrorsTestBase.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void verifyErrorsAreInRangeShouldThrowExceptionIfListIncludesNonCoreApiErrorAndRangeIsNull() {
    ProjectApiErrorsForTesting.withProjectSpecificData(Collections.<ApiError>singletonList(new ApiErrorBase("blah", 99001, "stuff", 400)), null);
}
 
Example #23
Source File: SanityCheckComponentTest.java    From backstopper with Apache License 2.0 4 votes vote down vote up
SanityCheckProjectApiError(int errorCode, String message, int httpStatusCode) {
    this(new ApiErrorBase(
        "delegated-to-enum-wrapper-" + UUID.randomUUID().toString(), errorCode, message, httpStatusCode
    ));
}
 
Example #24
Source File: BackstopperSpringWebFluxComponentTest.java    From backstopper with Apache License 2.0 4 votes vote down vote up
ComponentTestProjectApiError(int errorCode, String message, int httpStatusCode) {
    this(new ApiErrorBase(
        "delegated-to-enum-wrapper-" + UUID.randomUUID().toString(), errorCode, message, httpStatusCode
    ));
}
 
Example #25
Source File: ProjectApiErrorsTestBaseTest.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@Test
public void allErrorsShouldBeCoreApiErrorsOrCoreApiErrorWrappersOrFallInProjectSpecificErrorRange_should_explode_if_there_are_non_core_errors_that_are_also_not_in_range() {
    // given
    final ApiError nonCoreError = new ApiErrorBase("FOO", UUID.randomUUID().toString(), "foo message", 500);
    final List<ApiError> coreErrors = Arrays.<ApiError>asList(BarebonesCoreApiErrorForTesting.values());
    final List<ApiError> allProjectErrors = new ArrayList<>(coreErrors);
    allProjectErrors.add(nonCoreError);
    final ProjectApiErrors projectApiErrorsMock = mock(ProjectApiErrors.class);
    final ProjectApiErrorsTestBase base = new ProjectApiErrorsTestBase() {
        @Override
        protected ProjectApiErrors getProjectApiErrors() {
            return projectApiErrorsMock;
        }
    };
    ProjectSpecificErrorCodeRange range = new ProjectSpecificErrorCodeRange() {
        @Override
        public boolean isInRange(ApiError error) {
            return false;
        }

        @Override
        public String getName() {
            return "RANGE_FOR_TESTING";
        }
    };
    doReturn(range).when(projectApiErrorsMock).getProjectSpecificErrorCodeRange();
    doReturn(coreErrors).when(projectApiErrorsMock).getCoreApiErrors();
    doReturn(false).when(projectApiErrorsMock).isWrapperAroundCoreError(any(ApiError.class), any(List.class));
    doReturn(allProjectErrors).when(projectApiErrorsMock).getProjectApiErrors();

    // when
    Throwable ex = catchThrowable(new ThrowableAssert.ThrowingCallable() {
        @Override
        public void call() throws Throwable {
            base.allErrorsShouldBeCoreApiErrorsOrCoreApiErrorWrappersOrFallInProjectSpecificErrorRange();
        }
    });

    // then
    assertThat(ex)
        .isInstanceOf(AssertionError.class)
        .hasMessageContaining(nonCoreError.getErrorCode());
}
 
Example #26
Source File: ProjectApiErrorsTestBase.java    From backstopper with Apache License 2.0 4 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void verifyErrorsAreInRangeShouldThrowExceptionIfListIncludesNonCoreApiErrorAndRangeIsNull() {
    ProjectApiErrorsForTesting
        .withProjectSpecificData(Collections.<ApiError>singletonList(new ApiErrorBase("blah", 99001, "stuff", 400)),
                                 null);
}
 
Example #27
Source File: SanityCheckComponentTest.java    From backstopper with Apache License 2.0 4 votes vote down vote up
SanityCheckProjectApiError(int errorCode, String message, int httpStatusCode) {
    this(new ApiErrorBase(
        "delegated-to-enum-wrapper-" + UUID.randomUUID().toString(), errorCode, message, httpStatusCode
    ));
}