You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/01/22 08:15:18 UTC

[camel] branch master updated: Added test based on SO issue

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

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new c1ec731  Added test based on SO issue
c1ec731 is described below

commit c1ec73135b2b9f17f78d896a0f35204c2dbe0ba0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Jan 22 09:14:54 2018 +0100

    Added test based on SO issue
---
 .../component/jackson/MyJsonObjectMapper.java      | 22 ++++++++
 .../SpringJacksonObjectMapperRegistryTest.java     | 61 ++++++++++++++++++++++
 .../SpringJacksonObjectMapperRegistryTest.xml      | 48 +++++++++++++++++
 3 files changed, 131 insertions(+)

diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/MyJsonObjectMapper.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/MyJsonObjectMapper.java
new file mode 100644
index 0000000..e0536a4
--- /dev/null
+++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/MyJsonObjectMapper.java
@@ -0,0 +1,22 @@
+/**
+ * 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;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class MyJsonObjectMapper extends ObjectMapper {
+}
diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.java
new file mode 100644
index 0000000..ff30664
--- /dev/null
+++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringJacksonObjectMapperRegistryTest extends CamelSpringTestSupport {
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.xml");
+    }
+
+    @Test
+    public void testMarshalAndUnmarshalMap() throws Exception {
+        Map<String, Object> in = new HashMap<String, Object>();
+        in.put("name", "Camel");
+
+        MockEndpoint mock = getMockEndpoint("mock:reverse");
+        mock.expectedMessageCount(1);
+        mock.message(0).body().isInstanceOf(Map.class);
+        mock.message(0).body().isEqualTo(in);
+
+        Object marshalled = template.requestBody("direct:in", in);
+        String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled);
+        assertEquals("{\"name\":\"Camel\"}", marshalledAsString);
+
+        template.sendBody("direct:back", marshalled);
+
+        mock.assertIsSatisfied();
+
+        MyJsonObjectMapper mapper = (MyJsonObjectMapper) context.getRegistry().lookupByName("myJsonObjectMapper");
+        assertNotNull(mapper);
+
+        JacksonDataFormat df = (JacksonDataFormat) context.getDataFormats().get("jack").getDataFormat();
+        assertNotNull(df);
+        assertSame(mapper, df.getObjectMapper());
+    }
+
+}
diff --git a/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.xml b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.xml
new file mode 100644
index 0000000..f593adb
--- /dev/null
+++ b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonObjectMapperRegistryTest.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+    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.
+
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+  <bean name="myJsonObjectMapper" class="org.apache.camel.component.jackson.MyJsonObjectMapper" primary="true"/>
+
+  <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+    <dataFormats>
+      <json id="jack" library="Jackson" objectMapper="myJsonObjectMapper"/>
+    </dataFormats>
+
+    <route>
+      <from uri="direct:in"/>
+      <marshal ref="jack"/>
+    </route>
+
+    <route>
+      <from uri="direct:back"/>
+      <unmarshal ref="jack"/>
+      <to uri="mock:reverse"/>
+    </route>
+
+  </camelContext>
+
+</beans>

-- 
To stop receiving notification emails like this one, please contact
davsclaus@apache.org.