Search in sources :

Example 1 with DataFormatTransformer

use of org.apache.camel.impl.transformer.DataFormatTransformer in project camel by apache.

the class TransformerBuilderTest method testDataFormatTransformer.

public void testDataFormatTransformer() throws Exception {
    CamelContext ctx = new DefaultCamelContext();
    RouteBuilder builder = new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            transformer().fromType("xml:foo").toType("json:bar").withDataFormat(new StringDataFormat());
            from("direct:input").log("test");
        }
    };
    ctx.addRoutes(builder);
    ctx.start();
    Transformer transformer = ctx.resolveTransformer(new DataType("xml:foo"), new DataType("json:bar"));
    assertNotNull(transformer);
    assertEquals(DataFormatTransformer.class, transformer.getClass());
    DataFormatTransformer dft = (DataFormatTransformer) transformer;
    Field f = DataFormatTransformer.class.getDeclaredField("dataFormatType");
    f.setAccessible(true);
    Object dataFormatType = f.get(dft);
    assertEquals(StringDataFormat.class, dataFormatType.getClass());
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) Field(java.lang.reflect.Field) ProcessorTransformer(org.apache.camel.impl.transformer.ProcessorTransformer) Transformer(org.apache.camel.spi.Transformer) DataFormatTransformer(org.apache.camel.impl.transformer.DataFormatTransformer) StringDataFormat(org.apache.camel.model.dataformat.StringDataFormat) DataType(org.apache.camel.spi.DataType) DataFormatTransformer(org.apache.camel.impl.transformer.DataFormatTransformer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext)

Aggregations

Field (java.lang.reflect.Field)1 CamelContext (org.apache.camel.CamelContext)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DataFormatTransformer (org.apache.camel.impl.transformer.DataFormatTransformer)1 ProcessorTransformer (org.apache.camel.impl.transformer.ProcessorTransformer)1 StringDataFormat (org.apache.camel.model.dataformat.StringDataFormat)1 DataType (org.apache.camel.spi.DataType)1 Transformer (org.apache.camel.spi.Transformer)1