X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-persister-directory-xml-adapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fstorage%2Fdirectory%2Fxml%2FDirectoryStorageAdapterTest.java;fp=opendaylight%2Fconfig%2Fconfig-persister-directory-xml-adapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fpersist%2Fstorage%2Fdirectory%2Fxml%2FDirectoryStorageAdapterTest.java;h=73061f81de0d79ceae90b99852b9e8989faa0d45;hb=23ec2c1ab1e9266029437be0818101efbc74450e;hp=0000000000000000000000000000000000000000;hpb=aea39142ff1a2a5fc6183cf11f99fe2199259be8;p=controller.git diff --git a/opendaylight/config/config-persister-directory-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/xml/DirectoryStorageAdapterTest.java b/opendaylight/config/config-persister-directory-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/xml/DirectoryStorageAdapterTest.java new file mode 100644 index 0000000000..73061f81de --- /dev/null +++ b/opendaylight/config/config-persister-directory-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/xml/DirectoryStorageAdapterTest.java @@ -0,0 +1,88 @@ +/* + * 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.config.persist.storage.directory.xml; + +import org.junit.Test; +import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; + +import java.io.File; +import java.util.Collections; +import java.util.List; +import java.util.SortedSet; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class DirectoryStorageAdapterTest { + XmlDirectoryPersister tested; + + @Test + public void testEmptyDirectory() throws Exception { + File folder = new File("target/emptyFolder"); + folder.mkdir(); + tested = new XmlDirectoryPersister((folder)); + assertEquals(Collections.emptyList(), tested.loadLastConfigs()); + + try { + tested.persistConfig(new ConfigSnapshotHolder() { + @Override + public String getConfigSnapshot() { + throw new RuntimeException(); + } + + @Override + public SortedSet getCapabilities() { + throw new RuntimeException(); + } + }); + fail(); + } catch (UnsupportedOperationException e) { + + } + } + + private File getFolder(String folderName) { + File result = new File(("src/test/resources/" + + folderName).replace("/", File.separator)); + assertTrue(result + " is not a directory", result.isDirectory()); + return result; + } + + @Test + public void testOneFile() throws Exception { + File folder = getFolder("oneFile"); + tested = new XmlDirectoryPersister((folder)); + List results = tested.loadLastConfigs(); + assertEquals(1, results.size()); + ConfigSnapshotHolder result = results.get(0); + assertResult(result, "1", "cap1&rev", "cap2", "capa a"); + } + + private void assertResult(ConfigSnapshotHolder result, String s, String... caps) { + assertEquals(s, result.getConfigSnapshot().replaceAll("\\s", "")); + int i = 0; + for (String capFromSnapshot : result.getCapabilities()) { + assertEquals(capFromSnapshot, caps[i++]); + } + } + + @Test + public void testTwoFiles() throws Exception { + File folder = getFolder("twoFiles"); + tested = new XmlDirectoryPersister((folder)); + List results = tested.loadLastConfigs(); + assertEquals(2, results.size()); + + assertResult(results.get(0), "1", "cap1-a", "cap2-a", "capa a-a"); + assertResult(results.get(1), "2", "cap1-b", "cap2-b", "capa a-b"); + + } + +}