You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2014/01/13 20:45:32 UTC
git commit: [XMLJSON] Added more tests.
Updated Branches:
refs/heads/master 275207bc1 -> 126ae0088
[XMLJSON] Added more tests.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/126ae008
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/126ae008
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/126ae008
Branch: refs/heads/master
Commit: 126ae00883b5a11c45294df78281ad349fc0fe82
Parents: 275207b
Author: Henryk Konsek <he...@gmail.com>
Authored: Mon Jan 13 20:45:14 2014 +0100
Committer: Henryk Konsek <he...@gmail.com>
Committed: Mon Jan 13 20:45:14 2014 +0100
----------------------------------------------------------------------
.../xmljson/JsonToXmlAttributesTest.java | 33 ++++++++++++++++++--
.../jsonToXmlElementWithAttributeMessage.json | 4 +++
2 files changed, 35 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/126ae008/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/JsonToXmlAttributesTest.java
----------------------------------------------------------------------
diff --git a/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/JsonToXmlAttributesTest.java b/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/JsonToXmlAttributesTest.java
index a0b455f..744f895 100644
--- a/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/JsonToXmlAttributesTest.java
+++ b/components/camel-xmljson/src/test/java/org/apache/camel/dataformat/xmljson/JsonToXmlAttributesTest.java
@@ -16,8 +16,18 @@
*/
package org.apache.camel.dataformat.xmljson;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
@@ -27,7 +37,7 @@ public class JsonToXmlAttributesTest extends CamelTestSupport {
@Test
public void shouldCreateAttribute() {
// Given
- InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/jsonToXmlAttributesMessage.json");
+ InputStream inStream = getClass().getResourceAsStream("jsonToXmlAttributesMessage.json");
String in = context.getTypeConverter().convertTo(String.class, inStream);
// When
@@ -40,7 +50,7 @@ public class JsonToXmlAttributesTest extends CamelTestSupport {
@Test
public void shouldCreateOnlyOneAttribute() {
// Given
- InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/jsonToXmlAttributesMessage.json");
+ InputStream inStream = getClass().getResourceAsStream("jsonToXmlAttributesMessage.json");
String in = context.getTypeConverter().convertTo(String.class, inStream);
// When
@@ -50,6 +60,25 @@ public class JsonToXmlAttributesTest extends CamelTestSupport {
assertFalse(xml.contains("a="));
}
+ @Test
+ public void shouldCreateElementWithAttribute() throws ParserConfigurationException, IOException, SAXException {
+ // Given
+ InputStream inStream = getClass().getResourceAsStream("jsonToXmlElementWithAttributeMessage.json");
+ String in = context.getTypeConverter().convertTo(String.class, inStream);
+
+ // When
+ String xml = template.requestBody("direct:unmarshal", in, String.class);
+
+ // Then
+ Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().
+ parse(new ByteArrayInputStream(xml.getBytes()));
+ NodeList nodeList = document.getDocumentElement().getElementsByTagName("element");
+ assertEquals(1, nodeList.getLength());
+ Element element = (Element) nodeList.item(0);
+ assertEquals("elementContent", element.getTextContent());
+ assertEquals("attributeValue", element.getAttribute("attribute"));
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
http://git-wip-us.apache.org/repos/asf/camel/blob/126ae008/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/jsonToXmlElementWithAttributeMessage.json
----------------------------------------------------------------------
diff --git a/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/jsonToXmlElementWithAttributeMessage.json b/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/jsonToXmlElementWithAttributeMessage.json
new file mode 100644
index 0000000..77afc6f
--- /dev/null
+++ b/components/camel-xmljson/src/test/resources/org/apache/camel/dataformat/xmljson/jsonToXmlElementWithAttributeMessage.json
@@ -0,0 +1,4 @@
+{ "element": {
+ "@attribute": "attributeValue",
+ "#text": "elementContent"
+}}
\ No newline at end of file