89b0ecf4b0c5d68180b7dbee53a36a1225a360af
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2021 Samsung Electronics. All rights reserved.
6  * ================================================================================
7  *
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  *
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.ccsdk.adapter.impl;
26
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;
31
32
33 import java.io.FileOutputStream;
34 import java.io.OutputStream;
35
36 import static org.junit.Assert.assertEquals;
37
38 public class TestSshConnection {
39
40 private SshConnection sshConnection;
41
42
43     @Before
44     public void setup() throws IllegalArgumentException {
45         String HostName = "localhost";
46         int Port = 22;
47         String User = "test";
48         String Password = "test";
49         sshConnection = new SshConnection(HostName, Port, User, Password);
50     }
51
52
53     @Test(expected=NullPointerException.class)
54     public void reqConnect_exitStatusFailed() {
55             sshConnection.setExecTimeout(10);
56             sshConnection.connect();
57     }
58
59     @Test
60     public void reqexecCommandWithPty_exitStatusFailed() {
61         sshConnection.setExecTimeout(10);
62         int outcome = 999;
63         try {
64             OutputStream res = new FileOutputStream("test.out");
65             outcome = sshConnection.execCommandWithPty("ls",res);
66             assertEquals(1,outcome);
67         } catch (Exception e) {
68             e.printStackTrace();
69         }
70     }
71
72     @Test(expected=NullPointerException.class)
73     public void reqDisconnect_exitStatusFailed() {
74         sshConnection.setExecTimeout(10);
75         sshConnection.disconnect();
76     }
77
78     @Test
79     public void reqexecCommand_exitStatusFailed() {
80         sshConnection.setExecTimeout(10);
81         int outcome=999;
82         try {
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) {
88             e.printStackTrace();
89         }
90     }
91 }
92