2 * Copyright (c) 2016 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
8 package org.opendaylight.netconf.server.spi;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertFalse;
13 import java.util.stream.Stream;
14 import org.junit.jupiter.params.ParameterizedTest;
15 import org.junit.jupiter.params.provider.MethodSource;
16 import org.opendaylight.netconf.api.xml.XmlElement;
17 import org.opendaylight.netconf.api.xml.XmlUtil;
18 import org.w3c.dom.Document;
19 import org.xmlunit.builder.DiffBuilder;
21 class SubtreeFilterNotificationTest {
25 void testFilterNotification(final int directoryIndex) throws Exception {
26 final var filter = XmlElement.fromDomDocument(getDocument(directoryIndex, "filter.xml"));
27 final var preFilter = getDocument(directoryIndex, "pre-filter.xml");
28 final var expectedPostFilter = getDocument(directoryIndex, "post-filter.xml");
29 final var postFilterOpt = SubtreeFilter.applySubtreeNotificationFilter(filter, preFilter);
30 if (postFilterOpt.isPresent()) {
31 final var diff = DiffBuilder.compare(postFilterOpt.orElseThrow())
32 .withTest(expectedPostFilter)
36 assertFalse(diff.hasDifferences(), diff.toString());
38 assertEquals("empty", XmlElement.fromDomDocument(expectedPostFilter).getName());
42 private static Stream<Integer> testFilterNotification() {
43 return Stream.of(0, 1, 2, 3, 4);
46 private Document getDocument(final int directoryIndex, final String fileName) throws Exception {
47 return XmlUtil.readXmlToDocument(SubtreeFilterNotificationTest.class.getResourceAsStream(
48 "/subtree/notification/" + directoryIndex + "/" + fileName));