Search in sources :

Example 1 with EncodeException

use of gov.cms.qpp.conversion.encode.EncodeException in project qpp-conversion-tool by CMSgov.

the class Converter method encode.

/**
 * Place transformed content into an input stream
 *
 * @return content resulting from the transformation
 */
private JsonWrapper encode() {
    JsonOutputEncoder encoder = getEncoder();
    DEV_LOG.info("Encoding template ID {}", decoded.getType());
    try {
        encoder.setNodes(Collections.singletonList(decoded));
        JsonWrapper qpp = encoder.encode();
        details.addAll(encoder.getDetails());
        return qpp;
    } catch (EncodeException e) {
        throw new XmlInputFileException("Issues decoding/encoding.", e);
    }
}
Also used : JsonWrapper(gov.cms.qpp.conversion.encode.JsonWrapper) XmlInputFileException(gov.cms.qpp.conversion.decode.XmlInputFileException) JsonOutputEncoder(gov.cms.qpp.conversion.encode.JsonOutputEncoder) EncodeException(gov.cms.qpp.conversion.encode.EncodeException)

Example 2 with EncodeException

use of gov.cms.qpp.conversion.encode.EncodeException in project qpp-conversion-tool by CMSgov.

the class ConverterTest method testEncodingExceptions.

@Test
@PrepareForTest({ Converter.class, QppOutputEncoder.class })
public void testEncodingExceptions() throws Exception {
    QppOutputEncoder encoder = mock(QppOutputEncoder.class);
    whenNew(QppOutputEncoder.class).withAnyArguments().thenReturn(encoder);
    EncodeException ex = new EncodeException("mocked", new RuntimeException());
    doThrow(ex).when(encoder).encode();
    Path path = Paths.get("src/test/resources/converter/defaultedNode.xml");
    Converter converter = new Converter(new PathSource(path));
    converter.getContext().setDoDefaults(false);
    converter.getContext().setDoValidation(false);
    try {
        converter.transform();
        fail();
    } catch (TransformException exception) {
        checkup(exception, ErrorCode.NOT_VALID_XML_DOCUMENT);
    }
}
Also used : Path(java.nio.file.Path) QppOutputEncoder(gov.cms.qpp.conversion.encode.QppOutputEncoder) TransformException(gov.cms.qpp.conversion.model.error.TransformException) EncodeException(gov.cms.qpp.conversion.encode.EncodeException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

EncodeException (gov.cms.qpp.conversion.encode.EncodeException)2 XmlInputFileException (gov.cms.qpp.conversion.decode.XmlInputFileException)1 JsonOutputEncoder (gov.cms.qpp.conversion.encode.JsonOutputEncoder)1 JsonWrapper (gov.cms.qpp.conversion.encode.JsonWrapper)1 QppOutputEncoder (gov.cms.qpp.conversion.encode.QppOutputEncoder)1 TransformException (gov.cms.qpp.conversion.model.error.TransformException)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1