Merge "Add filtering capability to config.ini in order to reference logging bridge...
[controller.git] / opendaylight / netconf / config-persister-impl / src / test / java / org / opendaylight / controller / netconf / persist / impl / CapabilityStrippingConfigSnapshotHolderTest.java
1 /*
2  * Copyright (c) 2013 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 package org.opendaylight.controller.netconf.persist.impl;
9
10 import com.google.common.collect.Sets;
11 import org.apache.commons.io.IOUtils;
12 import org.junit.Test;
13 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
14 import org.w3c.dom.Element;
15
16 import java.io.IOException;
17 import java.util.HashSet;
18 import java.util.Set;
19
20 import static org.junit.Assert.assertEquals;
21
22 public class CapabilityStrippingConfigSnapshotHolderTest {
23
24     @Test
25     public void testCapabilityStripping() throws Exception {
26         Set<String> allCapabilities = readLines("/capabilities-all.txt");
27         Set<String> expectedCapabilities = readLines("/capabilities-stripped.txt");
28         String snapshotAsString = readToString("/snapshot.xml");
29         Element element = XmlUtil.readXmlToElement(snapshotAsString);
30         CapabilityStrippingConfigSnapshotHolder tested = new CapabilityStrippingConfigSnapshotHolder(
31                 element, allCapabilities);
32         assertEquals(expectedCapabilities, tested.getCapabilities());
33
34         Set<String> obsoleteCapabilities = Sets.difference(allCapabilities, expectedCapabilities);
35
36         assertEquals(obsoleteCapabilities, tested.getObsoleteCapabilities());
37     }
38
39     private Set<String> readLines(String fileName) throws IOException {
40         return new HashSet<>(IOUtils.readLines(getClass().getResourceAsStream(fileName)));
41     }
42
43     private String readToString(String fileName) throws IOException {
44         return IOUtils.toString(getClass().getResourceAsStream(fileName));
45     }
46
47 }