Search in sources :

Example 1 with Customer

use of org.wildfly.camel.test.jaxb.model.Customer in project wildfly-camel by wildfly-extras.

the class JAXBIntegrationTest method testJaxbUnmarshal.

@Test
public void testJaxbUnmarshal() throws Exception {
    final JaxbDataFormat format = new JaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").unmarshal(format);
        }
    });
    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/customer.xml")) {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = producer.requestBody("direct:start", input, Customer.class);
        Assert.assertEquals("John", customer.getFirstName());
        Assert.assertEquals("Doe", customer.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.jaxb.model.Customer) InputStream(java.io.InputStream) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) JaxbDataFormat(org.apache.camel.model.dataformat.JaxbDataFormat) Test(org.junit.Test)

Example 2 with Customer

use of org.wildfly.camel.test.jaxb.model.Customer in project wildfly-camel by wildfly-extras.

the class SOAPIntegrationTest method testSoapV1_2Marshal.

@Test
public void testSoapV1_2Marshal() throws Exception {
    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(format);
        }
    });
    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope-1.2-marshal.xml")) {
        String expected = camelctx.getTypeConverter().mandatoryConvertTo(String.class, input);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = new Customer("John", "Doe");
        String customerXML = producer.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(expected, XMLUtils.compactXML(customerXML));
    } 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.jaxb.model.Customer) InputStream(java.io.InputStream) SoapJaxbDataFormat(org.apache.camel.dataformat.soap.SoapJaxbDataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 3 with Customer

use of org.wildfly.camel.test.jaxb.model.Customer in project wildfly-camel by wildfly-extras.

the class SOAPIntegrationTest method testSoapMarshal.

@Test
public void testSoapMarshal() throws Exception {
    final SoapJaxbDataFormat format = new SoapJaxbDataFormat();
    format.setContextPath("org.wildfly.camel.test.jaxb.model");
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(format);
        }
    });
    camelctx.start();
    try (InputStream input = getClass().getResourceAsStream("/envelope.xml")) {
        String expected = XMLUtils.compactXML(input);
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Customer customer = new Customer("John", "Doe");
        String customerXML = producer.requestBody("direct:start", customer, String.class);
        Assert.assertEquals(expected, XMLUtils.compactXML(customerXML));
    } 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.jaxb.model.Customer) InputStream(java.io.InputStream) SoapJaxbDataFormat(org.apache.camel.dataformat.soap.SoapJaxbDataFormat) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 4 with Customer

use of org.wildfly.camel.test.jaxb.model.Customer in project wildfly-camel by wildfly-extras.

the class SOAPIntegrationTest method deployment.

@Deployment
public static JavaArchive deployment() {
    return ShrinkWrap.create(JavaArchive.class, "soap-dataformat-tests").addPackage(Customer.class.getPackage()).addClasses(XMLUtils.class).addAsResource(new StringAsset("Customer"), "org/wildfly/camel/test/jaxb/model/jaxb.index").addAsResource("soap/envelope.xml", "envelope.xml").addAsResource("soap/envelope-1.2-marshal.xml", "envelope-1.2-marshal.xml").addAsResource("soap/envelope-1.2-unmarshal.xml", "envelope-1.2-unmarshal.xml").setManifest(() -> {
        ManifestBuilder builder = new ManifestBuilder();
        builder.addManifestHeader("Dependencies", "org.jdom");
        return builder.openStream();
    });
}
Also used : XMLUtils(org.wildfly.camel.test.common.utils.XMLUtils) ManifestBuilder(org.jboss.gravia.resource.ManifestBuilder) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) Customer(org.wildfly.camel.test.jaxb.model.Customer) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 5 with Customer

use of org.wildfly.camel.test.jaxb.model.Customer in project wildfly-camel by wildfly-extras.

the class JAXBIntegrationTest method deployment.

@Deployment
public static WebArchive deployment() {
    final WebArchive archive = ShrinkWrap.create(WebArchive.class, "jaxb-integration-tests.war");
    archive.addPackage(Customer.class.getPackage());
    archive.addClasses(XMLUtils.class);
    archive.addAsResource(new StringAsset("Customer"), "org/wildfly/camel/test/jaxb/model/jaxb.index");
    archive.addAsResource("jaxb/customer.xml", "customer.xml");
    archive.setManifest(new Asset() {

        @Override
        public InputStream openStream() {
            ManifestBuilder builder = new ManifestBuilder();
            builder.addManifestHeader("Dependencies", "org.jdom");
            return builder.openStream();
        }
    });
    return archive;
}
Also used : ManifestBuilder(org.jboss.gravia.resource.ManifestBuilder) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) Customer(org.wildfly.camel.test.jaxb.model.Customer) InputStream(java.io.InputStream) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) Asset(org.jboss.shrinkwrap.api.asset.Asset) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Aggregations

Customer (org.wildfly.camel.test.jaxb.model.Customer)6 InputStream (java.io.InputStream)5 CamelContext (org.apache.camel.CamelContext)4 ProducerTemplate (org.apache.camel.ProducerTemplate)4 RouteBuilder (org.apache.camel.builder.RouteBuilder)4 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)4 Test (org.junit.Test)4 SoapJaxbDataFormat (org.apache.camel.dataformat.soap.SoapJaxbDataFormat)2 JaxbDataFormat (org.apache.camel.model.dataformat.JaxbDataFormat)2 Deployment (org.jboss.arquillian.container.test.api.Deployment)2 ManifestBuilder (org.jboss.gravia.resource.ManifestBuilder)2 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)2 Asset (org.jboss.shrinkwrap.api.asset.Asset)1 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)1 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)1 XMLUtils (org.wildfly.camel.test.common.utils.XMLUtils)1