Decouple config and netconf subsystems.
[controller.git] / opendaylight / netconf / netconf-util / src / test / java / org / opendaylight / controller / netconf / util / xml / XMLNetconfUtilTest.java
diff --git a/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/xml/XMLNetconfUtilTest.java b/opendaylight/netconf/netconf-util/src/test/java/org/opendaylight/controller/netconf/util/xml/XMLNetconfUtilTest.java
new file mode 100644 (file)
index 0000000..c702f6c
--- /dev/null
@@ -0,0 +1,25 @@
+package org.opendaylight.controller.netconf.util.xml;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import org.junit.Test;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
+import org.w3c.dom.Element;
+
+public class XMLNetconfUtilTest {
+
+    @Test
+    public void testXPath() throws Exception {
+        final XPathExpression correctXPath = XMLNetconfUtil.compileXPath("/top/innerText");
+        try {
+            XMLNetconfUtil.compileXPath("!@(*&$!");
+            fail("Incorrect xpath should fail");
+        } catch (IllegalStateException e) {}
+        final Object value = XmlUtil.evaluateXPath(correctXPath, XmlUtil.readXmlToDocument("<top><innerText>value</innerText></top>"), XPathConstants.NODE);
+        assertEquals("value", ((Element) value).getTextContent());
+    }
+
+}
\ No newline at end of file