saltstack adaptor improve test coverage 60/124560/1
authorTest <ganesh.c@samsung.com>
Wed, 29 Sep 2021 11:09:00 +0000 (16:39 +0530)
committerTest <ganesh.c@samsung.com>
Wed, 29 Sep 2021 11:09:24 +0000 (16:39 +0530)
Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
Issue-ID: CCSDK-3476
Change-Id: Ic11d786fea1464a859667f77bc72af0c02c0d4ac

adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java
adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java [new file with mode: 0644]

index 25d2d84..0384de0 100644 (file)
@@ -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 (file)
index 0000000..89b0ecf
--- /dev/null
@@ -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();
+        }
+    }
+}
+