Filter non-standard nodes from NETCONF monitoring schemas
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / NC881Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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 package org.opendaylight.netconf.sal.connect.netconf;
9
10 import static org.junit.Assert.assertTrue;
11
12 import java.io.IOException;
13 import javax.xml.transform.dom.DOMSource;
14 import org.custommonkey.xmlunit.XMLUnit;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17 import org.opendaylight.netconf.api.xml.XmlUtil;
18 import org.xml.sax.SAXException;
19
20 public class NC881Test {
21     @BeforeClass
22     public static void classSetUp() {
23         XMLUnit.setIgnoreWhitespace(true);
24     }
25
26     @Test
27     public void testFilterDomNamespaces() throws IOException, SAXException {
28         final var source = XmlUtil.readXmlToDocument(
29                 getClass().getResourceAsStream("/nc881/netconf-state.xml"));
30         final var expected = XmlUtil.readXmlToDocument(
31                 getClass().getResourceAsStream("/nc881/netconf-state-filtered.xml"));
32
33         final var filteredDom = NetconfStateSchemas.ietfMonitoringCopy(new DOMSource(source.getDocumentElement()));
34         final var filtered = XmlUtil.newDocument();
35         filtered.appendChild(filtered.importNode(filteredDom.getNode(), true));
36
37         final var diff = XMLUnit.compareXML(filtered, expected);
38         assertTrue(diff.toString(), diff.similar());
39     }
40 }