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;
}
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"));
}
}
Aggregations