Search in sources :

Example 16 with TransformException

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

the class ExceptionHandlerControllerV1Test method testTransformExceptionStatusCode.

@Test
void testTransformExceptionStatusCode() {
    TransformException exception = new TransformException("test transform exception", new NullPointerException(), report);
    ResponseEntity<AllErrors> responseEntity = objectUnderTest.handleTransformException(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) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Test(org.junit.jupiter.api.Test)

Example 17 with TransformException

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

the class AggregateCountFailureTest method testInvalidAggregateCounts.

@Test
void testInvalidAggregateCounts() throws IOException {
    // execute
    Converter converter = new Converter(new PathSource(Paths.get("src/test/resources/negative/angerTheConverter.xml")));
    String errorContent = "";
    try {
        converter.transform();
        Assertions.fail("A transformation exception must have been thrown!");
    } catch (TransformException exception) {
        AllErrors errors = exception.getDetails();
        ObjectWriter jsonObjectWriter = new ObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL).writer().withDefaultPrettyPrinter();
        errorContent = jsonObjectWriter.writeValueAsString(errors);
    }
    // assert
    assertWithMessage("The error file flags a aggregate count type error").that(errorContent).contains(ErrorCode.NUMERATOR_DENOMINATOR_MUST_BE_INTEGER.format("Numerator").getMessage());
    assertWithMessage("The error file flags a aggregate count value error").that(errorContent).contains(ErrorCode.NUMERATOR_DENOMINATOR_INVALID_VALUE.format("Denominator").getMessage());
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) PathSource(gov.cms.qpp.conversion.PathSource) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Converter(gov.cms.qpp.conversion.Converter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 18 with TransformException

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

the class MeasureDataValidatorTest method multipleNegativeMeasureDataTest.

@Test
void multipleNegativeMeasureDataTest() throws Exception {
    // setup
    Path path = Paths.get("src/test/resources/negative/angerMeasureDataValidations.xml");
    // execute
    Converter converter = new Converter(new PathSource(path));
    AllErrors allErrors = new AllErrors();
    try {
        converter.transform();
    } catch (TransformException exception) {
        allErrors = exception.getDetails();
    }
    List<Detail> errors = getErrors(allErrors);
    assertWithMessage("Must contain the error").that(errors).comparingElementsUsing(DetailsErrorEquals.INSTANCE).containsAllOf(ErrorCode.AGGREGATE_COUNT_VALUE_NOT_INTEGER, ErrorCode.AGGREGATE_COUNT_VALUE_NOT_SINGULAR, ErrorCode.MEASURE_DATA_VALUE_NOT_INTEGER);
}
Also used : Path(java.nio.file.Path) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) PathSource(gov.cms.qpp.conversion.PathSource) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Converter(gov.cms.qpp.conversion.Converter) Detail(gov.cms.qpp.conversion.model.error.Detail) Test(org.junit.jupiter.api.Test)

Example 19 with TransformException

use of gov.cms.qpp.conversion.model.error.TransformException 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 20 with TransformException

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

the class ConverterTest method testNotAValidQrdaIIIFile.

@Test
public void testNotAValidQrdaIIIFile() {
    Path path = Paths.get("src/test/resources/not-a-QRDA-III-file.xml");
    Converter converter = new Converter(new PathSource(path));
    converter.getContext().setDoDefaults(false);
    converter.getContext().setDoValidation(false);
    try {
        converter.transform();
        fail();
    } catch (TransformException exception) {
        checkup(exception, ErrorCode.NOT_VALID_QRDA_DOCUMENT.format(Context.REPORTING_YEAR, Context.IG_URL));
    }
}
Also used : Path(java.nio.file.Path) TransformException(gov.cms.qpp.conversion.model.error.TransformException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

TransformException (gov.cms.qpp.conversion.model.error.TransformException)27 AllErrors (gov.cms.qpp.conversion.model.error.AllErrors)21 Test (org.junit.jupiter.api.Test)17 Converter (gov.cms.qpp.conversion.Converter)16 PathSource (gov.cms.qpp.conversion.PathSource)13 Path (java.nio.file.Path)10 Detail (gov.cms.qpp.conversion.model.error.Detail)9 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Context (gov.cms.qpp.conversion.Context)2 InputStreamSupplierSource (gov.cms.qpp.conversion.InputStreamSupplierSource)2 LocalizedError (gov.cms.qpp.conversion.model.error.LocalizedError)2 InputStream (java.io.InputStream)2 List (java.util.List)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 ConversionReport (gov.cms.qpp.conversion.ConversionReport)1