sshAdaptor unit test cases added 41/128541/2
authorGanesh <ganesh.c@samsung.com>
Wed, 13 Apr 2022 08:07:45 +0000 (13:37 +0530)
committerGanesh <ganesh.c@samsung.com>
Mon, 18 Apr 2022 04:34:46 +0000 (10:04 +0530)
Signed-off-by: Ganesh <ganesh.c@samsung.com>
Change-Id: I980fcc8c33ea46e1813d5583b530e99800960411
Issue-ID: CCSDK-3476

adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/DbLibServiceMock.java [new file with mode: 0644]
adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/SshdDataAccessServiceTest.java [new file with mode: 0644]

diff --git a/adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/DbLibServiceMock.java b/adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/DbLibServiceMock.java
new file mode 100644 (file)
index 0000000..08b2bac
--- /dev/null
@@ -0,0 +1,77 @@
+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP : CCSDK\r
+ * ================================================================================\r
+ * Copyright (C) 2022 Samsung Electronics\r
+ * =============================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
+package org.onap.ccsdk.sli.adaptors.ssh;\r
+\r
+import org.mockito.Mockito;\r
+import org.onap.ccsdk.sli.core.dblib.DbLibService;\r
+\r
+import javax.sql.rowset.CachedRowSet;\r
+import java.sql.Connection;\r
+import java.sql.SQLException;\r
+import java.util.ArrayList;\r
+\r
+public abstract class DbLibServiceMock implements DbLibService {\r
+\r
+    @Override\r
+    public CachedRowSet getData(String statement,ArrayList<String> arguments, String preferredDS) throws SQLException{\r
+        CachedRowSet rowset = Mockito.mock(CachedRowSet.class);\r
+        return rowset;\r
+    }\r
+\r
+    @Override\r
+    public boolean writeData(String statement, ArrayList<String> arguments, String preferredDS)\r
+            throws SQLException {\r
+        return true;\r
+    }\r
+\r
+    @Override\r
+    public boolean isActive() {\r
+        return true;\r
+    }\r
+\r
+    @Override\r
+    public Connection getConnection() throws SQLException {\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public Connection getConnection(String username, String password) throws SQLException{\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public java.io.PrintWriter getLogWriter() throws SQLException{\r
+        return null;\r
+    }\r
+\r
+    @Override\r
+    public void setLogWriter(java.io.PrintWriter out) throws SQLException{}\r
+\r
+    @Override\r
+    public void setLoginTimeout(int seconds) throws SQLException{}\r
+\r
+    @Override\r
+    public int getLoginTimeout() throws SQLException{\r
+        return 1;\r
+    }\r
+\r
+\r
+}\r
diff --git a/adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/SshdDataAccessServiceTest.java b/adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/SshdDataAccessServiceTest.java
new file mode 100644 (file)
index 0000000..d8c22db
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK
+ * ================================================================================
+ * Copyright (C) 2022 Samsung Electronics
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.adaptors.ssh;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.ssh.sshd.SshdDataAccessService;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
+
+import javax.sql.rowset.CachedRowSet;
+import javax.sql.rowset.RowSetProvider;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class SshdDataAccessServiceTest {
+
+    private SshdDataAccessService sshdDataAccessService;
+    private DbLibService db;
+    CachedRowSet rowset;
+    @Before
+    public void setUp() throws SQLException {
+        sshdDataAccessService = new SshdDataAccessService();
+        DbLibServiceMock dbLibServiceMock = new DbLibServiceMock() {
+            @Override
+            public <T> T unwrap(Class<T> iface) throws SQLException {
+                return null;
+            }
+
+            @Override
+            public boolean isWrapperFor(Class<?> iface) throws SQLException {
+                return false;
+            }
+
+            @Override
+            public Logger getParentLogger() throws SQLFeatureNotSupportedException {
+                return null;
+            }
+        };
+        sshdDataAccessService.setDbLibService(db);
+    }
+
+    @Test
+    public void testSetSchema() {
+        sshdDataAccessService.setSchema("test");
+        assertEquals("test", sshdDataAccessService.getSchema());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testSetDbLibService() {
+        sshdDataAccessService.setDbLibService(db);
+        assertEquals(false, sshdDataAccessService.getDbLibService().isActive());
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testRetrieveConnectionDetails() {
+        SshConnectionDetails connectionDetails = new SshConnectionDetails();
+        sshdDataAccessService.setDbLibService(db);
+        assertTrue(sshdDataAccessService.retrieveConnectionDetails("test", connectionDetails));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testRetrieveConfigFileName() {
+        assertEquals(null, sshdDataAccessService.retrieveConfigFileName("test"));
+    }
+}