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 2014/09/05 08:42:25 UTC

[1/6] git commit: Add GPathResult converter tests

Repository: camel
Updated Branches:
  refs/heads/master ce8aac572 -> f4b7333c3


Add GPathResult converter tests


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

Branch: refs/heads/master
Commit: bc7a50cf9c80bce0b2e58201bb657789330c0b4e
Parents: 75b2c0a
Author: Dominik Adam Przybysz <al...@gmail.com>
Authored: Sun Aug 17 20:55:33 2014 +0200
Committer: Dominik Adam Przybysz <al...@gmail.com>
Committed: Sun Aug 17 21:07:44 2014 +0200

----------------------------------------------------------------------
 .../groovy/converter/GPathResultConverter.java  |  8 ++++
 .../services/org/apache/camel/TypeConverter     |  3 +-
 .../converter/GPathResultConverterTest.groovy   | 48 ++++++++++++++++++++
 3 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bc7a50cf/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
new file mode 100644
index 0000000..12802e3
--- /dev/null
+++ b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
@@ -0,0 +1,8 @@
+package org.apache.camel.groovy.converter;
+
+import org.apache.camel.Converter;
+
+@Converter
+public class GPathResultConverter {
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/bc7a50cf/components/camel-groovy/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/main/resources/META-INF/services/org/apache/camel/TypeConverter b/components/camel-groovy/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
index 62a0595..8a0e315 100644
--- a/components/camel-groovy/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
+++ b/components/camel-groovy/src/main/resources/META-INF/services/org/apache/camel/TypeConverter
@@ -14,4 +14,5 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-org.apache.camel.groovy.converter.TypeConverter
\ No newline at end of file
+org.apache.camel.groovy.converter.TypeConverter
+org.apache.camel.groovy.converter.GPathResultConverter
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/bc7a50cf/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
new file mode 100644
index 0000000..22daa5e
--- /dev/null
+++ b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
@@ -0,0 +1,48 @@
+package org.apache.camel.groovy.converter
+
+import groovy.util.slurpersupport.GPathResult
+import org.apache.camel.CamelContext
+import org.apache.camel.Exchange
+import org.apache.camel.StringSource
+import org.apache.camel.impl.DefaultCamelContext
+import org.apache.camel.impl.DefaultExchange
+import org.junit.Test
+import org.w3c.dom.Node
+
+import static org.junit.Assert.assertEquals
+
+public class GPathResultConverterTest {
+    String xml = "<test><elem1>This is test</elem1></test>"
+    CamelContext context = new DefaultCamelContext()
+
+    @Test
+    void "should convert string to GPathResult"() {
+        Exchange exchange = new DefaultExchange(context)
+        exchange.in.setBody(xml, String)
+        GPathResult result = exchange.in.getBody(GPathResult)
+        checkGPathResult(result)
+    }
+
+    @Test
+    void "should convert string source to GPathResult"() {
+        StringSource input = new StringSource(xml)
+        Exchange exchange = new DefaultExchange(context)
+        exchange.in.setBody(input, StringSource)
+        GPathResult result = exchange.in.getBody(GPathResult)
+        checkGPathResult(result)
+    }
+
+    @Test
+    void "should convert node to GPathResult"() {
+        Node node = new XmlParser().parseText(xml)
+        Exchange exchange = new DefaultExchange(context)
+        exchange.in.setBody(node, Node)
+        GPathResult result = exchange.in.getBody(GPathResult)
+        checkGPathResult(result)
+    }
+
+    private void checkGPathResult(GPathResult gPathResult) {
+        assertEquals(gPathResult.name(), "test")
+        assertEquals(gPathResult.elem1.text(), "This is test")
+    }
+}
\ No newline at end of file


[3/6] git commit: Rewrite converting Node to GPathResult

Posted by da...@apache.org.
Rewrite converting Node to GPathResult


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

Branch: refs/heads/master
Commit: e657822b7d905af1951765211dae7d205f18acaf
Parents: c9e26a5
Author: Dominik Adam Przybysz <al...@gmail.com>
Authored: Sun Aug 17 22:38:56 2014 +0200
Committer: Dominik Adam Przybysz <al...@gmail.com>
Committed: Sun Aug 17 22:38:56 2014 +0200

----------------------------------------------------------------------
 .../camel/groovy/converter/GPathResultConverter.java | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e657822b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
index e5008a8..f3c9118 100644
--- a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
+++ b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
@@ -4,7 +4,9 @@ import groovy.util.XmlSlurper;
 import groovy.util.slurpersupport.GPathResult;
 import groovy.xml.StreamingMarkupBuilder;
 import org.apache.camel.Converter;
+import org.apache.camel.Exchange;
 import org.apache.camel.StringSource;
+import org.apache.camel.converter.jaxp.XmlConverter;
 import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 
@@ -21,21 +23,20 @@ import java.io.StringWriter;
 @Converter
 public class GPathResultConverter {
 
+    private final XmlConverter xmlConverter = new XmlConverter();
+
     @Converter
-    public static GPathResult fromString(String input) throws ParserConfigurationException, SAXException, IOException {
+    public GPathResult fromString(String input) throws ParserConfigurationException, SAXException, IOException {
         return new XmlSlurper().parseText(input);
     }
 
     @Converter
-    public static GPathResult fromStringSource(StringSource input) throws IOException, SAXException, ParserConfigurationException {
+    public GPathResult fromStringSource(StringSource input) throws IOException, SAXException, ParserConfigurationException {
         return fromString(input.getText());
     }
 
     @Converter
-    public static GPathResult fromNode(Node input) throws IOException, SAXException, ParserConfigurationException, TransformerException {
-        StringWriter writer = new StringWriter();
-        Transformer t = TransformerFactory.newInstance().newTransformer();
-        t.transform(new DOMSource(input), new StreamResult(writer));
-        return fromString(writer.toString());
+    public GPathResult fromNode(Node input, Exchange exchange) throws IOException, SAXException, ParserConfigurationException, TransformerException {
+        return fromString(xmlConverter.toString(input, exchange));
     }
 }


[6/6] git commit: Fixed CS

Posted by da...@apache.org.
Fixed CS


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

Branch: refs/heads/master
Commit: f4b7333c34c1d389bd0386c24aab34ea6fc85b31
Parents: 5511262
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Sep 5 08:42:14 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 5 08:42:14 2014 +0200

----------------------------------------------------------------------
 .../groovy/converter/GPathResultConverter.java  | 29 ++++++++++++++++----
 1 file changed, 23 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/f4b7333c/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
index 561fc16..6c7384e 100644
--- a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
+++ b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
@@ -1,17 +1,34 @@
+/**
+ * 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.groovy.converter;
 
+import java.io.IOException;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
 import groovy.util.XmlSlurper;
 import groovy.util.slurpersupport.GPathResult;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.StringSource;
 import org.apache.camel.converter.jaxp.XmlConverter;
-import org.w3c.dom.Node;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.TransformerException;
-import java.io.IOException;
 
 @Converter
 public class GPathResultConverter {


[5/6] git commit: Merge branch 'addGPathResultConverter' of https://github.com/alien11689/camel

Posted by da...@apache.org.
Merge branch 'addGPathResultConverter' of https://github.com/alien11689/camel


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

Branch: refs/heads/master
Commit: 55112629231b8bcaa0b0b288d3f13d7c9e530751
Parents: ce8aac5 7bb8b76
Author: Claus Ibsen <da...@apache.org>
Authored: Fri Sep 5 08:38:16 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Fri Sep 5 08:38:16 2014 +0200

----------------------------------------------------------------------
 .../groovy/converter/GPathResultConverter.java  | 35 +++++++++++++
 .../services/org/apache/camel/TypeConverter     |  3 +-
 .../converter/GPathResultConverterTest.groovy   | 54 ++++++++++++++++++++
 3 files changed, 91 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[4/6] git commit: Organize imports in GPathResultConverter

Posted by da...@apache.org.
Organize imports in GPathResultConverter


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

Branch: refs/heads/master
Commit: 7bb8b76aaa63236965aeacb4a6f98f57ba90b754
Parents: e657822
Author: Dominik Adam Przybysz <al...@gmail.com>
Authored: Sun Aug 17 22:40:37 2014 +0200
Committer: Dominik Adam Przybysz <al...@gmail.com>
Committed: Sun Aug 17 22:40:37 2014 +0200

----------------------------------------------------------------------
 .../apache/camel/groovy/converter/GPathResultConverter.java   | 7 -------
 .../camel/groovy/converter/GPathResultConverterTest.groovy    | 7 ++++---
 2 files changed, 4 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7bb8b76a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
index f3c9118..561fc16 100644
--- a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
+++ b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
@@ -2,7 +2,6 @@ package org.apache.camel.groovy.converter;
 
 import groovy.util.XmlSlurper;
 import groovy.util.slurpersupport.GPathResult;
-import groovy.xml.StreamingMarkupBuilder;
 import org.apache.camel.Converter;
 import org.apache.camel.Exchange;
 import org.apache.camel.StringSource;
@@ -11,14 +10,8 @@ import org.w3c.dom.Node;
 import org.xml.sax.SAXException;
 
 import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
 import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
 import java.io.IOException;
-import java.io.StringWriter;
 
 @Converter
 public class GPathResultConverter {

http://git-wip-us.apache.org/repos/asf/camel/blob/7bb8b76a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
index c17feb8..517cfc0 100644
--- a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
+++ b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
@@ -8,9 +8,10 @@ import org.apache.camel.impl.DefaultCamelContext
 import org.apache.camel.impl.DefaultExchange
 import org.junit.Test
 import org.w3c.dom.Node
-import javax.xml.parsers.DocumentBuilderFactory
 import org.xml.sax.InputSource
 
+import javax.xml.parsers.DocumentBuilderFactory
+
 import static org.junit.Assert.assertEquals
 import static org.junit.Assert.assertNotNull
 
@@ -38,7 +39,7 @@ public class GPathResultConverterTest {
     @Test
     void "should convert node to GPathResult"() {
         Node node = DocumentBuilderFactory.newInstance().newDocumentBuilder()
-					.parse(new InputSource(new StringReader(xml)))
+                .parse(new InputSource(new StringReader(xml)))
         Exchange exchange = new DefaultExchange(context)
         exchange.in.setBody(node, Node)
         GPathResult result = exchange.in.getBody(GPathResult)
@@ -46,7 +47,7 @@ public class GPathResultConverterTest {
     }
 
     private void checkGPathResult(GPathResult gPathResult) {
-		    assertNotNull(gPathResult)
+        assertNotNull(gPathResult)
         assertEquals(gPathResult.name(), "test")
         assertEquals(gPathResult.elem1.text(), "This is test")
     }


[2/6] git commit: Implement GPathConverter methods

Posted by da...@apache.org.
Implement GPathConverter methods


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

Branch: refs/heads/master
Commit: c9e26a52222a1e01b324ade199e731d7a96d9811
Parents: bc7a50c
Author: Dominik Adam Przybysz <al...@gmail.com>
Authored: Sun Aug 17 22:33:59 2014 +0200
Committer: Dominik Adam Przybysz <al...@gmail.com>
Committed: Sun Aug 17 22:33:59 2014 +0200

----------------------------------------------------------------------
 .../groovy/converter/GPathResultConverter.java  | 33 ++++++++++++++++++++
 .../converter/GPathResultConverterTest.groovy   |  9 ++++--
 2 files changed, 40 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c9e26a52/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
index 12802e3..e5008a8 100644
--- a/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
+++ b/components/camel-groovy/src/main/java/org/apache/camel/groovy/converter/GPathResultConverter.java
@@ -1,8 +1,41 @@
 package org.apache.camel.groovy.converter;
 
+import groovy.util.XmlSlurper;
+import groovy.util.slurpersupport.GPathResult;
+import groovy.xml.StreamingMarkupBuilder;
 import org.apache.camel.Converter;
+import org.apache.camel.StringSource;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import java.io.IOException;
+import java.io.StringWriter;
 
 @Converter
 public class GPathResultConverter {
 
+    @Converter
+    public static GPathResult fromString(String input) throws ParserConfigurationException, SAXException, IOException {
+        return new XmlSlurper().parseText(input);
+    }
+
+    @Converter
+    public static GPathResult fromStringSource(StringSource input) throws IOException, SAXException, ParserConfigurationException {
+        return fromString(input.getText());
+    }
+
+    @Converter
+    public static GPathResult fromNode(Node input) throws IOException, SAXException, ParserConfigurationException, TransformerException {
+        StringWriter writer = new StringWriter();
+        Transformer t = TransformerFactory.newInstance().newTransformer();
+        t.transform(new DOMSource(input), new StreamResult(writer));
+        return fromString(writer.toString());
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/c9e26a52/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
----------------------------------------------------------------------
diff --git a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
index 22daa5e..c17feb8 100644
--- a/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
+++ b/components/camel-groovy/src/test/groovy/org/apache/camel/groovy/converter/GPathResultConverterTest.groovy
@@ -8,8 +8,11 @@ import org.apache.camel.impl.DefaultCamelContext
 import org.apache.camel.impl.DefaultExchange
 import org.junit.Test
 import org.w3c.dom.Node
+import javax.xml.parsers.DocumentBuilderFactory
+import org.xml.sax.InputSource
 
 import static org.junit.Assert.assertEquals
+import static org.junit.Assert.assertNotNull
 
 public class GPathResultConverterTest {
     String xml = "<test><elem1>This is test</elem1></test>"
@@ -34,7 +37,8 @@ public class GPathResultConverterTest {
 
     @Test
     void "should convert node to GPathResult"() {
-        Node node = new XmlParser().parseText(xml)
+        Node node = DocumentBuilderFactory.newInstance().newDocumentBuilder()
+					.parse(new InputSource(new StringReader(xml)))
         Exchange exchange = new DefaultExchange(context)
         exchange.in.setBody(node, Node)
         GPathResult result = exchange.in.getBody(GPathResult)
@@ -42,7 +46,8 @@ public class GPathResultConverterTest {
     }
 
     private void checkGPathResult(GPathResult gPathResult) {
+		    assertNotNull(gPathResult)
         assertEquals(gPathResult.name(), "test")
         assertEquals(gPathResult.elem1.text(), "This is test")
     }
-}
\ No newline at end of file
+}