2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2021 Samsung Electronics. All rights reserved.
6 * ================================================================================
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
22 * ============LICENSE_END=========================================================
25 package org.onap.ccsdk.adapter.impl;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult;
30 import org.onap.ccsdk.sli.adaptors.saltstack.impl.SshConnection;
33 import java.io.FileOutputStream;
34 import java.io.OutputStream;
36 import static org.junit.Assert.assertEquals;
38 public class TestSshConnection {
40 private SshConnection sshConnection;
44 public void setup() throws IllegalArgumentException {
45 String HostName = "localhost";
48 String Password = "test";
49 sshConnection = new SshConnection(HostName, Port, User, Password);
53 @Test(expected=NullPointerException.class)
54 public void reqConnect_exitStatusFailed() {
55 sshConnection.setExecTimeout(10);
56 sshConnection.connect();
60 public void reqexecCommandWithPty_exitStatusFailed() {
61 sshConnection.setExecTimeout(10);
64 OutputStream res = new FileOutputStream("test.out");
65 outcome = sshConnection.execCommandWithPty("ls",res);
66 assertEquals(1,outcome);
67 } catch (Exception e) {
72 @Test(expected=NullPointerException.class)
73 public void reqDisconnect_exitStatusFailed() {
74 sshConnection.setExecTimeout(10);
75 sshConnection.disconnect();
79 public void reqexecCommand_exitStatusFailed() {
80 sshConnection.setExecTimeout(10);
83 OutputStream res = new FileOutputStream("test.out");
84 OutputStream resErr = new FileOutputStream("test.out");
85 outcome = sshConnection.execCommand("ls",res, resErr);
86 assertEquals(1,outcome);
87 } catch (Exception e) {