当前位置: 首页>>代码示例>>Java>>正文


Java DefaultErrorDTO类代码示例

本文整理汇总了Java中com.nike.backstopper.model.DefaultErrorDTO的典型用法代码示例。如果您正苦于以下问题:Java DefaultErrorDTO类的具体用法?Java DefaultErrorDTO怎么用?Java DefaultErrorDTO使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DefaultErrorDTO类属于com.nike.backstopper.model包,在下文中一共展示了DefaultErrorDTO类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleException_uses_getGenericServiceError_from_projectApiErrors

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
@Test
public void handleException_uses_getGenericServiceError_from_projectApiErrors() {
    // given
    ApiError expectedApiErrorMatch = testProjectApiErrors.getGenericServiceError();

    // when
    ErrorResponseInfo<TestDTO> result = exHandlerSpy.handleException(new Exception(), reqMock);

    // then
    DefaultErrorContractDTO errorContract = result.frameworkRepresentationObj.erv;
    assertThat(errorContract.errors).hasSize(1);
    DefaultErrorDTO error = errorContract.errors.get(0);
    assertThat(error.code).isEqualTo(expectedApiErrorMatch.getErrorCode());
    assertThat(error.message).isEqualTo(expectedApiErrorMatch.getMessage());
    assertThat(error.metadata).isEqualTo(expectedApiErrorMatch.getMetadata());
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:17,代码来源:UnhandledExceptionHandlerBaseTest.java

示例2: errorResponseViewMatches

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
private Matcher<DefaultErrorContractDTO> errorResponseViewMatches(final DefaultErrorContractDTO expectedErrorContract) {
    return new CustomTypeSafeMatcher<DefaultErrorContractDTO>("a matching ErrorResponseView"){
        @Override
        protected boolean matchesSafely(DefaultErrorContractDTO item) {
            if (!(item.errors.size() == expectedErrorContract.errors.size()))
                return false;

            for (int i = 0; i < item.errors.size(); i++) {
                DefaultErrorDTO itemError = item.errors.get(i);
                DefaultErrorDTO expectedError = item.errors.get(i);
                if (!itemError.code.equals(expectedError.code))
                    return false;
                if (!itemError.message.equals(expectedError.message))
                    return false;
            }

            return item.error_id.equals(expectedErrorContract.error_id);
        }
    };
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:21,代码来源:UnhandledExceptionHandlerBaseTest.java

示例3: verifyErrorResponse

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
/**
 * Verifies that the given MvcResult's {@link org.springframework.test.web.servlet.MvcResult#getResponse()} has the
 * expected HTTP status code, that its contents can be converted to the appropriate {@link DefaultErrorContractDTO} with the
 * expected errors (as per the default error handling contract), and that the MvcResult's {@link
 * org.springframework.test.web.servlet.MvcResult#getResolvedException()} matches the given expectedExceptionType.
 */
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
protected void verifyErrorResponse(MvcResult result, ProjectApiErrors projectApiErrors,
                                   List<ApiError> expectedErrors, Class<? extends Exception> expectedExceptionType)
    throws IOException {
    Integer expectedStatusCode = projectApiErrors.determineHighestPriorityHttpStatusCode(expectedErrors);
    expectedErrors = projectApiErrors.getSublistContainingOnlyHttpStatusCode(expectedErrors, expectedStatusCode);
    MockHttpServletResponse response = result.getResponse();
    assertThat(response.getStatus(), is(expectedStatusCode));
    DefaultErrorContractDTO details =
        objectMapper.readValue(response.getContentAsString(), DefaultErrorContractDTO.class);
    assertNotNull(details);
    assertNotNull(details.error_id);
    assertNotNull(details.errors);
    assertThat(details.errors.size(), is(expectedErrors.size()));
    List<Pair<String, String>> expectedErrorsAsPairs = convertToCodeAndMessagePairs(expectedErrors);
    for (DefaultErrorDTO errorView : details.errors) {
        assertTrue(expectedErrorsAsPairs.contains(Pair.of(errorView.code, errorView.message)));
    }
    assertNotNull(result.getResolvedException());
    Assertions.assertThat(result.getResolvedException()).isInstanceOf(expectedExceptionType);
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:28,代码来源:BaseSpringEnabledValidationTestCase.java

示例4: verifyErrorReceived

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
private void verifyErrorReceived(ExtractableResponse response, Collection<ApiError> expectedErrors, int expectedHttpStatusCode) {
    assertThat(response.statusCode()).isEqualTo(expectedHttpStatusCode);
    try {
        DefaultErrorContractDTO errorContract = objectMapper.readValue(response.asString(), DefaultErrorContractDTO.class);
        assertThat(errorContract.error_id).isNotEmpty();
        assertThat(UUID.fromString(errorContract.error_id)).isNotNull();
        assertThat(errorContract.errors).hasSameSizeAs(expectedErrors);
        for (ApiError apiError : expectedErrors) {
            DefaultErrorDTO matchingError = findErrorMatching(errorContract, apiError);
            assertThat(matchingError).isNotNull();
            assertThat(matchingError.code).isEqualTo(apiError.getErrorCode());
            assertThat(matchingError.message).isEqualTo(apiError.getMessage());
            assertThat(matchingError.metadata).isEqualTo(apiError.getMetadata());
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:19,代码来源:VerifyExpectedErrorsAreReturnedComponentTest.java

示例5: writeValueAsString_serializes_Error_with_metadata_if_metadata_exists

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
@Test
public void writeValueAsString_serializes_Error_with_metadata_if_metadata_exists() throws IOException {
    // given
    Map<String, Object> metadata = new HashMap<>();
    metadata.put("meta", UUID.randomUUID().toString());

    DefaultErrorDTO error = new DefaultErrorDTO(42, "bar", metadata);

    // when
    String resultString = JsonUtilWithDefaultErrorContractDTOSupport.writeValueAsString(error);

    // then
    assertThat(resultString).contains("metadata");
    DefaultErrorDTO result = objectMapper.readValue(resultString, DefaultErrorDTO.class);
    verifyErrorsMatch(result, error);
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:17,代码来源:JsonUtilWithDefaultErrorContractDTOSupportTest.java

示例6: writeValueAsString_serializes_ErrorContract_with_metadata_if_metadata_exists

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
@Test
public void writeValueAsString_serializes_ErrorContract_with_metadata_if_metadata_exists() throws IOException {
    // given
    Map<String, Object> metadata = new HashMap<>();
    metadata.put("meta", UUID.randomUUID().toString());
    DefaultErrorDTO withMetadata = new DefaultErrorDTO(42, UUID.randomUUID().toString(), metadata);
    DefaultErrorDTO noMetadata = new DefaultErrorDTO(43, UUID.randomUUID().toString(), null);
    DefaultErrorContractDTO
        contract = new DefaultErrorContractDTO(UUID.randomUUID().toString(), Arrays.asList(withMetadata, noMetadata), null);

    // when
    String resultString = JsonUtilWithDefaultErrorContractDTOSupport.writeValueAsString(contract);

    // then
    DefaultErrorContractDTO result = objectMapper.readValue(resultString, DefaultErrorContractDTO.class);
    verifyErrorContractsMatch(result, contract);
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:18,代码来源:JsonUtilWithDefaultErrorContractDTOSupportTest.java

示例7: writeValueAsString_serializes_Error_with_code_as_string_if_code_is_not_parseable_to_an_integer

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
@DataProvider(value = {
    "foo",
    "42.42"
}, splitBy = "\\|")
@Test
public void writeValueAsString_serializes_Error_with_code_as_string_if_code_is_not_parseable_to_an_integer(String notAnInt) throws IOException {
    // given
    DefaultErrorDTO error = new DefaultErrorDTO(notAnInt, "bar", null);

    // when
    String resultString = JsonUtilWithDefaultErrorContractDTOSupport.writeValueAsString(error);

    // then
    assertThat(resultString).contains("\"code\":\"" + notAnInt + "\"");
    DefaultErrorDTO result = objectMapper.readValue(resultString, DefaultErrorDTO.class);
    verifyErrorsMatch(result, error);
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:18,代码来源:JsonUtilWithDefaultErrorContractDTOSupportTest.java

示例8: verifyExpectedErrors

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
/**
 * Helper method for component tests that verifies that the given {@code response} contains an error contract
 * matching the given collection of {@code expectedErrors} and that the HTTP status code received is the given
 * {@code expectedHttpStatusCode}.
 *
 * @param response The response to check.
 * @param expectedHttpStatusCode The HTTP status code that the response should match.
 * @param expectedErrors The errors that the response should match.
 */
public static void verifyExpectedErrors(ExtractableResponse response, int expectedHttpStatusCode,
                                        Collection<ApiError> expectedErrors) {
    try {
        assertThat(response.statusCode()).isEqualTo(expectedHttpStatusCode);
        DefaultErrorContractDTO errorContract =
            OBJECT_MAPPER.readValue(response.asString(), DefaultErrorContractDTO.class);
        assertThat(errorContract.errors).hasSameSizeAs(expectedErrors);
        for (ApiError expectedError : expectedErrors) {
            Optional<DefaultErrorDTO> matchingError = errorContract.errors.stream().filter(
                error -> (error.code.equals(expectedError.getErrorCode())
                          && error.message .equals(expectedError.getMessage()))
            ).findAny();

            assertThat(matchingError)
                .overridingErrorMessage("Unable to find an error in the response contract that matches: "
                                        + expectedError.getName() + ". Actual response payload: "
                                        + response.asString())
                .isPresent();
        }
    }
    catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:Nike-Inc,项目名称:riposte-microservice-template,代码行数:34,代码来源:TestUtils.java

示例9: containsApiError

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
private boolean containsApiError(Collection<DefaultErrorDTO> errorViews, ApiError error) {
    for (DefaultErrorDTO iev : errorViews) {
        if (iev.code.equals(error.getErrorCode()) && iev.message.equals(error.getMessage()))
            return true;
    }
    return false;
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:8,代码来源:ApiExceptionHandlerBaseTest.java

示例10: findErrorMatching

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
private DefaultErrorDTO findErrorMatching(DefaultErrorContractDTO errorContract, ApiError desiredError) {
    for (DefaultErrorDTO error : errorContract.errors) {
        if (error.code.equals(desiredError.getErrorCode()) && error.message.equals(desiredError.getMessage()))
            return error;
    }

    return null;
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:9,代码来源:VerifyExpectedErrorsAreReturnedComponentTest.java

示例11: serializeAsField

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
@Override
public void serializeAsField(Object bean, JsonGenerator jgen, SerializerProvider prov) throws Exception {
    if (bean instanceof DefaultErrorDTO) {
        DefaultErrorDTO error = (DefaultErrorDTO) bean;
        if (error.metadata == null || error.metadata.isEmpty()) {
            return; // empty metadata. Don't serialize
        }
    }
    super.serializeAsField(bean, jgen, prov);
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:11,代码来源:JsonUtilWithDefaultErrorContractDTOSupport.java

示例12: verifyErrorContractsMatch

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
private void verifyErrorContractsMatch(DefaultErrorContractDTO actual, DefaultErrorContractDTO expected) {
    assertThat(actual.error_id).isEqualTo(expected.error_id);
    assertThat(actual.errors.size()).isEqualTo(expected.errors.size());
    for (int i = 0; i < actual.errors.size(); i++) {
        DefaultErrorDTO actualError = actual.errors.get(i);
        DefaultErrorDTO expectedError = expected.errors.get(i);
        verifyErrorsMatch(actualError, expectedError);
    }
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:10,代码来源:JsonUtilWithDefaultErrorContractDTOSupportTest.java

示例13: writeValueAsString_serializes_Error_without_metadata_if_metadata_is_missing

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
@Test
public void writeValueAsString_serializes_Error_without_metadata_if_metadata_is_missing() throws IOException {
    // given
    DefaultErrorDTO error = new DefaultErrorDTO(42, "bar", null);

    // when
    String resultString = JsonUtilWithDefaultErrorContractDTOSupport.writeValueAsString(error);

    // then
    assertThat(resultString).doesNotContain("metadata");
    DefaultErrorDTO result = objectMapper.readValue(resultString, DefaultErrorDTO.class);
    verifyErrorsMatch(result, error);
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:14,代码来源:JsonUtilWithDefaultErrorContractDTOSupportTest.java

示例14: writeValueAsString_serializes_Error_with_code_as_JSON_number_if_possible

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
@Test
public void writeValueAsString_serializes_Error_with_code_as_JSON_number_if_possible() throws IOException {
    // given
    DefaultErrorDTO error = new DefaultErrorDTO(42, "bar", null);

    // when
    String resultString = JsonUtilWithDefaultErrorContractDTOSupport.writeValueAsString(error);

    // then
    assertThat(resultString).contains("\"code\":42");
    DefaultErrorDTO result = objectMapper.readValue(resultString, DefaultErrorDTO.class);
    verifyErrorsMatch(result, error);
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:14,代码来源:JsonUtilWithDefaultErrorContractDTOSupportTest.java

示例15: verifyResultIsDefaultErrorContract

import com.nike.backstopper.model.DefaultErrorDTO; //导入依赖的package包/类
private void verifyResultIsDefaultErrorContract(String result) throws IOException {
    DefaultErrorContractDTO defaultResponse = objectMapper.readValue(JsonUtilWithDefaultErrorContractDTOSupport.DEFAULT_ERROR_RESPONSE_STRING, DefaultErrorContractDTO.class);
    DefaultErrorContractDTO resultContract = objectMapper.readValue(result, DefaultErrorContractDTO.class);
    assertThat(resultContract.errors)
        .hasSameSizeAs(defaultResponse.errors)
        .isNotEmpty();
    for (int i = 0; i < defaultResponse.errors.size(); i++) {
        DefaultErrorDTO expectedError = defaultResponse.errors.get(i);
        DefaultErrorDTO actualError = resultContract.errors.get(i);
        verifyErrorsMatch(actualError, expectedError);
    }
}
 
开发者ID:Nike-Inc,项目名称:backstopper,代码行数:13,代码来源:JsonUtilWithDefaultErrorContractDTOSupportTest.java


注:本文中的com.nike.backstopper.model.DefaultErrorDTO类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。