You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ff...@apache.org on 2022/03/02 22:16:57 UTC

[camel-spring-boot] branch main updated: [CAMEL-17735]add tests in camel-jackson-avro-starter (#449)

This is an automated email from the ASF dual-hosted git repository.

ffang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-spring-boot.git


The following commit(s) were added to refs/heads/main by this push:
     new c605b02  [CAMEL-17735]add tests in camel-jackson-avro-starter (#449)
c605b02 is described below

commit c605b02305409802505f94a5125acefd67e1317d
Author: Freeman(Yue) Fang <fr...@gmail.com>
AuthorDate: Wed Mar 2 17:16:52 2022 -0500

    [CAMEL-17735]add tests in camel-jackson-avro-starter (#449)
---
 .../test/JacksonAvroLookupResolverTest.java        | 145 ++++++++++++++++
 .../JacksonAvroMarshalUnmarshalJsonNodeTest.java   | 189 +++++++++++++++++++++
 .../JacksonAvroMarshalUnmarshalPojoListTest.java   | 159 +++++++++++++++++
 .../test/JacksonAvroMarshalUnmarshalPojoTest.java  | 149 ++++++++++++++++
 4 files changed, 642 insertions(+)

diff --git a/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroLookupResolverTest.java b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroLookupResolverTest.java
new file mode 100644
index 0000000..21a0daa
--- /dev/null
+++ b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroLookupResolverTest.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson.avro.springboot.test;
+
+
+import com.fasterxml.jackson.dataformat.avro.AvroSchema;
+
+import org.apache.avro.Schema;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jackson.SchemaResolver;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.dataformat.AvroLibrary;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+    classes = {
+        CamelAutoConfiguration.class,
+        JacksonAvroLookupResolverTest.class,
+        JacksonAvroLookupResolverTest.TestConfiguration.class
+    }
+)
+public class JacksonAvroLookupResolverTest {
+
+    
+    @Autowired
+    ProducerTemplate template;
+
+    @EndpointInject("mock:serialized")
+    MockEndpoint mock1;
+    
+    @EndpointInject("mock:pojo")
+    MockEndpoint mock2;
+
+    @Bean("schema-resolver-1")
+    private SchemaResolver getSchemaResolver() {
+        String schemaJson = "{\n"
+            + "\"type\": \"record\",\n"
+            + "\"name\": \"Pojo\",\n"
+            + "\"fields\": [\n"
+            + " {\"name\": \"text\", \"type\": \"string\"}\n"
+            + "]}";
+        Schema raw = new Schema.Parser().setValidate(true).parse(schemaJson);
+        AvroSchema schema = new AvroSchema(raw);
+        SchemaResolver resolver = ex -> schema;
+        
+        return resolver;
+    }
+    
+    @Test
+    public void testMarshalUnmarshalPojo() throws Exception {
+        
+        mock1.expectedMessageCount(1);
+        mock1.message(0).body().isInstanceOf(byte[].class);
+
+        Pojo pojo = new Pojo("Hello");
+        template.sendBody("direct:pojo", pojo);
+
+        mock1.assertIsSatisfied();
+
+        byte[] serialized = mock1.getReceivedExchanges().get(0).getIn().getBody(byte[].class);
+        assertNotNull(serialized);
+        assertEquals(6, serialized.length);
+
+        mock2.expectedMessageCount(1);
+        mock2.message(0).body().isInstanceOf(Pojo.class);
+
+        template.sendBody("direct:serialized", serialized);
+        mock2.assertIsSatisfied();
+
+        Pojo back = mock2.getReceivedExchanges().get(0).getIn().getBody(Pojo.class);
+
+        assertEquals(pojo.getText(), back.getText());
+    }
+
+
+    // *************************************
+    // Config
+    // *************************************
+
+    @Configuration
+    public static class TestConfiguration {
+
+        @Bean
+        public RouteBuilder routeBuilder() {
+            return new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:serialized").unmarshal().avro(AvroLibrary.Jackson, Pojo.class, "schema-resolver-1")
+                            .to("mock:pojo");
+                    from("direct:pojo").marshal().avro(AvroLibrary.Jackson, Pojo.class, "schema-resolver-1").to("mock:serialized");
+                }
+            };
+        }
+    }
+    
+    public static class Pojo {
+
+        private String text;
+
+        public Pojo() {
+        }
+
+        public Pojo(String text) {
+            this.text = text;
+        }
+
+        public String getText() {
+            return text;
+        }
+
+        public void setText(String text) {
+            this.text = text;
+        }
+    }
+}
diff --git a/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalJsonNodeTest.java b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalJsonNodeTest.java
new file mode 100644
index 0000000..ae67398
--- /dev/null
+++ b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalJsonNodeTest.java
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson.avro.springboot.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.dataformat.avro.AvroSchema;
+
+import org.apache.avro.Schema;
+import org.apache.camel.CamelContext;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jackson.SchemaResolver;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.dataformat.AvroLibrary;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(classes = {
+                           CamelAutoConfiguration.class, JacksonAvroMarshalUnmarshalJsonNodeTest.class,
+                           JacksonAvroMarshalUnmarshalJsonNodeTest.TestConfiguration.class
+})
+public class JacksonAvroMarshalUnmarshalJsonNodeTest {
+
+    @Autowired
+    ProducerTemplate template;
+    
+    @Autowired
+    CamelContext context;
+
+    @EndpointInject("mock:serialized")
+    MockEndpoint mock1;
+
+    @EndpointInject("mock:pojo")
+    MockEndpoint mock2;
+
+    @Bean("schema-resolver")
+    private SchemaResolver getSchemaResolver() {
+        String schemaJson = "{\n" + "\"type\": \"record\",\n" + "\"name\": \"Pojo\",\n" + "\"fields\": [\n"
+                            + " {\"name\": \"text\", \"type\": \"string\"}\n" + "]}";
+        String listSchemaJson = "{\n" + "  \"type\": \"array\",  \n" + "  \"items\":{\n"
+                                + "    \"name\":\"Pojo\",\n" + "    \"type\":\"record\",\n"
+                                + "    \"fields\":[\n" + "      {\"name\":\"text\", \"type\":\"string\"}\n"
+                                + "    ]\n" + "  }\n" + "}";
+
+        Schema raw = new Schema.Parser().setValidate(true).parse(schemaJson);
+        AvroSchema schema = new AvroSchema(raw);
+
+        Schema rawList = new Schema.Parser().setValidate(true).parse(listSchemaJson);
+        AvroSchema schemaList = new AvroSchema(rawList);
+
+        SchemaResolver resolver = ex -> {
+            Boolean isList = ex.getMessage().getHeader("list", Boolean.class);
+            if (isList != null && isList) {
+                return schemaList;
+            }
+            return schema;
+        };
+        return resolver;
+    }
+
+    @Test
+    public void testMarshalUnmarshalJsonNode() throws Exception {
+        MockEndpoint.resetMocks(context);
+        mock1.expectedMessageCount(1);
+        mock1.message(0).body().isInstanceOf(byte[].class);
+
+        Pojo pojo = new Pojo("Hello");
+        template.sendBody("direct:pojo", pojo);
+
+        mock1.assertIsSatisfied();
+
+        byte[] serialized = mock1.getReceivedExchanges().get(0).getIn().getBody(byte[].class);
+        assertNotNull(serialized);
+        assertEquals(6, serialized.length);
+
+        mock2.expectedMessageCount(1);
+        mock2.message(0).body().isInstanceOf(JsonNode.class);
+
+        template.sendBody("direct:serialized", serialized);
+        mock2.assertIsSatisfied();
+
+        JsonNode back = mock2.getReceivedExchanges().get(0).getIn().getBody(JsonNode.class);
+
+        assertEquals(pojo.getText(), back.at("/text").asText());
+    }
+
+    @Test
+    public void testMarshalUnmarshalJsonNodeList() throws Exception {
+        MockEndpoint.resetMocks(context);
+        mock1.expectedMessageCount(1);
+        mock1.message(0).body().isInstanceOf(byte[].class);
+
+        List<Pojo> pojos = new ArrayList<>();
+        pojos.add(new Pojo("Hello"));
+        pojos.add(new Pojo("World"));
+
+        template.sendBodyAndHeader("direct:pojo", pojos, "list", true);
+
+        mock1.assertIsSatisfied();
+
+        byte[] serialized = mock1.getReceivedExchanges().get(0).getIn().getBody(byte[].class);
+        assertNotNull(serialized);
+        assertEquals(14, serialized.length);
+
+        mock2.expectedMessageCount(1);
+        mock2.message(0).body().isInstanceOf(JsonNode.class);
+
+        template.sendBodyAndHeader("direct:serialized", serialized, "list", true);
+        mock2.assertIsSatisfied();
+
+        
+        JsonNode back = mock2.getReceivedExchanges().get(0).getIn().getBody(JsonNode.class);
+        assertTrue(back.isArray());
+        assertEquals(2, back.size());
+        assertEquals("Hello", back.get(0).at("/text").asText());
+        assertEquals("World", back.get(1).at("/text").asText());
+    }
+
+    // *************************************
+    // Config
+    // *************************************
+
+    @Configuration
+    public static class TestConfiguration {
+
+        @Bean
+        public RouteBuilder routeBuilder() {
+            return new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:serialized").unmarshal().avro(AvroLibrary.Jackson, JsonNode.class)
+                        .to("mock:pojo");
+                    from("direct:pojo").marshal().avro(AvroLibrary.Jackson).to("mock:serialized");
+                }
+            };
+        }
+    }
+
+    public static class Pojo {
+
+        private String text;
+
+        public Pojo() {
+        }
+
+        public Pojo(String text) {
+            this.text = text;
+        }
+
+        public String getText() {
+            return text;
+        }
+
+        public void setText(String text) {
+            this.text = text;
+        }
+    }
+}
diff --git a/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalPojoListTest.java b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalPojoListTest.java
new file mode 100644
index 0000000..00d62b1
--- /dev/null
+++ b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalPojoListTest.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson.avro.springboot.test;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.fasterxml.jackson.dataformat.avro.AvroSchema;
+
+import org.apache.avro.Schema;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jackson.SchemaResolver;
+import org.apache.camel.component.jackson.avro.JacksonAvroDataFormat;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.DataFormat;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+    classes = {
+        CamelAutoConfiguration.class,
+        JacksonAvroMarshalUnmarshalPojoListTest.class,
+        JacksonAvroMarshalUnmarshalPojoListTest.TestConfiguration.class
+    }
+)
+public class JacksonAvroMarshalUnmarshalPojoListTest {
+
+    
+    @Autowired
+    ProducerTemplate template;
+
+    @EndpointInject("mock:serialized")
+    MockEndpoint mock1;
+    
+    @EndpointInject("mock:pojo")
+    MockEndpoint mock2;
+
+    @Bean("schema-resolver")
+    private SchemaResolver getSchemaResolver() {
+        String schemaJson = "{\n" + "  \"type\": \"array\",  \n" + "  \"items\":{\n"
+                            + "    \"name\":\"Pojo\",\n" + "    \"type\":\"record\",\n" + "    \"fields\":[\n"
+                            + "      {\"name\":\"text\", \"type\":\"string\"}\n" + "    ]\n" + "  }\n" + "}";
+        Schema raw = new Schema.Parser().setValidate(true).parse(schemaJson);
+        AvroSchema schema = new AvroSchema(raw);
+        SchemaResolver resolver = ex -> schema;
+        
+        return resolver;
+    }
+    
+    @Bean("custom-df")
+    private DataFormat getDataFormat() {
+        JacksonAvroDataFormat df = new JacksonAvroDataFormat();
+        df.setUnmarshalType(Pojo.class);
+        df.setUseList(true);
+        return df;
+    }
+    
+    @Test
+    public void testMarshalUnmarshalPojoList() throws Exception {
+        
+        mock1.expectedMessageCount(1);
+        mock1.message(0).body().isInstanceOf(byte[].class);
+
+        List<Pojo> pojos = new ArrayList<>();
+        pojos.add(new Pojo("Hello"));
+        pojos.add(new Pojo("World"));
+
+        template.sendBody("direct:pojo", pojos);
+
+        mock1.assertIsSatisfied();
+
+        byte[] serialized = mock1.getReceivedExchanges().get(0).getIn().getBody(byte[].class);
+        assertNotNull(serialized);
+        assertEquals(14, serialized.length);
+
+        
+        mock2.expectedMessageCount(1);
+        mock2.message(0).body().isInstanceOf(List.class);
+
+        template.sendBody("direct:serialized", serialized);
+        mock2.assertIsSatisfied();
+
+        @SuppressWarnings("unchecked")
+        List<Pojo> back = mock2.getReceivedExchanges().get(0).getIn().getBody(List.class);
+
+        assertEquals(2, back.size());
+        assertEquals("Hello", back.get(0).getText());
+        assertEquals("World", back.get(1).getText());
+    }
+
+    // *************************************
+    // Config
+    // *************************************
+
+    @Configuration
+    public static class TestConfiguration {
+
+        @Bean
+        public RouteBuilder routeBuilder() {
+            return new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:serialized").unmarshal().custom("custom-df").to("mock:pojo");
+                    from("direct:pojo").marshal().custom("custom-df").to("mock:serialized");
+                }
+            };
+        }
+    }
+    
+    public static class Pojo {
+
+        private String text;
+
+        public Pojo() {
+        }
+
+        public Pojo(String text) {
+            this.text = text;
+        }
+
+        public String getText() {
+            return text;
+        }
+
+        public void setText(String text) {
+            this.text = text;
+        }
+    }
+}
diff --git a/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalPojoTest.java b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalPojoTest.java
new file mode 100644
index 0000000..ee06aa8
--- /dev/null
+++ b/components-starter/camel-jackson-avro-starter/src/test/java/org/apache/camel/component/jackson/avro/springboot/test/JacksonAvroMarshalUnmarshalPojoTest.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jackson.avro.springboot.test;
+
+
+import com.fasterxml.jackson.dataformat.avro.AvroSchema;
+
+import org.apache.avro.Schema;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.jackson.SchemaResolver;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.model.dataformat.AvroLibrary;
+import org.apache.camel.spring.boot.CamelAutoConfiguration;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
+
+
+@DirtiesContext
+@CamelSpringBootTest
+@SpringBootTest(
+    classes = {
+        CamelAutoConfiguration.class,
+        JacksonAvroMarshalUnmarshalPojoTest.class,
+        JacksonAvroMarshalUnmarshalPojoTest.TestConfiguration.class
+    }
+)
+public class JacksonAvroMarshalUnmarshalPojoTest {
+
+    
+    @Autowired
+    ProducerTemplate template;
+
+    @EndpointInject("mock:serialized")
+    MockEndpoint mock1;
+    
+    @EndpointInject("mock:pojo")
+    MockEndpoint mock2;
+
+    @Bean("schema-resolver")
+    private SchemaResolver getSchemaResolver() {
+        String schemaJson = "{\n"
+            + "\"type\": \"record\",\n"
+            + "\"name\": \"Pojo\",\n"
+            + "\"fields\": [\n"
+            + " {\"name\": \"text\", \"type\": \"string\"}\n"
+            + "]}";
+        Schema raw = new Schema.Parser().setValidate(true).parse(schemaJson);
+        AvroSchema schema = new AvroSchema(raw);
+        SchemaResolver resolver = ex -> schema;
+        
+        return resolver;
+    }
+    
+    @Test
+    public void testMarshalUnmarshalPojo() throws Exception {
+        
+        mock1.expectedMessageCount(1);
+        mock1.message(0).body().isInstanceOf(byte[].class);
+
+        Pojo pojo = new Pojo("Hello");
+        template.sendBody("direct:pojo", pojo);
+
+        mock1.assertIsSatisfied();
+
+        byte[] serialized = mock1.getReceivedExchanges().get(0).getIn().getBody(byte[].class);
+        assertNotNull(serialized);
+        assertEquals(6, serialized.length);
+
+        
+        mock2.expectedMessageCount(1);
+        mock2.message(0).body().isInstanceOf(Pojo.class);
+
+        template.sendBody("direct:serialized", serialized);
+        mock2.assertIsSatisfied();
+
+        Pojo back = mock2.getReceivedExchanges().get(0).getIn().getBody(Pojo.class);
+
+        assertEquals(pojo.getText(), back.getText());
+    }
+
+
+
+    // *************************************
+    // Config
+    // *************************************
+
+    @Configuration
+    public static class TestConfiguration {
+
+        @Bean
+        public RouteBuilder routeBuilder() {
+            return new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    from("direct:serialized").unmarshal().avro(AvroLibrary.Jackson, Pojo.class).to("mock:pojo");
+                    from("direct:pojo").marshal().avro(AvroLibrary.Jackson).to("mock:serialized");
+                }
+            };
+        }
+    }
+    
+    public static class Pojo {
+
+        private String text;
+
+        public Pojo() {
+        }
+
+        public Pojo(String text) {
+            this.text = text;
+        }
+
+        public String getText() {
+            return text;
+        }
+
+        public void setText(String text) {
+            this.text = text;
+        }
+    }
+
+    
+    
+}