Updated Branches:
  refs/heads/master 735595e54 -> 9dc34bc39

Test that shows https://issues.apache.org/jira/browse/CAMEL-7108 already works 
-- using GenericRecord with camel-avro


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/9dc34bc3
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/9dc34bc3
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/9dc34bc3

Branch: refs/heads/master
Commit: 9dc34bc3941ddffe317c84f5f0d33a89c2a30f7d
Parents: 735595e
Author: Christian Posta <christian.po...@gmail.com>
Authored: Mon Jan 13 12:12:35 2014 -0700
Committer: Christian Posta <christian.po...@gmail.com>
Committed: Mon Jan 13 12:53:55 2014 -0700

----------------------------------------------------------------------
 .../avro/AvroGenericMarshaAndUnmarshaTest.java  | 87 ++++++++++++++++++++
 .../org/apache/camel/dataformat/avro/user.avsc  |  7 ++
 2 files changed, 94 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/9dc34bc3/components/camel-avro/src/test/java/org/apache/camel/dataformat/avro/AvroGenericMarshaAndUnmarshaTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-avro/src/test/java/org/apache/camel/dataformat/avro/AvroGenericMarshaAndUnmarshaTest.java
 
b/components/camel-avro/src/test/java/org/apache/camel/dataformat/avro/AvroGenericMarshaAndUnmarshaTest.java
new file mode 100644
index 0000000..7c202bf
--- /dev/null
+++ 
b/components/camel-avro/src/test/java/org/apache/camel/dataformat/avro/AvroGenericMarshaAndUnmarshaTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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.dataformat.avro;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericData;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+
+/**
+ * @author <a href="http://www.christianposta.com/blog";>Christian Posta</a>
+ */
+public class AvroGenericMarshaAndUnmarshaTest extends CamelTestSupport {
+
+    private Schema schema;
+
+    @Override
+    public void setUp() throws Exception {
+        schema = getSchema();
+        super.setUp();
+    }
+
+    @Test
+    public void testGenericMarshalAndUnmarshal() throws InterruptedException {
+        marshalAndUnmarshalGeneric("direct:in", "direct:back");
+    }
+
+
+    private void marshalAndUnmarshalGeneric(String inURI, String outURI) 
throws InterruptedException {
+        GenericRecord input = new GenericData.Record(schema);
+        input.put("name", "ceposta");
+
+        MockEndpoint mock = getMockEndpoint("mock:reverse");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(GenericRecord.class);
+        mock.message(0).body().equals(input);
+
+        Object marshalled = template.requestBody(inURI, input);
+        template.sendBody(outURI, marshalled);
+        mock.assertIsSatisfied();
+
+        GenericRecord output = 
mock.getReceivedExchanges().get(0).getIn().getBody(GenericRecord.class);
+        assertEquals(input, output);
+
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                AvroDataFormat format = new AvroDataFormat(schema);
+
+                from("direct:in").marshal(format);
+                from("direct:back").unmarshal(format).to("mock:reverse");
+            }
+        };
+    }
+
+    private Schema getSchema() throws IOException {
+        String schemaLocation = getClass().getResource("user.avsc").getFile();
+        File schemaFile = new File(schemaLocation);
+        assertTrue(schemaFile.exists());
+        return new Schema.Parser().parse(schemaFile);
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/9dc34bc3/components/camel-avro/src/test/resources/org/apache/camel/dataformat/avro/user.avsc
----------------------------------------------------------------------
diff --git 
a/components/camel-avro/src/test/resources/org/apache/camel/dataformat/avro/user.avsc
 
b/components/camel-avro/src/test/resources/org/apache/camel/dataformat/avro/user.avsc
new file mode 100644
index 0000000..7df3a77
--- /dev/null
+++ 
b/components/camel-avro/src/test/resources/org/apache/camel/dataformat/avro/user.avsc
@@ -0,0 +1,7 @@
+{"namespace": "example.avro",
+ "type": "record",
+ "name": "User",
+ "fields": [
+     {"name": "name", "type": "string"}
+ ]
+}
\ No newline at end of file

Reply via email to