Search in sources :

Example 1 with Person

use of org.wildfly.camel.test.protobuf.model.AddressBookProtos.Person in project wildfly-camel by wildfly-extras.

the class ProtobufIntegrationTest method testMarshall.

@Test
public void testMarshall() throws Exception {
    final ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance());
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").marshal(format);
        }
    });
    Person person = Person.newBuilder().setId(1).setName("John Doe").build();
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        String result = producer.requestBody("direct:start", person, String.class);
        Assert.assertEquals("John Doe", result.trim());
    } 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) Person(org.wildfly.camel.test.protobuf.model.AddressBookProtos.Person) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProtobufDataFormat(org.apache.camel.dataformat.protobuf.ProtobufDataFormat) Test(org.junit.Test)

Example 2 with Person

use of org.wildfly.camel.test.protobuf.model.AddressBookProtos.Person in project wildfly-camel by wildfly-extras.

the class ProtobufIntegrationTest method testUnmarshall.

@Test
public void testUnmarshall() throws Exception {
    final ProtobufDataFormat format = new ProtobufDataFormat(Person.getDefaultInstance());
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:start").unmarshal(format);
        }
    });
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Person person = Person.newBuilder().setId(1).setName("John Doe").build();
    person.writeTo(baos);
    camelctx.start();
    try {
        ProducerTemplate producer = camelctx.createProducerTemplate();
        Person result = producer.requestBody("direct:start", baos.toByteArray(), Person.class);
        Assert.assertEquals("John Doe", result.getName().trim());
    } 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) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Person(org.wildfly.camel.test.protobuf.model.AddressBookProtos.Person) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) ProtobufDataFormat(org.apache.camel.dataformat.protobuf.ProtobufDataFormat) Test(org.junit.Test)

Aggregations

CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2 RouteBuilder (org.apache.camel.builder.RouteBuilder)2 ProtobufDataFormat (org.apache.camel.dataformat.protobuf.ProtobufDataFormat)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 Test (org.junit.Test)2 Person (org.wildfly.camel.test.protobuf.model.AddressBookProtos.Person)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1