Search in sources :

Example 6 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class XPathTest method testXPathNodeSetResult.

public void testXPathNodeSetResult() throws Exception {
    Object result = xpath("/foo").nodeSetResult().evaluate(createExchange("<foo>bar</foo>"));
    NodeList node = assertIsInstanceOf(NodeList.class, result);
    assertNotNull(node);
    String s = context.getTypeConverter().convertTo(String.class, node);
    assertEquals("<foo>bar</foo>", s);
}
Also used : NodeList(org.w3c.dom.NodeList)

Example 7 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class DumpModelAsXmlSplitBodyRouteTest method testDumpModelAsXml.

public void testDumpModelAsXml() throws Exception {
    String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
    assertNotNull(xml);
    log.info(xml);
    Document doc = new XmlConverter().toDOMDocument(xml);
    NodeList nodes = doc.getElementsByTagName("simple");
    assertEquals(1, nodes.getLength());
    Element node = (Element) nodes.item(0);
    assertNotNull("Node <simple> expected to be instanceof Element", node);
    assertEquals("body", node.getTextContent());
    nodes = doc.getElementsByTagName("split");
    assertEquals(1, nodes.getLength());
    nodes = doc.getElementsByTagName("to");
    assertEquals(1, nodes.getLength());
    node = (Element) nodes.item(0);
    assertNotNull("Node <to> expected to be instanceof Element", node);
    assertEquals("mock:sub", node.getAttribute("uri"));
    assertEquals("myMock", node.getAttribute("id"));
    assertEquals("true", node.getAttribute("customId"));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 8 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class DumpModelAsXmlTransformRouteConstantTest method testDumpModelAsXml.

public void testDumpModelAsXml() throws Exception {
    String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
    assertNotNull(xml);
    log.info(xml);
    Document doc = new XmlConverter().toDOMDocument(xml);
    NodeList nodes = doc.getElementsByTagName("constant");
    assertEquals(1, nodes.getLength());
    Element node = (Element) nodes.item(0);
    assertNotNull("Node <simple> expected to be instanceof Element", node);
    assertEquals("Hello World", node.getTextContent());
    nodes = doc.getElementsByTagName("to");
    assertEquals(1, nodes.getLength());
    node = (Element) nodes.item(0);
    assertNotNull("Node <to> expected to be instanceof Element", node);
    assertEquals("mock:result", node.getAttribute("uri"));
    assertEquals("myMock", node.getAttribute("id"));
    assertEquals("true", node.getAttribute("customId"));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 9 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class DumpModelAsXmlTransformRouteLanguageTest method testDumpModelAsXml.

public void testDumpModelAsXml() throws Exception {
    String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
    assertNotNull(xml);
    log.info(xml);
    Document doc = new XmlConverter().toDOMDocument(xml);
    NodeList nodes = doc.getElementsByTagName("language");
    assertEquals(1, nodes.getLength());
    Element node = (Element) nodes.item(0);
    assertNotNull("Node <simple> expected to be instanceof Element", node);
    assertEquals("constant", node.getAttribute("language"));
    assertEquals("Hello World", node.getTextContent());
    nodes = doc.getElementsByTagName("to");
    assertEquals(1, nodes.getLength());
    node = (Element) nodes.item(0);
    assertNotNull("Node <to> expected to be instanceof Element", node);
    assertEquals("mock:result", node.getAttribute("uri"));
    assertEquals("myMock", node.getAttribute("id"));
    assertEquals("true", node.getAttribute("customId"));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 10 with NodeList

use of org.w3c.dom.NodeList in project camel by apache.

the class DumpModelAsXmlTransformRouteTest method testDumpModelAsXml.

public void testDumpModelAsXml() throws Exception {
    String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
    assertNotNull(xml);
    log.info(xml);
    Document doc = new XmlConverter().toDOMDocument(xml);
    NodeList nodes = doc.getElementsByTagName("simple");
    assertEquals(1, nodes.getLength());
    Element node = (Element) nodes.item(0);
    assertNotNull("Node <simple> expected to be instanceof Element", node);
    assertEquals("Hello ${body}", node.getTextContent());
    nodes = doc.getElementsByTagName("to");
    assertEquals(1, nodes.getLength());
    node = (Element) nodes.item(0);
    assertNotNull("Node <to> expected to be instanceof Element", node);
    assertEquals("mock:result", node.getAttribute("uri"));
    assertEquals("myMock", node.getAttribute("id"));
    assertEquals("true", node.getAttribute("customId"));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Aggregations

NodeList (org.w3c.dom.NodeList)1806 Node (org.w3c.dom.Node)1059 Element (org.w3c.dom.Element)902 Document (org.w3c.dom.Document)636 ArrayList (java.util.ArrayList)314 DocumentBuilder (javax.xml.parsers.DocumentBuilder)268 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)208 IOException (java.io.IOException)183 NamedNodeMap (org.w3c.dom.NamedNodeMap)144 InputSource (org.xml.sax.InputSource)131 HashMap (java.util.HashMap)121 Test (org.junit.Test)117 SAXException (org.xml.sax.SAXException)117 StringReader (java.io.StringReader)106 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)100 XPath (javax.xml.xpath.XPath)99 Attr (org.w3c.dom.Attr)80 XPathExpressionException (javax.xml.xpath.XPathExpressionException)76 File (java.io.File)64 HashSet (java.util.HashSet)59