From a66d29f4ba5f5d5636f3de84ab184dad844f027b Mon Sep 17 00:00:00 2001 From: Test Date: Wed, 29 Sep 2021 16:39:00 +0530 Subject: saltstack adaptor improve test coverage Signed-off-by: Ganesh Chandrasekaran Issue-ID: CCSDK-3476 Change-Id: Ic11d786fea1464a859667f77bc72af0c02c0d4ac --- .../sli/adaptors/saltstack/impl/SshConnection.java | 2 +- .../adaptors/saltstack/impl/TestSshConnection.java | 92 ++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 adaptors/saltstack-adaptor/saltstack-adaptor-provider/src/test/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/TestSshConnection.java (limited to 'adaptors/saltstack-adaptor') 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(); + } + } +} + -- cgit 1.2.3-korg