summaryrefslogtreecommitdiffstats
path: root/adaptors/ssh-adaptor
diff options
context:
space:
mode:
authorGanesh <ganesh.c@samsung.com>2022-04-13 13:37:45 +0530
committerGanesh <ganesh.c@samsung.com>2022-04-18 10:04:46 +0530
commitd586124b71ded10aa677ad28f207edc6a3dc7653 (patch)
tree8de5294c953d03723cef689e5c4344c2e846594a /adaptors/ssh-adaptor
parentff6b20220ab657ef20ec40d84ee36c4be04e1f94 (diff)
sshAdaptor unit test cases added
Signed-off-by: Ganesh <ganesh.c@samsung.com> Change-Id: I980fcc8c33ea46e1813d5583b530e99800960411 Issue-ID: CCSDK-3476
Diffstat (limited to 'adaptors/ssh-adaptor')
-rw-r--r--adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/DbLibServiceMock.java77
-rw-r--r--adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/SshdDataAccessServiceTest.java91
2 files changed, 168 insertions, 0 deletions
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
index 000000000..08b2bac06
--- /dev/null
+++ b/adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/DbLibServiceMock.java
@@ -0,0 +1,77 @@
+/*-
+ * ============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.mockito.Mockito;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
+
+import javax.sql.rowset.CachedRowSet;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.ArrayList;
+
+public abstract class DbLibServiceMock implements DbLibService {
+
+ @Override
+ public CachedRowSet getData(String statement,ArrayList<String> arguments, String preferredDS) throws SQLException{
+ CachedRowSet rowset = Mockito.mock(CachedRowSet.class);
+ return rowset;
+ }
+
+ @Override
+ public boolean writeData(String statement, ArrayList<String> arguments, String preferredDS)
+ throws SQLException {
+ return true;
+ }
+
+ @Override
+ public boolean isActive() {
+ return true;
+ }
+
+ @Override
+ public Connection getConnection() throws SQLException {
+ return null;
+ }
+
+ @Override
+ public Connection getConnection(String username, String password) throws SQLException{
+ return null;
+ }
+
+ @Override
+ public java.io.PrintWriter getLogWriter() throws SQLException{
+ return null;
+ }
+
+ @Override
+ public void setLogWriter(java.io.PrintWriter out) throws SQLException{}
+
+ @Override
+ public void setLoginTimeout(int seconds) throws SQLException{}
+
+ @Override
+ public int getLoginTimeout() throws SQLException{
+ return 1;
+ }
+
+
+}
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
index 000000000..d8c22dbb8
--- /dev/null
+++ b/adaptors/ssh-adaptor/ssh-adaptor-bundle/src/test/java/org/onap/ccsdk/sli/adaptors/ssh/SshdDataAccessServiceTest.java
@@ -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"));
+ }
+}