increased test coverage 68/4268/2
authorMartin Bobak <mbobak@cisco.com>
Wed, 15 Jan 2014 13:46:41 +0000 (14:46 +0100)
committerMartin Bobak <mbobak@cisco.com>
Wed, 15 Jan 2014 14:38:19 +0000 (15:38 +0100)
Change-Id: I4f9f387a606a17724d2c835f6243cda14b9f4e0c
Signed-off-by: Martin Bobak <mbobak@cisco.com>
opendaylight/config/config-persister-directory-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/directory/xml/DirectoryStorageAdapterTest.java
opendaylight/config/config-persister-file-xml-adapter/pom.xml
opendaylight/config/config-persister-file-xml-adapter/src/test/java/org/opendaylight/controller/config/persist/storage/file/xml/FileStorageAdapterTest.java

index 0a36db9e2ed76fead08be6ae57fde038430624ae..825eb946c8ec8be817caf0c73470528531e15650 100644 (file)
@@ -14,15 +14,15 @@ import java.util.List;
 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.assertTrue;
 import static org.junit.Assert.fail;
 
 public class DirectoryStorageAdapterTest {
-
-    Persister tested;
+    XmlDirectoryPersister tested;
+    Logger logger = LoggerFactory.getLogger(DirectoryStorageAdapterTest.class.toString());
 
     @Test
     public void testEmptyDirectory() throws Exception {
@@ -59,12 +59,8 @@ public class DirectoryStorageAdapterTest {
     @Test
     public void testOneFile() throws Exception {
         File folder = getFolder("oneFile");
-
-        PropertiesProviderTest pp = new PropertiesProviderTest();
-        pp.addProperty("directoryStorage",folder.getPath());
-        XmlDirectoryStorageAdapter xmlDsa = new XmlDirectoryStorageAdapter();
-        tested = xmlDsa.instantiate(pp);
-
+        tested = new XmlDirectoryPersister(folder);
+        logger.info("Testing : "+tested.toString());
         List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
         assertEquals(1, results.size());
         ConfigSnapshotHolder result = results.get(0);
@@ -82,12 +78,8 @@ public class DirectoryStorageAdapterTest {
     @Test
     public void testTwoFiles() throws Exception {
         File folder = getFolder("twoFiles");
-
-        PropertiesProviderTest pp = new PropertiesProviderTest();
-        pp.addProperty("directoryStorage",folder.getPath());
-        XmlDirectoryStorageAdapter xmlDsa = new XmlDirectoryStorageAdapter();
-        tested = xmlDsa.instantiate(pp);
-
+        tested = new XmlDirectoryPersister((folder));
+        logger.info("Testing : "+tested.toString());
         List<ConfigSnapshotHolder> results = tested.loadLastConfigs();
         assertEquals(2, results.size());
 
index abbec382b7a7e2e95e16387f7775912a8e4df855..d08a93e1148b4c00c2f1e794a62aa5846ceb0669 100644 (file)
             <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>
 
     <build>
index d6bbeb31da2f3b3caa9a86acbadcd94452c070e1..0e4cce544f049dc361ccc0770d3161db46d5c482 100644 (file)
@@ -9,18 +9,17 @@
 package org.opendaylight.controller.config.persist.storage.file.xml;
 
 import com.google.common.base.Charsets;
-import junit.framework.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
-
 import java.io.File;
 import java.nio.file.Files;
 import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
-
+import junit.framework.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder;
+import org.opendaylight.controller.config.persist.test.PropertiesProviderTest;
 import static junit.framework.Assert.assertFalse;
 import static org.hamcrest.CoreMatchers.is;
 import static org.junit.Assert.assertEquals;
@@ -43,8 +42,11 @@ public class FileStorageAdapterTest {
     @Test
     public void testFileAdapter() throws Exception {
         XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
-        storage.setFileStorage(file);
-        storage.setNumberOfBackups(Integer.MAX_VALUE);
+        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() {
@@ -89,8 +91,12 @@ public class FileStorageAdapterTest {
     @Test
     public void testFileAdapterOneBackup() throws Exception {
         XmlFileStorageAdapter storage = new XmlFileStorageAdapter();
-        storage.setFileStorage(file);
-        storage.setNumberOfBackups(1);
+
+        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() {
@@ -106,7 +112,7 @@ public class FileStorageAdapterTest {
 
         storage.persistConfig(holder);
 
-        assertEquals(16, com.google.common.io.Files.readLines(file, Charsets.UTF_8).size());
+        assertEquals(27, com.google.common.io.Files.readLines(file, Charsets.UTF_8).size());
 
         List<ConfigSnapshotHolder> lastConf = storage.loadLastConfigs();
         assertEquals(1, lastConf.size());