Search in sources :

Example 16 with Customer

use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.

the class CastorIntegrationTest method testUnmarshal.

@Test
public void testUnmarshal() throws Exception {
    CastorDataFormat castor = new CastorDataFormat();
    castor.setMappingFile("castor-mapping.xml");
    castor.setAllowClasses(Customer.class);
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").unmarshal(castor);
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer result = producer.requestBody("direct:start", CUSTOMER_XML, Customer.class);
        Assert.assertEquals("John", result.getFirstName());
        Assert.assertEquals("Doe", result.getLastName());
    } finally {
        camelctx.stop();
    }
}
Also used : 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.common.types.Customer) CastorDataFormat(org.apache.camel.dataformat.castor.CastorDataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) IOException(java.io.IOException) Test(org.junit.Test)

Example 17 with Customer

use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.

the class CastorIntegrationTest method testMarshal.

@Test
public void testMarshal() throws Exception {
    CastorDataFormat castor = new CastorDataFormat();
    castor.setMappingFile("castor-mapping.xml");
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(castor);
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class);
        Assert.assertTrue("Ends with: " + result, result.endsWith(CUSTOMER_XML));
    } finally {
        camelctx.stop();
    }
}
Also used : 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.common.types.Customer) CastorDataFormat(org.apache.camel.dataformat.castor.CastorDataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) IOException(java.io.IOException) Test(org.junit.Test)

Example 18 with Customer

use of org.wildfly.camel.test.common.types.Customer 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)

Example 19 with Customer

use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.

the class CustomConverterTest method testMarshal.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").convertBodyTo(Map.class);
        }
    });
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Map<?, ?> result = producer.requestBody("direct:start", new Customer("John", "Doe"), Map.class);
        Assert.assertEquals("{firstName=John, lastName=Doe}", result.toString());
    } finally {
        camelctx.stop();
    }
}
Also used : 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.common.types.Customer) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 20 with Customer

use of org.wildfly.camel.test.common.types.Customer in project wildfly-camel by wildfly-extras.

the class JSONDataFormatTest method testMarshalJackson.

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

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal().json(JsonLibrary.Jackson);
        }
    });
    String expected = "{'firstName':'John','lastName':'Doe'}";
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", new Customer("John", "Doe"), String.class);
        Assert.assertEquals(expected.replace('\'', '"'), result);
    } finally {
        camelctx.stop();
    }
}
Also used : 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.common.types.Customer) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

Customer (org.wildfly.camel.test.common.types.Customer)23 CamelContext (org.apache.camel.CamelContext)22 ProducerTemplate (org.apache.camel.ProducerTemplate)22 RouteBuilder (org.apache.camel.builder.RouteBuilder)22 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)22 Test (org.junit.Test)22 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 CastorDataFormat (org.apache.camel.dataformat.castor.CastorDataFormat)2 BoonDataFormat (org.apache.camel.model.dataformat.BoonDataFormat)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Map (java.util.Map)1 SnakeYAMLDataFormat (org.apache.camel.component.snakeyaml.SnakeYAMLDataFormat)1 DozerBeanMapperConfiguration (org.apache.camel.converter.dozer.DozerBeanMapperConfiguration)1 DozerTypeConverterLoader (org.apache.camel.converter.dozer.DozerTypeConverterLoader)1 SoapJaxbDataFormat (org.apache.camel.dataformat.soap.SoapJaxbDataFormat)1