+ @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, Charsets.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());
+ }
+
+ @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, Charsets.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());
+ }
+