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.sli.adaptors.saltstack.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;
35 import java.util.Properties;
37 import static org.junit.Assert.assertEquals;
39 public class TestSshConnection {
41 private SshConnection sshConnection;
42 private Properties params;
46 public void setup() throws IllegalArgumentException {
47 String HostName = "localhost";
50 String Password = "test";
51 sshConnection = new SshConnection(HostName, Port, User, Password);
52 params = new Properties();
55 @Test(expected=NullPointerException.class)
56 public void reqConnect_exitStatusFailed() {
57 sshConnection.setExecTimeout(10);
58 sshConnection.connect();
62 public void reqexecCommandWithPty_exitStatusFailed() {
63 sshConnection.setExecTimeout(10);
66 params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT");
67 params.put("org.onap.appc.adaptor.saltstack.host", "test");
68 params.put("org.onap.appc.adaptor.saltstack.port", "10");
69 params.put("org.onap.appc.adaptor.saltstack.userName", "test");
70 params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test");
71 params.put("org.onap.appc.adaptor.saltstack.sshKey", "test");
72 OutputStream res = new FileOutputStream("test.out");
73 outcome = sshConnection.execCommandWithPty("ls",res);
74 assertEquals(1,outcome);
75 } catch (Exception e) {
80 @Test(expected=NullPointerException.class)
81 public void reqDisconnect_exitStatusFailed() {
82 params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT");
83 params.put("org.onap.appc.adaptor.saltstack.host", "test");
84 params.put("org.onap.appc.adaptor.saltstack.port", "10");
85 params.put("org.onap.appc.adaptor.saltstack.userName", "test");
86 params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test");
87 params.put("org.onap.appc.adaptor.saltstack.sshKey", "test");
88 sshConnection.setExecTimeout(10);
89 sshConnection.disconnect();
93 public void reqexecCommand_exitStatusFailed() {
94 sshConnection.setExecTimeout(10);
97 params.put("org.onap.appc.adaptor.saltstack.clientType", "SSH_CERT");
98 params.put("org.onap.appc.adaptor.saltstack.host", "test");
99 params.put("org.onap.appc.adaptor.saltstack.port", "10");
100 params.put("org.onap.appc.adaptor.saltstack.userName", "test");
101 params.put("org.onap.appc.adaptor.saltstack.userPasswd", "test");
102 params.put("org.onap.appc.adaptor.saltstack.sshKey", "test");
103 OutputStream res = new FileOutputStream("test.out");
104 OutputStream resErr = new FileOutputStream("test.out");
105 outcome = sshConnection.execCommand("ls",res, resErr);
106 assertEquals(1,outcome);
107 } catch (Exception e) {