Search in sources :

Example 1 with QppValidationException

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

the class ValidationServiceImpl method validateQpp.

/**
 * Validates that the given QPP is valid.
 *
 * @param conversionReport A report on the status of the conversion.
 */
@Override
public void validateQpp(final ConversionReport conversionReport) {
    String validationUrl = environment.getProperty(Constants.VALIDATION_URL_ENV_VARIABLE);
    if (StringUtils.isEmpty(validationUrl)) {
        return;
    }
    conversionReport.getEncoded().stream().forEach(wrapper -> {
        ResponseEntity<String> validationResponse = callValidationEndpoint(validationUrl, wrapper);
        if (HttpStatus.UNPROCESSABLE_ENTITY == validationResponse.getStatusCode()) {
            API_LOG.warn("Failed QPP validation");
            AllErrors convertedErrors = convertQppValidationErrorsToQrda(validationResponse.getBody(), wrapper);
            conversionReport.setRawValidationDetails(validationResponse.getBody());
            conversionReport.setReportDetails(convertedErrors);
            throw new QppValidationException("Converted QPP failed validation", null, conversionReport);
        }
    });
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) QppValidationException(gov.cms.qpp.conversion.model.error.QppValidationException)

Example 2 with QppValidationException

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

the class ExceptionHandlerControllerV1Test method testQppValidationExceptionHeaderContentType.

@Test
void testQppValidationExceptionHeaderContentType() {
    QppValidationException exception = new QppValidationException("test transform exception", new NullPointerException(), report);
    ResponseEntity<AllErrors> responseEntity = objectUnderTest.handleQppValidationException(exception);
    assertThat(responseEntity.getHeaders().getContentType()).isEquivalentAccordingToCompareTo(MediaType.APPLICATION_JSON_UTF8);
}
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 3 with QppValidationException

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

use of gov.cms.qpp.conversion.model.error.QppValidationException 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)

Aggregations

AllErrors (gov.cms.qpp.conversion.model.error.AllErrors)4 QppValidationException (gov.cms.qpp.conversion.model.error.QppValidationException)4 Test (org.junit.jupiter.api.Test)3