Search in sources :

Example 11 with TransformException

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

the class QrdaServiceImplTest method testConvertQrda3ToQppError.

@Test
void testConvertQrda3ToQppError() {
    TransformException exception = assertThrows(TransformException.class, () -> objectUnderTest.convertQrda3ToQpp(MOCK_ERROR_QRDA_SOURCE));
    AllErrors allErrors = exception.getDetails();
    assertThat(allErrors.getErrors().get(0).getSourceIdentifier()).isSameAs(MOCK_ERROR_SOURCE_IDENTIFIER);
}
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 12 with TransformException

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

the class ValidationServiceImplTest method testValidationFail.

@Test
void testValidationFail() throws IOException {
    String validationUrl = "https://qpp.net/validate";
    when(environment.getProperty(eq(Constants.VALIDATION_URL_ENV_VARIABLE))).thenReturn(validationUrl);
    ResponseEntity<String> spiedResponseEntity = spy(new ResponseEntity<>(FileUtils.readFileToString(pathToSubmissionError.toFile(), "UTF-8"), HttpStatus.UNPROCESSABLE_ENTITY));
    when(restTemplate.postForEntity(eq(validationUrl), any(HttpEntity.class), eq(String.class))).thenReturn(spiedResponseEntity);
    TransformException thrown = assertThrows(TransformException.class, () -> objectUnderTest.validateQpp(converter.getReport()));
    assertThat(thrown).hasMessageThat().isEqualTo("Converted QPP failed validation");
}
Also used : HttpEntity(org.springframework.http.HttpEntity) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Test(org.junit.jupiter.api.Test)

Example 13 with TransformException

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

the class ClinicalDocumentValidatorTest method testClinicalDocumentValidationParsesMultipleErrors.

@Test
void testClinicalDocumentValidationParsesMultipleErrors() {
    // setup
    Path path = Paths.get("src/test/resources/negative/angerClinicalDocumentValidations.xml");
    // execute
    Context context = new Context();
    context.setDoDefaults(true);
    Converter converter = new Converter(new PathSource(path), context);
    AllErrors allErrors = new AllErrors();
    try {
        converter.transform();
    } catch (TransformException exception) {
        allErrors = exception.getDetails();
    }
    List<Detail> errors = getErrors(allErrors);
    assertWithMessage("Must have 4 errors").that(errors).hasSize(4);
    assertWithMessage("Must contain the correct errors").that(errors).comparingElementsUsing(DetailsErrorEquals.INSTANCE).containsAllOf(ErrorCode.CLINICAL_DOCUMENT_MISSING_PROGRAM_NAME, ErrorCode.REPORTING_PARAMETERS_MUST_CONTAIN_SINGLE_PERFORMANCE_START);
}
Also used : Path(java.nio.file.Path) Context(gov.cms.qpp.conversion.Context) 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 14 with TransformException

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

the class ConversionFileWriterWrapper method executeConverter.

/**
 * Execute the converter and do initial handling of the result.
 *
 * @param converter The Converter to execute.
 */
private void executeConverter(Converter converter) {
    try {
        JsonWrapper jsonWrapper = converter.transform();
        Path outFile = getOutputFile(source.getName(), true);
        DEV_LOG.info("Successful conversion.  Writing out QPP to {}", outFile.toString());
        writeOutQpp(jsonWrapper, outFile);
    } catch (TransformException exception) {
        AllErrors allErrors = exception.getDetails();
        Path outFile = getOutputFile(source.getName(), false);
        DEV_LOG.warn("There were errors during conversion.  Writing out errors to " + outFile.toString(), exception);
        writeOutErrors(allErrors, outFile);
    }
}
Also used : Path(java.nio.file.Path) JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) TransformException(gov.cms.qpp.conversion.model.error.TransformException)

Example 15 with TransformException

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

the class QrdaServiceImplTest method errorConverter.

private Converter errorConverter() {
    Converter mockConverter = mock(Converter.class);
    AllErrors allErrors = new AllErrors();
    allErrors.addError(new Error(MOCK_ERROR_SOURCE_IDENTIFIER, null));
    ConversionReport report = mock(ConversionReport.class);
    when(report.getReportDetails()).thenReturn(allErrors);
    TransformException transformException = new TransformException("mock problem", new NullPointerException(), report);
    when(mockConverter.transform()).thenThrow(transformException);
    return mockConverter;
}
Also used : AllErrors(gov.cms.qpp.conversion.model.error.AllErrors) TransformException(gov.cms.qpp.conversion.model.error.TransformException) Converter(gov.cms.qpp.conversion.Converter) Error(gov.cms.qpp.conversion.model.error.Error) ConversionReport(gov.cms.qpp.conversion.ConversionReport)

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