Search in sources :

Example 1 with JsonOutputEncoder

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

the class ConverterTest method testEncodeThrowingEncodeException.

@Test
public void testEncodeThrowingEncodeException() throws Exception {
    Converter converter = Mockito.mock(Converter.class);
    Field field = Converter.class.getDeclaredField("decoded");
    field.setAccessible(true);
    field.set(converter, new Node());
    JsonOutputEncoder mockEncoder = Mockito.mock(JsonOutputEncoder.class);
    Mockito.when(mockEncoder.encode()).thenThrow(EncodeException.class);
    Mockito.when(converter.getEncoder()).thenReturn(mockEncoder);
    Method encode = Converter.class.getDeclaredMethod("encode");
    encode.setAccessible(true);
    Exception thrown = Assertions.assertThrows(InvocationTargetException.class, () -> encode.invoke(converter));
    Truth.assertThat(thrown).hasCauseThat().isInstanceOf(XmlInputFileException.class);
}
Also used : Field(java.lang.reflect.Field) Node(gov.cms.qpp.conversion.model.Node) JsonOutputEncoder(gov.cms.qpp.conversion.encode.JsonOutputEncoder) Method(java.lang.reflect.Method) XmlInputFileException(gov.cms.qpp.conversion.decode.XmlInputFileException) TransformException(gov.cms.qpp.conversion.model.error.TransformException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EncodeException(gov.cms.qpp.conversion.encode.EncodeException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with JsonOutputEncoder

use of gov.cms.qpp.conversion.encode.JsonOutputEncoder 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)

Aggregations

XmlInputFileException (gov.cms.qpp.conversion.decode.XmlInputFileException)2 EncodeException (gov.cms.qpp.conversion.encode.EncodeException)2 JsonOutputEncoder (gov.cms.qpp.conversion.encode.JsonOutputEncoder)2 JsonWrapper (gov.cms.qpp.conversion.encode.JsonWrapper)1 Node (gov.cms.qpp.conversion.model.Node)1 TransformException (gov.cms.qpp.conversion.model.error.TransformException)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1