Increase coverage for sshdDataAccessDervice 55/57955/2
authorGanesh Chandrasekaran <ganesh.c@samsung.com>
Mon, 30 Jul 2018 00:39:17 +0000 (09:39 +0900)
committerGanesh Chandrasekaran <ganesh.c@samsung.com>
Mon, 30 Jul 2018 00:53:36 +0000 (09:53 +0900)
Issue-ID: APPC-1113

Change-Id: If7f466c6e6c205c220ae020c3e4ce24e1088f7f3
Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessService.java
appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessServiceTest.java [new file with mode: 0644]

index 7c762c1..b0abcb4 100644 (file)
@@ -44,11 +44,19 @@ public class SshdDataAccessService implements SshDataAccessService {
         this.schema = schema;
     }
 
+    public String getSchema() {
+        return this.schema;
+    }
+
     @Override
     public void setDbLibService(DbLibService dbLibService) {
         this.dbLibService = dbLibService;
     }
 
+    public DbLibService getDbLibService() {
+        return this.dbLibService;
+    }
+
     @Override
     public boolean retrieveConnectionDetails(String vnfType, SshConnectionDetails connectionDetails) throws SshDataAccessException {
 
diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessServiceTest.java b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessServiceTest.java
new file mode 100644 (file)
index 0000000..0739e67
--- /dev/null
@@ -0,0 +1,111 @@
+package org.onap.appc.adapter.ssh.sshd;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.appc.adapter.ssh.SshConnectionDetails;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
+
+import javax.sql.rowset.CachedRowSet;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.ArrayList;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
+
+public class SshdDataAccessServiceTest {
+
+    private SshdDataAccessService sshdDataAccessService;
+    private DbLibService db;
+    @Before
+    public void setUp() {
+        sshdDataAccessService = new SshdDataAccessService();
+        db = new DbLibService() {
+            @Override
+            public CachedRowSet getData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
+                return null;
+            }
+
+            @Override
+            public boolean writeData(String s, ArrayList<String> arrayList, String s1) throws SQLException {
+                return false;
+            }
+
+            @Override
+            public boolean isActive() {
+                return false;
+            }
+
+            @Override
+            public Connection getConnection() throws SQLException {
+                return null;
+            }
+
+            @Override
+            public Connection getConnection(String username, String password) throws SQLException {
+                return null;
+            }
+
+            @Override
+            public <T> T unwrap(Class<T> iface) throws SQLException {
+                return null;
+            }
+
+            @Override
+            public boolean isWrapperFor(Class<?> iface) throws SQLException {
+                return false;
+            }
+
+            @Override
+            public PrintWriter getLogWriter() throws SQLException {
+                return null;
+            }
+
+            @Override
+            public void setLogWriter(PrintWriter out) throws SQLException {
+
+            }
+
+            @Override
+            public void setLoginTimeout(int seconds) throws SQLException {
+
+            }
+
+            @Override
+            public int getLoginTimeout() throws SQLException {
+                return 0;
+            }
+
+            @Override
+            public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+                return null;
+            }
+        };
+    }
+
+    @Test
+    public void testSetSchema() {
+        sshdDataAccessService.setSchema("test");
+        assertEquals("test", sshdDataAccessService.getSchema());
+    }
+
+    @Test
+    public void testSetDbLibService() {
+        sshdDataAccessService.setDbLibService(db);
+        assertEquals(false, sshdDataAccessService.getDbLibService().isActive());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testRetrieveConnectionDetails() {
+        SshConnectionDetails connectionDetails = new SshConnectionDetails();
+        sshdDataAccessService.retrieveConnectionDetails("test", connectionDetails);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testRetrieveConfigFileName() {
+        SshConnectionDetails connectionDetails = new SshConnectionDetails();
+        sshdDataAccessService.retrieveConfigFileName("test");
+    }
+}