Search in sources :

Example 1 with Customer

use of org.wildfly.camel.test.beanio.subA.Customer in project wildfly-camel by wildfly-extras.

the class BeanIOIntegrationTest method testMarshal.

@Test
public void testMarshal() throws Exception {
    DataFormat beanio = new BeanIODataFormat(MAPPINGS_XML, "customerStream");
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(beanio);
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = new Customer("Peter", "Post", "Street", "12345");
        String result = producer.requestBody("direct:start", customer, String.class);
        Assert.assertEquals("Peter,Post,Street,12345", result.trim());
    } finally {
        camelctx.stop();
    }
}
Also used : BeanIODataFormat(org.apache.camel.dataformat.beanio.BeanIODataFormat) CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Customer(org.wildfly.camel.test.beanio.subA.Customer) BeanIODataFormat(org.apache.camel.dataformat.beanio.BeanIODataFormat) DataFormat(org.apache.camel.spi.DataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 2 with Customer

use of org.wildfly.camel.test.beanio.subA.Customer in project wildfly-camel by wildfly-extras.

the class BeanIOIntegrationTest method testUnmarshal.

@Test
public void testUnmarshal() throws Exception {
    DataFormat beanio = new BeanIODataFormat(MAPPINGS_XML, "customerStream");
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").unmarshal(beanio);
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        List<?> result = producer.requestBody("direct:start", "Peter,Post,Street,12345", List.class);
        Assert.assertEquals(1, result.size());
        Customer customer = (Customer) result.get(0);
        Assert.assertEquals("Peter", customer.getFirstName());
        Assert.assertEquals("Post", customer.getLastName());
        Assert.assertEquals("Street", customer.getStreet());
        Assert.assertEquals("12345", customer.getZip());
    } finally {
        camelctx.stop();
    }
}
Also used : BeanIODataFormat(org.apache.camel.dataformat.beanio.BeanIODataFormat) CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) RouteBuilder(org.apache.camel.builder.RouteBuilder) Customer(org.wildfly.camel.test.beanio.subA.Customer) BeanIODataFormat(org.apache.camel.dataformat.beanio.BeanIODataFormat) DataFormat(org.apache.camel.spi.DataFormat) 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 BeanIODataFormat (org.apache.camel.dataformat.beanio.BeanIODataFormat)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DataFormat (org.apache.camel.spi.DataFormat)2 Test (org.junit.Test)2 Customer (org.wildfly.camel.test.beanio.subA.Customer)2