aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-12 08:38:12 +0000
committerJoss Armstrong <joss.armstrong@ericsson.com>2019-02-12 08:42:57 +0000
commit7149e05b6a0d1d98f96ccdc3acea35d2b2b4c199 (patch)
treeb7bcfb14965cd3fa2ce0dba669f91a031cfaf297
parent422344933185539064ba5fd0b267e88bc442c23d (diff)
Test coverage in SshdDataAccessService
Increase coverage from 45% to 93% Issue-ID: APPC-1416 Change-Id: Icd9560f279b6dcd3986fcf28b16796a68b2ccb4f Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
-rw-r--r--appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessService.java12
-rw-r--r--appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/test/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessServiceTest.java114
2 files changed, 43 insertions, 83 deletions
diff --git a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessService.java b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessService.java
index b0abcb4f7..63acab6fb 100644
--- a/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessService.java
+++ b/appc-adapters/appc-ssh-adapter/appc-ssh-adapter-sshd/src/main/java/org/onap/appc/adapter/ssh/sshd/SshdDataAccessService.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,17 +25,15 @@
package org.onap.appc.adapter.ssh.sshd;
+import java.sql.SQLException;
+import java.util.ArrayList;
import javax.sql.rowset.CachedRowSet;
-
import org.onap.appc.adapter.ssh.Constants;
import org.onap.appc.adapter.ssh.SshConnectionDetails;
import org.onap.appc.adapter.ssh.SshDataAccessException;
import org.onap.appc.adapter.ssh.SshDataAccessService;
import org.onap.ccsdk.sli.core.dblib.DbLibService;
-import java.sql.SQLException;
-import java.util.ArrayList;
-
public class SshdDataAccessService implements SshDataAccessService {
private String schema = Constants.NETCONF_SCHEMA;
@@ -62,8 +62,8 @@ public class SshdDataAccessService implements SshDataAccessService {
boolean recordFound = false;
- String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," + Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " +
- "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
+ String queryString = "select " + Constants.USER_NAME_TABLE_FIELD_NAME + "," + Constants.PASSWORD_TABLE_FIELD_NAME + "," +
+ Constants.PORT_NUMBER_TABLE_FIELD_NAME + " " + "from " + Constants.DEVICE_AUTHENTICATION_TABLE_NAME + " " +
"where " + Constants.VNF_TYPE_TABLE_FIELD_NAME + " = ?";
ArrayList<String> argList = new ArrayList<>();
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
index 0739e679b..0d9fb3e82 100644
--- 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
@@ -1,88 +1,48 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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.appc.adapter.ssh.sshd;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.sql.SQLException;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mockito;
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;
+import com.sun.rowset.CachedRowSetImpl;
public class SshdDataAccessServiceTest {
private SshdDataAccessService sshdDataAccessService;
private DbLibService db;
@Before
- public void setUp() {
+ public void setUp() throws SQLException {
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;
- }
- };
+ db = Mockito.mock(DbLibService.class);
+ CachedRowSetImpl rowset = Mockito.mock(CachedRowSetImpl.class);
+ Mockito.when(rowset.first()).thenReturn(true);
+ Mockito.when(db.getData(Mockito.anyString(), Mockito.any(), Mockito.anyString())).thenReturn(rowset);
+ sshdDataAccessService.setDbLibService(db);
}
@Test
@@ -97,15 +57,15 @@ public class SshdDataAccessServiceTest {
assertEquals(false, sshdDataAccessService.getDbLibService().isActive());
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testRetrieveConnectionDetails() {
SshConnectionDetails connectionDetails = new SshConnectionDetails();
- sshdDataAccessService.retrieveConnectionDetails("test", connectionDetails);
+ sshdDataAccessService.setDbLibService(db);
+ assertTrue(sshdDataAccessService.retrieveConnectionDetails("test", connectionDetails));
}
- @Test(expected = NullPointerException.class)
+ @Test
public void testRetrieveConfigFileName() {
- SshConnectionDetails connectionDetails = new SshConnectionDetails();
- sshdDataAccessService.retrieveConfigFileName("test");
+ assertEquals(null, sshdDataAccessService.retrieveConfigFileName("test"));
}
}