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