當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。