2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.netconf.impl;
11 import static org.junit.Assert.assertTrue;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
17 import org.custommonkey.xmlunit.Diff;
18 import org.custommonkey.xmlunit.XMLUnit;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.junit.runners.Parameterized;
23 import org.junit.runners.Parameterized.Parameters;
24 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.w3c.dom.Document;
28 import org.xml.sax.SAXException;
30 @RunWith(value = Parameterized.class)
31 public class SubtreeFilterTest {
32 private static final Logger LOG = LoggerFactory.getLogger(SubtreeFilterTest.class);
34 private final int directoryIndex;
37 public static Collection<Object[]> data() {
38 List<Object[]> result = new ArrayList<>();
39 for (int i = 0; i <= 10; i++) {
40 result.add(new Object[]{i});
45 public SubtreeFilterTest(int directoryIndex) {
46 this.directoryIndex = directoryIndex;
51 XMLUnit.setIgnoreWhitespace(true);
55 public void test() throws Exception {
56 Document requestDocument = getDocument("request.xml");
57 Document preFilterDocument = getDocument("pre-filter.xml");
58 Document postFilterDocument = getDocument("post-filter.xml");
59 Document actualPostFilterDocument = SubtreeFilter.applySubtreeFilter(requestDocument, preFilterDocument);
60 LOG.info("Actual document: {}", XmlUtil.toString(actualPostFilterDocument));
61 Diff diff = XMLUnit.compareXML(postFilterDocument, actualPostFilterDocument);
62 assertTrue(diff.toString(), diff.similar());
66 public Document getDocument(String fileName) throws SAXException, IOException {
67 return XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/subtree/" + directoryIndex + "/" +