2 * Copyright (c) 2013 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.config.persist.storage.directory.xml;
11 import org.junit.Test;
12 import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.SortedSet;
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 import static org.junit.Assert.fail;
23 public class DirectoryStorageAdapterTest {
24 XmlDirectoryPersister tested;
27 public void testEmptyDirectory() throws Exception {
28 File folder = new File("target/emptyFolder");
30 tested = new XmlDirectoryPersister((folder));
31 assertEquals(Collections.<ConfigSnapshotHolder>emptyList(), tested.loadLastConfigs());
34 tested.persistConfig(new ConfigSnapshotHolder() {
36 public String getConfigSnapshot() {
37 throw new RuntimeException();
41 public SortedSet<String> getCapabilities() {
42 throw new RuntimeException();
46 } catch (UnsupportedOperationException e) {
51 private File getFolder(String folderName) {
52 File result = new File(("src/test/resources/" +
53 folderName).replace("/", File.separator));
54 assertTrue(result + " is not a directory", result.isDirectory());
59 public void testOneFile() throws Exception {
60 File folder = getFolder("oneFile");
61 tested = new XmlDirectoryPersister((folder));
62 List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
63 assertEquals(1, results.size());
64 ConfigSnapshotHolder result = results.get(0);
65 assertResult(result, "<config>1</config>", "cap1&rev", "cap2", "capa a");
68 private void assertResult(ConfigSnapshotHolder result, String s, String... caps) {
69 assertEquals(s, result.getConfigSnapshot().replaceAll("\\s", ""));
71 for (String capFromSnapshot : result.getCapabilities()) {
72 assertEquals(capFromSnapshot, caps[i++]);
77 public void testTwoFiles() throws Exception {
78 File folder = getFolder("twoFiles");
79 tested = new XmlDirectoryPersister((folder));
80 List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
81 assertEquals(2, results.size());
83 assertResult(results.get(0), "<config>1</config>", "cap1-a", "cap2-a", "capa a-a");
84 assertResult(results.get(1), "<config>2</config>", "cap1-b", "cap2-b", "capa a-b");