Search in sources :

Example 1 with PropertiesProviderTest

use of org.opendaylight.controller.config.persist.test.PropertiesProviderTest in project controller by opendaylight.

the class FileStorageAdapterTest method testFileAdapter.

@Test
public void testFileAdapter() throws Exception {
    PropertiesProviderTest pp = new PropertiesProviderTest();
    pp.addProperty("fileStorage", file.getPath());
    pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
    storage.instantiate(pp);
    final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {

        @Override
        public String getConfigSnapshot() {
            return createConfig();
        }

        @Override
        public SortedSet<String> getCapabilities() {
            return createCaps();
        }
    };
    storage.persistConfig(holder);
    storage.persistConfig(holder);
    assertEquals(29, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size());
    List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
    assertEquals(1, lastConf.size());
    ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
    assertXMLEqual("<config>2</config>", configSnapshotHolder.getConfigSnapshot());
    assertEquals(createCaps(), configSnapshotHolder.getCapabilities());
    storage = new XmlFileStorageAdapter();
    storage.setFileStorage(file);
    storage.setNumberOfBackups(Integer.MAX_VALUE);
    List<ConfigSnapshotHolder> last = storage.loadLastConfigs();
    assertEquals(createCaps(), last.get(0).getCapabilities());
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 2 with PropertiesProviderTest

use of org.opendaylight.controller.config.persist.test.PropertiesProviderTest in project controller by opendaylight.

the class FileStorageAdapterTest method testWithFeatures.

@Test
public void testWithFeatures() throws Exception {
    PropertiesProviderTest pp = new PropertiesProviderTest();
    pp.addProperty("fileStorage", file.getPath());
    pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
    storage.instantiate(pp);
    final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {

        @Override
        public String getConfigSnapshot() {
            return createConfig();
        }

        @Override
        public SortedSet<String> getCapabilities() {
            return createCaps();
        }
    };
    final FeatureListProvider mock = mock(FeatureListProvider.class);
    doReturn(Sets.newHashSet("f1-11", "f2-22")).when(mock).listFeatures();
    storage.setFeaturesService(mock);
    storage.persistConfig(holder);
    assertEquals(20, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size());
    List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
    assertEquals(1, lastConf.size());
    ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
    assertXMLEqual("<config>1</config>", configSnapshotHolder.getConfigSnapshot());
    assertEquals(Sets.newHashSet("f1-11", "f2-22"), storage.getPersistedFeatures());
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 3 with PropertiesProviderTest

use of org.opendaylight.controller.config.persist.test.PropertiesProviderTest in project controller by opendaylight.

the class FileStorageAdapterTest method testNewFile.

@Test
public void testNewFile() throws Exception {
    PropertiesProviderTest pp = new PropertiesProviderTest();
    pp.addProperty("fileStorage", NON_EXISTENT_DIRECTORY + NON_EXISTENT_FILE);
    pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
    storage.instantiate(pp);
    final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {

        @Override
        public String getConfigSnapshot() {
            return createConfig();
        }

        @Override
        public SortedSet<String> getCapabilities() {
            return createCaps();
        }
    };
    storage.persistConfig(holder);
    storage.persistConfig(holder);
    assertEquals(storage.toString().replace("\\", "/"), "XmlFileStorageAdapter [storage=" + NON_EXISTENT_DIRECTORY + NON_EXISTENT_FILE + "]");
    delete(new File(NON_EXISTENT_DIRECTORY));
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest) File(java.io.File) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 4 with PropertiesProviderTest

use of org.opendaylight.controller.config.persist.test.PropertiesProviderTest in project controller by opendaylight.

the class FileStorageAdapterTest method testNoFeaturesStored.

@Test
public void testNoFeaturesStored() throws Exception {
    PropertiesProviderTest pp = new PropertiesProviderTest();
    pp.addProperty("fileStorage", file.getPath());
    pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
    storage.instantiate(pp);
    com.google.common.io.Files.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<persisted-snapshots>\n" + "   <snapshots>\n" + "      <snapshot>\n" + "         <required-capabilities>\n" + "            <capability>cap12</capability>\n" + "         </required-capabilities>\n" + "         <configuration>\n" + "            <config>1</config>\n" + "         </configuration>\n" + "      </snapshot>\n" + "   </snapshots>\n" + "</persisted-snapshots>", file, StandardCharsets.UTF_8);
    List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
    assertEquals(1, lastConf.size());
    ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
    assertXMLEqual("<config>1</config>", configSnapshotHolder.getConfigSnapshot());
    assertTrue(storage.getPersistedFeatures().isEmpty());
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Example 5 with PropertiesProviderTest

use of org.opendaylight.controller.config.persist.test.PropertiesProviderTest in project controller by opendaylight.

the class FileStorageAdapterTest method testFileAdapterOneBackup.

@Test
public void testFileAdapterOneBackup() throws Exception {
    PropertiesProviderTest pp = new PropertiesProviderTest();
    pp.addProperty("fileStorage", file.getPath());
    pp.addProperty("numberOfBackups", Integer.toString(Integer.MAX_VALUE));
    storage.instantiate(pp);
    final ConfigSnapshotHolder holder = new ConfigSnapshotHolder() {

        @Override
        public String getConfigSnapshot() {
            return createConfig();
        }

        @Override
        public SortedSet<String> getCapabilities() {
            return createCaps();
        }
    };
    storage.persistConfig(holder);
    storage.persistConfig(holder);
    assertEquals(29, com.google.common.io.Files.readLines(file, StandardCharsets.UTF_8).size());
    List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
    assertEquals(1, lastConf.size());
    ConfigSnapshotHolder configSnapshotHolder = lastConf.get(0);
    assertXMLEqual("<config>2</config>", configSnapshotHolder.getConfigSnapshot());
}
Also used : ConfigSnapshotHolder(org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest) Test(org.junit.Test) PropertiesProviderTest(org.opendaylight.controller.config.persist.test.PropertiesProviderTest)

Aggregations

PropertiesProviderTest (org.opendaylight.controller.config.persist.test.PropertiesProviderTest)6 Test (org.junit.Test)5 ConfigSnapshotHolder (org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder)5 File (java.io.File)1