camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bvah...@apache.org
Subject git commit: CAMEL-7874: Fix the non-working prettyPrint option by the json dataformat
Date Sat, 27 Sep 2014 19:59:40 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x 47725f76e -> ce90e4379


CAMEL-7874: Fix the non-working prettyPrint option by the json
dataformat


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

Branch: refs/heads/camel-2.14.x
Commit: ce90e4379fae3d5f09eb997885ac28d08b24c3f4
Parents: 47725f7
Author: Babak Vahdat <bvahdat@apache.org>
Authored: Sat Sep 27 21:46:27 2014 +0200
Committer: Babak Vahdat <bvahdat@apache.org>
Committed: Sat Sep 27 21:53:53 2014 +0200

----------------------------------------------------------------------
 .../camel/model/dataformat/JsonDataFormat.java  |  2 +-
 .../jackson/JacksonJsonDataFormatTest.java      |  7 +++++
 .../component/jackson/JacksonMarshalTest.java   | 30 ++++++++++++++++++--
 .../SpringJacksonJsonDataFormatTest.java        | 22 ++++++++++++++
 .../jackson/SpringJacksonJsonDataFormatTest.xml |  6 ++++
 5 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/ce90e437/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
b/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
index 5869d12..15c5a81 100644
--- a/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
+++ b/camel-core/src/main/java/org/apache/camel/model/dataformat/JsonDataFormat.java
@@ -170,7 +170,7 @@ public class JsonDataFormat extends DataFormatDefinition {
             setProperty(camelContext, dataFormat, "unmarshalType", unmarshalType);
         }
         if (prettyPrint != null) {
-            setProperty(camelContext, dataFormat, "prettyPrint", unmarshalType);
+            setProperty(camelContext, dataFormat, "prettyPrint", prettyPrint);
         }
         if (jsonView != null) {
             setProperty(camelContext, dataFormat, "jsonView", jsonView);

http://git-wip-us.apache.org/repos/asf/camel/blob/ce90e437/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java
index 292179c..dfaa3ce 100644
--- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java
+++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJsonDataFormatTest.java
@@ -29,6 +29,13 @@ public class JacksonJsonDataFormatTest extends JacksonMarshalTest {
                 from("direct:in").marshal().json(JsonLibrary.Jackson);
                 from("direct:back").unmarshal().json(JsonLibrary.Jackson).to("mock:reverse");
 
+                // no possible usage of the json() DSL method here as there's no prettyPrint
option available through it
+                JacksonDataFormat prettyPrintDataFormat = new JacksonDataFormat();
+                prettyPrintDataFormat.setPrettyPrint(true);
+
+                from("direct:pretty").marshal(prettyPrintDataFormat);
+                from("direct:backPretty").unmarshal(prettyPrintDataFormat).to("mock:reverse");
+
                 from("direct:inPojo").marshal().json(JsonLibrary.Jackson);
                 from("direct:backPojo").unmarshal().json(JsonLibrary.Jackson, TestPojo.class).to("mock:reversePojo");
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/ce90e437/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java
index b113e5e..bd5de84 100644
--- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java
+++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonMarshalTest.java
@@ -28,7 +28,6 @@ public class JacksonMarshalTest extends CamelTestSupport {
 
     @Test
     public void testMarshalAndUnmarshalMap() throws Exception {
-
         Map<String, Object> in = new HashMap<String, Object>();
         in.put("name", "Camel");
 
@@ -47,8 +46,29 @@ public class JacksonMarshalTest extends CamelTestSupport {
     }
 
     @Test
-    public void testMarshalAndUnmarshalPojo() throws Exception {
+    public void testMarshalAndUnmarshalMapWithPrettyPrint() 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().equals(in);
 
+        Object marshalled = template.requestBody("direct:pretty", in);
+        String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled);
+        String expected = "{\n"
+                         + "  \"name\" : \"Camel\""
+                         + "\n}";
+        assertEquals(expected, marshalledAsString);
+
+        template.sendBody("direct:backPretty", marshalled);
+
+        mock.assertIsSatisfied();
+    }
+
+    @Test
+    public void testMarshalAndUnmarshalPojo() throws Exception {
         TestPojo in = new TestPojo();
         in.setName("Camel");
 
@@ -78,6 +98,12 @@ public class JacksonMarshalTest extends CamelTestSupport {
                 from("direct:in").marshal(format);
                 from("direct:back").unmarshal(format).to("mock:reverse");
 
+                JacksonDataFormat prettyPrintDataFormat = new JacksonDataFormat();
+                prettyPrintDataFormat.setPrettyPrint(true);
+
+                from("direct:pretty").marshal(prettyPrintDataFormat);
+                from("direct:backPretty").unmarshal(prettyPrintDataFormat).to("mock:reverse");
+
                 JacksonDataFormat formatPojo = new JacksonDataFormat(TestPojo.class);
 
                 from("direct:inPojo").marshal(formatPojo);

http://git-wip-us.apache.org/repos/asf/camel/blob/ce90e437/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.java
b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.java
index ab2ac06..ea22b3b 100644
--- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.java
+++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.java
@@ -50,6 +50,28 @@ public class SpringJacksonJsonDataFormatTest extends CamelSpringTestSupport
{
     }
 
     @Test
+    public void testMarshalAndUnmarshalMapWithPrettyPrint() 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().equals(in);
+
+        Object marshalled = template.requestBody("direct:pretty", in);
+        String marshalledAsString = context.getTypeConverter().convertTo(String.class, marshalled);
+        String expected = "{\n"
+                        + "  \"name\" : \"Camel\""
+                        + "\n}";
+        assertEquals(expected, marshalledAsString);
+
+        template.sendBody("direct:back", marshalled);
+
+        mock.assertIsSatisfied();
+    }
+
+    @Test
     public void testMarshalAndUnmarshalPojo() throws Exception {
         TestPojo in = new TestPojo();
         in.setName("Camel");

http://git-wip-us.apache.org/repos/asf/camel/blob/ce90e437/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml
b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml
index a5182ea..61bd1a0 100644
--- a/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml
+++ b/components/camel-jackson/src/test/resources/org/apache/camel/component/jackson/SpringJacksonJsonDataFormatTest.xml
@@ -29,6 +29,7 @@
         <dataFormats>
             <!-- this uses the default unmarshal type that is a Map based -->
             <json id="jack" library="Jackson"/>
+            <json id="pretty" library="Jackson" prettyPrint="true"/>
             <!-- and this one uses our own TestPojo class as unmarshal type -->
             <json id="pojo" library="Jackson" unmarshalTypeName="org.apache.camel.component.jackson.TestPojo"/>
             <!-- in addition to our own TestPojoView class we make use of the jsonView
attribute here as filter -->
@@ -41,6 +42,11 @@
         </route>
 
         <route>
+            <from uri="direct:pretty"/>
+            <marshal ref="pretty"/>
+        </route>
+
+        <route>
             <from uri="direct:back"/>
             <unmarshal ref="jack"/>
             <to uri="mock:reverse"/>


Mime
View raw message