summaryrefslogtreecommitdiffstats
path: root/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src
diff options
context:
space:
mode:
authorTest <ganesh.c@samsung.com>2021-09-29 16:39:00 +0530
committerTest <ganesh.c@samsung.com>2021-09-29 16:39:24 +0530
commita66d29f4ba5f5d5636f3de84ab184dad844f027b (patch)
tree44d817861ec6f7d1c5c2f26e1de5c5100253c627 /adaptors/saltstack-adaptor/saltstack-adaptor-provider/src
parentbd80b9fd16416c34c77290582fa014b88513eb3a (diff)
saltstack adaptor improve test coverage
Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com> Issue-ID: CCSDK-3476 Change-Id: Ic11d786fea1464a859667f77bc72af0c02c0d4ac
Diffstat (limited to 'adaptors/saltstack-adaptor/saltstack-adaptor-provider/src')
-rw-r--r--adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java2
-rw-r--r--adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java92
2 files changed, 93 insertions, 1 deletions
diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java
index 25d2d8402..0384de0ec 100644
--- a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java
+++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java
@@ -43,7 +43,7 @@ import com.att.eelf.configuration.EELFManager;
/**
* Implementation of SshConnection interface based on Apache MINA SSHD library.
*/
-class SshConnection {
+public class SshConnection {
private static final EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
diff --git a/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java
new file mode 100644
index 000000000..89b0ecf4b
--- /dev/null
+++ b/adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : CCSDK
+ * ================================================================================
+ * Copyright (C) 2021 Samsung Electronics. All rights reserved.
+ * ================================================================================
+ *
+ * =============================================================================
+ * 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.adapter.impl;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult;
+import org.onap.ccsdk.sli.adaptors.saltstack.impl.SshConnection;
+
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestSshConnection {
+
+private SshConnection sshConnection;
+
+
+ @Before
+ public void setup() throws IllegalArgumentException {
+ String HostName = "localhost";
+ int Port = 22;
+ String User = "test";
+ String Password = "test";
+ sshConnection = new SshConnection(HostName, Port, User, Password);
+ }
+
+
+ @Test(expected=NullPointerException.class)
+ public void reqConnect_exitStatusFailed() {
+ sshConnection.setExecTimeout(10);
+ sshConnection.connect();
+ }
+
+ @Test
+ public void reqexecCommandWithPty_exitStatusFailed() {
+ sshConnection.setExecTimeout(10);
+ int outcome = 999;
+ try {
+ OutputStream res = new FileOutputStream("test.out");
+ outcome = sshConnection.execCommandWithPty("ls",res);
+ assertEquals(1,outcome);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test(expected=NullPointerException.class)
+ public void reqDisconnect_exitStatusFailed() {
+ sshConnection.setExecTimeout(10);
+ sshConnection.disconnect();
+ }
+
+ @Test
+ public void reqexecCommand_exitStatusFailed() {
+ sshConnection.setExecTimeout(10);
+ int outcome=999;
+ try {
+ OutputStream res = new FileOutputStream("test.out");
+ OutputStream resErr = new FileOutputStream("test.out");
+ outcome = sshConnection.execCommand("ls",res, resErr);
+ assertEquals(1,outcome);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
+