Search in sources :

Example 21 with AllErrors

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

the class ExceptionHandlerControllerV1Test method testQppValidationExceptionBody.

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

Example 22 with AllErrors

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

the class ExceptionHandlerControllerV1Test method testQppValidationExceptionStatusCode.

@Test
void testQppValidationExceptionStatusCode() {
    QppValidationException exception = new QppValidationException("test transform exception", new NullPointerException(), report);
    ResponseEntity<AllErrors> responseEntity = objectUnderTest.handleQppValidationException(exception);
    assertWithMessage("The response entity's status code must be 422.").that(responseEntity.getStatusCode()).isEquivalentAccordingToCompareTo(HttpStatus.UNPROCESSABLE_ENTITY);
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) QppValidationException(gov.cms.qpp.conversion.model.error.QppValidationException) Test(org.junit.jupiter.api.Test)

Example 23 with AllErrors

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

the class ValidationServiceImpl method convertQppValidationErrorsToQrda.

/**
 * Converts the QPP error returned from the validation API to QRDA3 errors
 *
 * @param validationResponse The JSON response containing a QPP error.
 * @param wrapper The QPP that resulted in the QPP error.
 * @return The QRDA3 errors.
 */
AllErrors convertQppValidationErrorsToQrda(String validationResponse, JsonWrapper wrapper) {
    AllErrors errors = new AllErrors();
    if (validationResponse == null) {
        return errors;
    }
    Error error = getError(validationResponse);
    error.getDetails().forEach(detail -> {
        detail.setMessage(SV_LABEL + detail.getMessage());
        String newPath = UNABLE_PROVIDE_XPATH;
        try {
            newPath = PathCorrelator.prepPath(detail.getPath(), wrapper);
        } catch (ClassCastException | JsonPathException exc) {
            API_LOG.warn("Failed to convert from json path to an XPath.", exc);
        }
        detail.setPath(newPath);
    });
    errors.addError(error);
    return errors;
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) Error(gov.cms.qpp.conversion.model.error.Error) JsonPathException(com.jayway.jsonpath.JsonPathException)

Example 24 with AllErrors

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

the class ConverterTest method testValidationErrors.

@Test
@PrepareForTest({ Converter.class, QrdaValidator.class })
public void testValidationErrors() throws Exception {
    Context context = new Context();
    context.setDoDefaults(true);
    TestHelper.mockDecoder(context, JennyDecoder.class, new ComponentKey(TemplateId.DEFAULT, Program.ALL));
    QrdaValidator mockQrdaValidator = TestHelper.mockValidator(context, TestDefaultValidator.class, new ComponentKey(TemplateId.DEFAULT, Program.ALL), true);
    PowerMockito.whenNew(QrdaValidator.class).withAnyArguments().thenReturn(mockQrdaValidator);
    Path path = Paths.get("src/test/resources/converter/errantDefaultedNode.xml");
    Converter converter = new Converter(new PathSource(path), context);
    try {
        converter.transform();
        fail("The converter should not create valid QPP JSON");
    } catch (TransformException exception) {
        AllErrors allErrors = exception.getDetails();
        List<Error> errors = allErrors.getErrors();
        assertWithMessage("There must only be one error source.").that(errors).hasSize(1);
        List<Detail> details = errors.get(0).getDetails();
        assertWithMessage("The expected validation error was missing").that(details).comparingElementsUsing(DetailsErrorEquals.INSTANCE).contains(new FormattedErrorCode(ErrorCode.UNEXPECTED_ERROR, "Test validation error for Jenny"));
    }
}
Also used : Path(java.nio.file.Path) QrdaValidator(gov.cms.qpp.conversion.validate.QrdaValidator) FormattedErrorCode(gov.cms.qpp.conversion.model.error.FormattedErrorCode) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) ComponentKey(gov.cms.qpp.conversion.model.ComponentKey) TransformException(gov.cms.qpp.conversion.model.error.TransformException) List(java.util.List) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with AllErrors

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

the class ConverterTest method checkup.

private void checkup(TransformException exception, LocalizedError error) {
    AllErrors allErrors = exception.getDetails();
    List<Error> errors = allErrors.getErrors();
    assertWithMessage("There must only be one error source.").that(errors).hasSize(1);
    List<Detail> details = errors.get(0).getDetails();
    assertWithMessage("There must be only one validation error.").that(details).hasSize(1);
    assertWithMessage("The validation error was incorrect").that(details).comparingElementsUsing(DetailsErrorEquals.INSTANCE).containsExactly(error);
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) Error(gov.cms.qpp.conversion.model.error.Error) LocalizedError(gov.cms.qpp.conversion.model.error.LocalizedError) Detail(gov.cms.qpp.conversion.model.error.Detail)

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