Search in sources :

Example 1 with AllErrors

use of gov.cms.qpp.conversion.model.error.AllErrors in project qpp-conversion-tool by CMSgov.

the class ExceptionHandlerControllerV1Test method testTransformExceptionBody.

@Test
void testTransformExceptionBody() {
    TransformException exception = new TransformException("test transform exception", new NullPointerException(), report);
    ResponseEntity<AllErrors> responseEntity = objectUnderTest.handleTransformException(exception);
    assertThat(responseEntity.getBody()).isEqualTo(allErrors);
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Test(org.junit.jupiter.api.Test)

Example 2 with AllErrors

use of gov.cms.qpp.conversion.model.error.AllErrors in project qpp-conversion-tool by CMSgov.

the class ExceptionHandlerControllerV1Test method testTransformExceptionHeaderContentType.

@Test
void testTransformExceptionHeaderContentType() {
    TransformException exception = new TransformException("test transform exception", new NullPointerException(), report);
    ResponseEntity<AllErrors> responseEntity = objectUnderTest.handleTransformException(exception);
    assertThat(responseEntity.getHeaders().getContentType()).isEquivalentAccordingToCompareTo(MediaType.APPLICATION_JSON_UTF8);
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Test(org.junit.jupiter.api.Test)

Example 3 with AllErrors

use of gov.cms.qpp.conversion.model.error.AllErrors in project qpp-conversion-tool by CMSgov.

the class ValidationApiAcceptance method testUnprocessedFiles.

@AcceptanceTest
void testUnprocessedFiles() {
    Response response = given().multiPart("file", PATH.toFile()).when().post("/");
    AllErrors blah = response.getBody().as(AllErrors.class);
    blah.getErrors().stream().flatMap(error -> error.getDetails().stream()).forEach(this::verifyDetail);
}
Also used : Response(io.restassured.response.Response) Assertions.fail(org.junit.jupiter.api.Assertions.fail) AcceptanceTest(gov.cms.qpp.test.annotations.AcceptanceTest) Filter(org.jdom2.filter.Filter) XPathFactory(org.jdom2.xpath.XPathFactory) XmlUtils(gov.cms.qpp.conversion.xml.XmlUtils) NioHelper(gov.cms.qpp.test.helper.NioHelper) Truth.assertThat(com.google.common.truth.Truth.assertThat) XPathExpression(org.jdom2.xpath.XPathExpression) ValidationServiceImpl(gov.cms.qpp.conversion.api.services.ValidationServiceImpl) Detail(gov.cms.qpp.conversion.model.error.Detail) Attribute(org.jdom2.Attribute) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Response(io.restassured.response.Response) Paths(java.nio.file.Paths) RestAssured.given(io.restassured.RestAssured.given) DataConversionException(org.jdom2.DataConversionException) XmlException(gov.cms.qpp.conversion.xml.XmlException) Filters(org.jdom2.filter.Filters) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) Path(java.nio.file.Path) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) AcceptanceTest(gov.cms.qpp.test.annotations.AcceptanceTest)

Example 4 with AllErrors

use of gov.cms.qpp.conversion.model.error.AllErrors in project qpp-conversion-tool by CMSgov.

the class ValidationApiFailureAcceptance method testBadPerformanceStart.

@ParameterizedAcceptanceTest
@MethodSource("getFailureScenarios")
void testBadPerformanceStart(String comparison, Map<String, String> override) {
    String qrda = getQrda(override);
    Response response = performRequest(qrda);
    assertThat(response.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY.value());
    AllErrors blah = response.getBody().as(AllErrors.class);
    blah.getErrors().stream().flatMap(error -> error.getDetails().stream()).forEach(verifyDetail(comparison, qrda));
}
Also used : Response(io.restassured.response.Response) Assertions.fail(org.junit.jupiter.api.Assertions.fail) AcceptanceTest(gov.cms.qpp.test.annotations.AcceptanceTest) XPathFactory(org.jdom2.xpath.XPathFactory) Mustache(com.github.mustachejava.Mustache) HashMap(java.util.HashMap) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) MustacheFactory(com.github.mustachejava.MustacheFactory) MethodSource(org.junit.jupiter.params.provider.MethodSource) DefaultMustacheFactory(com.github.mustachejava.DefaultMustacheFactory) Filter(org.jdom2.filter.Filter) StringWriter(java.io.StringWriter) XmlUtils(gov.cms.qpp.conversion.xml.XmlUtils) ParameterizedAcceptanceTest(gov.cms.qpp.test.annotations.ParameterizedAcceptanceTest) Arguments(org.junit.jupiter.params.provider.Arguments) Truth.assertThat(com.google.common.truth.Truth.assertThat) XPathExpression(org.jdom2.xpath.XPathExpression) Consumer(java.util.function.Consumer) HttpStatus(org.springframework.http.HttpStatus) Detail(gov.cms.qpp.conversion.model.error.Detail) Attribute(org.jdom2.Attribute) Stream(java.util.stream.Stream) Response(io.restassured.response.Response) RestAssured.given(io.restassured.RestAssured.given) XmlException(gov.cms.qpp.conversion.xml.XmlException) Filters(org.jdom2.filter.Filters) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) Collections(java.util.Collections) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) MethodSource(org.junit.jupiter.params.provider.MethodSource) ParameterizedAcceptanceTest(gov.cms.qpp.test.annotations.ParameterizedAcceptanceTest)

Example 5 with AllErrors

use of gov.cms.qpp.conversion.model.error.AllErrors in project qpp-conversion-tool by CMSgov.

the class ValidationServiceImpl method validateQpp.

/**
 * Validates that the given QPP is valid.
 *
 * @param conversionReport A report on the status of the conversion.
 */
@Override
public void validateQpp(final ConversionReport conversionReport) {
    String validationUrl = environment.getProperty(Constants.VALIDATION_URL_ENV_VARIABLE);
    if (StringUtils.isEmpty(validationUrl)) {
        return;
    }
    conversionReport.getEncoded().stream().forEach(wrapper -> {
        ResponseEntity<String> validationResponse = callValidationEndpoint(validationUrl, wrapper);
        if (HttpStatus.UNPROCESSABLE_ENTITY == validationResponse.getStatusCode()) {
            API_LOG.warn("Failed QPP validation");
            AllErrors convertedErrors = convertQppValidationErrorsToQrda(validationResponse.getBody(), wrapper);
            conversionReport.setRawValidationDetails(validationResponse.getBody());
            conversionReport.setReportDetails(convertedErrors);
            throw new QppValidationException("Converted QPP failed validation", null, conversionReport);
        }
    });
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) QppValidationException(gov.cms.qpp.conversion.model.error.QppValidationException)

Aggregations

AllErrors (gov.cms.qpp.conversion.model.error.AllErrors)31 TransformException (gov.cms.qpp.conversion.model.error.TransformException)21 Test (org.junit.jupiter.api.Test)19 Converter (gov.cms.qpp.conversion.Converter)15 PathSource (gov.cms.qpp.conversion.PathSource)12 Detail (gov.cms.qpp.conversion.model.error.Detail)11 Path (java.nio.file.Path)8 ArrayList (java.util.ArrayList)6 Error (gov.cms.qpp.conversion.model.error.Error)4 QppValidationException (gov.cms.qpp.conversion.model.error.QppValidationException)4 LocalizedError (gov.cms.qpp.conversion.model.error.LocalizedError)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Context (gov.cms.qpp.conversion.Context)2 InputStreamSupplierSource (gov.cms.qpp.conversion.InputStreamSupplierSource)2 XmlException (gov.cms.qpp.conversion.xml.XmlException)2 XmlUtils (gov.cms.qpp.conversion.xml.XmlUtils)2 AcceptanceTest (gov.cms.qpp.test.annotations.AcceptanceTest)2 RestAssured.given (io.restassured.RestAssured.given)2 Response (io.restassured.response.Response)2 InputStream (java.io.InputStream)2