Search in sources :

Example 1 with QrdaValidator

use of gov.cms.qpp.conversion.validate.QrdaValidator in project qpp-conversion-tool by CMSgov.

the class Converter method transform.

/**
 * Transform the content in a given input stream
 *
 * @param inStream source content
 * @return a transformed representation of the source content
 * @throws XmlException during transform
 */
private JsonWrapper transform(InputStream inStream) {
    Element doc = XmlUtils.parseXmlStream(inStream);
    decoded = XmlDecoderEngine.decodeXml(context, doc);
    JsonWrapper qpp = null;
    if (null != decoded) {
        DEV_LOG.info("Decoded template ID {}", decoded.getType());
        if (!context.isDoDefaults()) {
            DefaultDecoder.removeDefaultNode(decoded.getChildNodes());
        }
        if (context.isDoValidation()) {
            QrdaValidator validator = new QrdaValidator(context);
            details.addAll(validator.validate(decoded));
        }
        if (details.isEmpty()) {
            qpp = encode();
        }
    } else {
        Detail detail = Detail.forErrorCode(ErrorCode.NOT_VALID_QRDA_DOCUMENT.format(Context.REPORTING_YEAR, Context.IG_URL));
        details.add(detail);
    }
    return qpp;
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) QrdaValidator(gov.cms.qpp.conversion.validate.QrdaValidator) Element(org.jdom2.Element) Detail(gov.cms.qpp.conversion.model.error.Detail)

Example 2 with QrdaValidator

use of gov.cms.qpp.conversion.validate.QrdaValidator 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)

Aggregations

QrdaValidator (gov.cms.qpp.conversion.validate.QrdaValidator)2 JsonWrapper (gov.cms.qpp.conversion.encode.JsonWrapper)1 ComponentKey (gov.cms.qpp.conversion.model.ComponentKey)1 AllErrors (gov.cms.qpp.conversion.model.error.AllErrors)1 Detail (gov.cms.qpp.conversion.model.error.Detail)1 FormattedErrorCode (gov.cms.qpp.conversion.model.error.FormattedErrorCode)1 TransformException (gov.cms.qpp.conversion.model.error.TransformException)1 Path (java.nio.file.Path)1 List (java.util.List)1 Element (org.jdom2.Element)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1