Search in sources :

Example 1 with CustomerB

use of org.apache.camel.converter.dozer.model.CustomerB in project camel by apache.

the class DozerBeanMappingTest method testBeanMapping.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").convertBodyTo(CustomerB.class);
        }
    });
    DozerBeanMapperConfiguration mconfig = new DozerBeanMapperConfiguration();
    mconfig.setMappingFiles(Arrays.asList("bean-to-bean-dozer-mappings.xml"));
    new DozerTypeConverterLoader(context, mconfig);
    CustomerA customerA = new CustomerA("Peter", "Post", "SomeStreet", "12345");
    context.start();
    try {
        ProducerTemplate producer = context.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 {
        context.stop();
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) CustomerA(org.apache.camel.converter.dozer.model.CustomerA) RouteBuilder(org.apache.camel.builder.RouteBuilder) CustomerB(org.apache.camel.converter.dozer.model.CustomerB) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

CamelContext (org.apache.camel.CamelContext)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 CustomerA (org.apache.camel.converter.dozer.model.CustomerA)1 CustomerB (org.apache.camel.converter.dozer.model.CustomerB)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 Test (org.junit.Test)1