/* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html */ package org.opendaylight.controller.netconf.persist.impl; import static org.junit.Assert.assertEquals; import com.google.common.collect.Sets; import java.io.IOException; import java.util.HashSet; import java.util.Set; import org.apache.commons.io.IOUtils; import org.junit.Test; import org.opendaylight.controller.netconf.util.xml.XmlUtil; import org.w3c.dom.Element; public class CapabilityStrippingConfigSnapshotHolderTest { @Test public void testCapabilityStripping() throws Exception { Set allCapabilities = readLines("/capabilities-all.txt"); Set expectedCapabilities = readLines("/capabilities-stripped.txt"); String snapshotAsString = readToString("/snapshot.xml"); Element element = XmlUtil.readXmlToElement(snapshotAsString); CapabilityStrippingConfigSnapshotHolder tested = new CapabilityStrippingConfigSnapshotHolder( element, allCapabilities); assertEquals(expectedCapabilities, tested.getCapabilities()); Set obsoleteCapabilities = Sets.difference(allCapabilities, expectedCapabilities); assertEquals(obsoleteCapabilities, tested.getObsoleteCapabilities()); } private Set readLines(String fileName) throws IOException { return new HashSet<>(IOUtils.readLines(getClass().getResourceAsStream(fileName))); } private String readToString(String fileName) throws IOException { return IOUtils.toString(getClass().getResourceAsStream(fileName)); } }