c702f6cab9d7683c7586747fbf699c2fca3a3c94
[controller.git] / opendaylight / netconf / netconf-util / src / test / java / org / opendaylight / controller / netconf / util / xml / XMLNetconfUtilTest.java
1 package org.opendaylight.controller.netconf.util.xml;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.fail;
5
6 import javax.xml.xpath.XPathConstants;
7 import javax.xml.xpath.XPathExpression;
8 import org.junit.Test;
9 import org.opendaylight.controller.config.util.xml.XmlUtil;
10 import org.w3c.dom.Element;
11
12 public class XMLNetconfUtilTest {
13
14     @Test
15     public void testXPath() throws Exception {
16         final XPathExpression correctXPath = XMLNetconfUtil.compileXPath("/top/innerText");
17         try {
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());
23     }
24
25 }