Search in sources :

Example 1 with CustomerB

use of org.wildfly.camel.test.dozer.subA.CustomerB in project wildfly-camel by wildfly-extras.

the class DozerSpringIntegrationTest method testBeanMapping.

@Test
public void testBeanMapping() throws Exception {
    CamelContext camelctx = contextRegistry.getCamelContext("dozer-spring-context");
    Assert.assertEquals(ServiceStatus.Started, camelctx.getStatus());
    String json = "{" + CustomerA.class.getName() + ":{firstName:John,lastName:Doe,street:Street,zip:1234}}";
    ProducerTemplate template = camelctx.createProducerTemplate();
    CustomerB customer = template.requestBody("direct:start", json, CustomerB.class);
    Assert.assertEquals("John", customer.getFirstName());
    Assert.assertEquals("Doe", customer.getLastName());
    Assert.assertEquals("Street", customer.getAddress().getStreet());
    Assert.assertEquals("1234", customer.getAddress().getZip());
}
Also used : CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) CustomerB(org.wildfly.camel.test.dozer.subA.CustomerB) Test(org.junit.Test)

Example 2 with CustomerB

use of org.wildfly.camel.test.dozer.subA.CustomerB 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)

Aggregations

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