Merge "Bug 8153: Enforce check-style rules for netconf - aaa-authn-odl-plugin"
[netconf.git] / netconf / netconf-util / src / test / java / org / opendaylight / netconf / util / xml / XMLNetconfUtilTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.netconf.util.xml;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import static org.junit.Assert.fail;
14
15 import javax.xml.xpath.XPathConstants;
16 import javax.xml.xpath.XPathExpression;
17 import org.junit.Test;
18 import org.opendaylight.controller.config.util.xml.XmlUtil;
19 import org.w3c.dom.Element;
20
21 public class XMLNetconfUtilTest {
22
23     @Test
24     public void testXPath() throws Exception {
25         final XPathExpression correctXPath = XMLNetconfUtil.compileXPath("/top/innerText");
26         try {
27             XMLNetconfUtil.compileXPath("!@(*&$!");
28             fail("Incorrect xpath should fail");
29         } catch (IllegalStateException e) {
30             assertTrue(e.getMessage().startsWith("Error while compiling xpath expression "));
31         }
32         final Object value = XmlUtil.evaluateXPath(correctXPath,
33                 XmlUtil.readXmlToDocument("<top><innerText>value</innerText></top>"), XPathConstants.NODE);
34         assertEquals("value", ((Element) value).getTextContent());
35     }
36
37 }