1 package org.opendaylight.controller.netconf.util.xml;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.fail;
6 import javax.xml.xpath.XPathConstants;
7 import javax.xml.xpath.XPathExpression;
9 import org.opendaylight.controller.config.util.xml.XmlUtil;
10 import org.w3c.dom.Element;
12 public class XMLNetconfUtilTest {
15 public void testXPath() throws Exception {
16 final XPathExpression correctXPath = XMLNetconfUtil.compileXPath("/top/innerText");
18 XMLNetconfUtil.compileXPath("!@(*&$!");
19 fail("Incorrect xpath should fail");
20 } catch (IllegalStateException e) {}
21 final Object value = XmlUtil.evaluateXPath(correctXPath, XmlUtil.readXmlToDocument("<top><innerText>value</innerText></top>"), XPathConstants.NODE);
22 assertEquals("value", ((Element) value).getTextContent());