public class DirectoryStorageAdapterTest {
Persister tested;
+ private Persister instantiatePersisterFromAdapter(File file){
+ PropertiesProviderTest pp = new PropertiesProviderTest();
+ pp.addProperty("directoryStorage",file.getPath());
+ DirectoryStorageAdapter dsa = new DirectoryStorageAdapter();
+ return dsa.instantiate(pp);
+ }
@Test
public void testEmptyDirectory() throws Exception {
File folder = new File("target/emptyFolder");
folder.mkdir();
- PropertiesProviderTest pp = new PropertiesProviderTest();
- pp.addProperty("directoryStorage",folder.getPath());
- DirectoryStorageAdapter dsa = new DirectoryStorageAdapter();
- tested = dsa.instantiate(pp);
+ tested = instantiatePersisterFromAdapter(folder);
assertEquals(Collections.<ConfigSnapshotHolder>emptyList(), tested.loadLastConfigs());
try {
@Test
public void testOneFile() throws Exception {
File folder = getFolder("oneFile");
- PropertiesProviderTest pp = new PropertiesProviderTest();
- pp.addProperty("directoryStorage",folder.getPath());
- DirectoryStorageAdapter dsa = new DirectoryStorageAdapter();
- tested = dsa.instantiate(pp);
+
+ tested = instantiatePersisterFromAdapter(folder);
List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
assertEquals(1, results.size());
@Test
public void testTwoFiles() throws Exception {
File folder = getFolder("twoFiles");
- PropertiesProviderTest pp = new PropertiesProviderTest();
- pp.addProperty("directoryStorage",folder.getPath());
- DirectoryStorageAdapter dsa = new DirectoryStorageAdapter();
- tested = dsa.instantiate(pp);
+ tested = instantiatePersisterFromAdapter(folder);
List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
assertEquals(2, results.size());
<artifactId>mockito-configuration</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>config-persister-api</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
</dependencies>
*/
package org.opendaylight.controller.config.persist.storage.directory.autodetect;
+import java.io.File;
+import java.util.List;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.matchers.JUnitMatchers;
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
-
-import java.io.File;
-import java.util.List;
+import org.opendaylight.controller.config.persist.test.PropertiesProviderTest;
public class AutodetectDirectoryPersisterTest {
@Test
public void testCombined() throws Exception {
File resourcePath = FileTypeTest.getResourceAsFile("/combined/1controller.txt.config");
+ File parentFile = resourcePath.getParentFile();
+
+ AutodetectDirectoryStorageAdapter adapter = new AutodetectDirectoryStorageAdapter();
- AutodetectDirectoryPersister persister = new AutodetectDirectoryPersister(resourcePath.getParentFile());
+ PropertiesProviderTest pp = new PropertiesProviderTest();
+ pp.addProperty("directoryStorage",parentFile.getPath());
+ AutodetectDirectoryPersister persister = (AutodetectDirectoryPersister) adapter.instantiate(pp);
List<ConfigSnapshotHolder> configs = persister.loadLastConfigs();
Assert.assertEquals(2, configs.size());
String snapFromXml = configs.get(1).getConfigSnapshot();
org.junit.Assert.assertThat(snapFromXml, JUnitMatchers.containsString("<config>xml</config>"));
- Assert.assertEquals(configs.get(0).getCapabilities(), configs.get(1).getCapabilities());
- }
+ Assert.assertEquals(configs.get(0).getCapabilities(), configs.get(1).getCapabilities()); }
}
import java.util.SortedSet;
import org.junit.Test;
import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+import org.opendaylight.controller.config.persist.api.Persister;
+import org.opendaylight.controller.config.persist.test.PropertiesProviderTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
public class DirectoryStorageAdapterTest {
- XmlDirectoryPersister tested;
+ Persister tested;
Logger logger = LoggerFactory.getLogger(DirectoryStorageAdapterTest.class.toString());
+ private Persister instantiatePersisterFromAdapter(File file){
+ PropertiesProviderTest pp = new PropertiesProviderTest();
+ pp.addProperty("directoryStorage",file.getPath());
+ XmlDirectoryStorageAdapter dsa = new XmlDirectoryStorageAdapter();
+ return dsa.instantiate(pp);
+ }
+
@Test
public void testEmptyDirectory() throws Exception {
File folder = new File("target/emptyFolder");
folder.mkdir();
- tested = new XmlDirectoryPersister((folder));
+
+ tested = instantiatePersisterFromAdapter(folder);
assertEquals(Collections.<ConfigSnapshotHolder>emptyList(), tested.loadLastConfigs());
try {
@Test
public void testOneFile() throws Exception {
File folder = getFolder("oneFile");
- tested = new XmlDirectoryPersister(folder);
+ tested = instantiatePersisterFromAdapter(folder);
+
logger.info("Testing : "+tested.toString());
List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
assertEquals(1, results.size());
@Test
public void testTwoFiles() throws Exception {
File folder = getFolder("twoFiles");
- tested = new XmlDirectoryPersister((folder));
+ tested = instantiatePersisterFromAdapter(folder);
logger.info("Testing : "+tested.toString());
List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
assertEquals(2, results.size());