Search in sources :

Example 1 with DozerTypeConverterLoader

use of org.apache.camel.converter.dozer.DozerTypeConverterLoader in project wildfly-camel by wildfly-extras.

the class DozerIntegrationTest method testBeanMapping.

@Test
public void testBeanMapping() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").convertBodyTo(CustomerB.class);
        }
    });
    DozerBeanMapperConfiguration mconfig = new DozerBeanMapperConfiguration();
    mconfig.setMappingFiles(Arrays.asList(new String[] { DOZER_MAPPINGS_XML }));
    new DozerTypeConverterLoader(camelctx, mconfig);
    CustomerA customerA = new CustomerA("Peter", "Post", "Street", "12345");
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        CustomerB result = producer.requestBody("direct:start", customerA, CustomerB.class);
        Assert.assertEquals(customerA.getFirstName(), result.getFirstName());
        Assert.assertEquals(customerA.getLastName(), result.getLastName());
        Assert.assertEquals(customerA.getStreet(), result.getAddress().getStreet());
        Assert.assertEquals(customerA.getZip(), result.getAddress().getZip());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DozerBeanMapperConfiguration(org.apache.camel.converter.dozer.DozerBeanMapperConfiguration) ProducerTemplate(org.apache.camel.ProducerTemplate) CustomerA(org.wildfly.camel.test.dozer.subA.CustomerA) RouteBuilder(org.apache.camel.builder.RouteBuilder) CustomerB(org.wildfly.camel.test.dozer.subA.CustomerB) DozerTypeConverterLoader(org.apache.camel.converter.dozer.DozerTypeConverterLoader) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 2 with DozerTypeConverterLoader

use of org.apache.camel.converter.dozer.DozerTypeConverterLoader in project wildfly-camel by wildfly-extras.

the class CSVIntegrationTest method testMarshalViaDozer.

@Test
public void testMarshalViaDozer() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal().csv();
        }
    });
    DozerBeanMapperConfiguration mconfig = new DozerBeanMapperConfiguration();
    mconfig.setMappingFiles(Arrays.asList(new String[] { DOZER_MAPPINGS_XML }));
    new DozerTypeConverterLoader(camelctx, mconfig);
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class);
        Assert.assertEquals("John,Doe", result.trim());
    } finally {
        camelctx.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) DozerBeanMapperConfiguration(org.apache.camel.converter.dozer.DozerBeanMapperConfiguration) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) DozerTypeConverterLoader(org.apache.camel.converter.dozer.DozerTypeConverterLoader) Customer(org.wildfly.camel.test.common.types.Customer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 DozerBeanMapperConfiguration (org.apache.camel.converter.dozer.DozerBeanMapperConfiguration)2 DozerTypeConverterLoader (org.apache.camel.converter.dozer.DozerTypeConverterLoader)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 Customer (org.wildfly.camel.test.common.types.Customer)1 CustomerA (org.wildfly.camel.test.dozer.subA.CustomerA)1 CustomerB (org.wildfly.camel.test.dozer.subA.CustomerB)1