dependancy and tests cases added
[ccsdk/sli/plugins.git] / sshapi-call-node / provider / src / test / java / jtest / org / onap / ccsdk / sli / plugins / sshapicall / TestSshApiCallNode.java
1 package jtest.org.onap.ccsdk.sli.plugins.sshapicall;
2
3 import org.junit.After;
4 import org.junit.Before;
5 import org.junit.Test;
6 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
7 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
8 import org.onap.ccsdk.sli.plugins.sshapicall.SshApiCallNode;
9 import org.onap.ccsdk.sli.plugins.sshapicall.model.XmlParser;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
12
13 import java.io.BufferedReader;
14 import java.io.InputStreamReader;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.Map;
18 import java.util.Set;
19
20 import static org.junit.Assert.assertEquals;
21
22 public class TestSshApiCallNode {
23
24     private static final Logger log = LoggerFactory.getLogger(TestSshApiCallNode.class);
25
26     private SshApiCallNode adapter;
27     private String TestId;
28     private boolean testMode = true;
29     private Map<String, String> params;
30     private SvcLogicContext svcContext;
31
32
33     @Before
34     public void setup() throws IllegalArgumentException {
35         testMode = true;
36         svcContext = new SvcLogicContext();
37         adapter = new SshApiCallNode();
38
39         params = new HashMap<>();
40         params.put("AgentUrl", "https://192.168.1.1");
41         params.put("User", "test");
42         params.put("Password", "test");
43     }
44
45     @After
46     public void tearDown() {
47         testMode = false;
48         adapter = null;
49         params = null;
50         svcContext = null;
51     }
52
53     @Test(expected = SvcLogicException.class)
54     public void testExecCommand_noUrlFailed() throws SvcLogicException,
55             IllegalStateException, IllegalArgumentException {
56
57         params.put("HostName", "test");
58         params.put("Port", "10");
59         params.put("User", "test");
60         params.put("Password", "test");
61         params.put("Test", "fail");
62         adapter.execCommand(params, svcContext);
63     }
64
65     @Test(expected = SvcLogicException.class)
66     public void testExecCommandPty_noUrlFailed() throws SvcLogicException,
67             IllegalStateException, IllegalArgumentException {
68
69         params.put("HostName", "test");
70         params.put("Port", "10");
71         params.put("User", "test");
72         params.put("Password", "test");
73         params.put("Test", "fail");
74         adapter.execCommandWithPty(params, svcContext);
75     }
76
77     @Test(expected = SvcLogicException.class)
78     public void testExecCommandResponse_noUrlFailed() throws SvcLogicException,
79             IllegalStateException, IllegalArgumentException {
80
81         params.put("HostName", "test");
82         params.put("Port", "10");
83         params.put("User", "test");
84         params.put("Password", "test");
85         params.put("Test", "fail");
86         adapter.execWithStatusCheck(params, svcContext);
87     }
88
89     @Test(expected = SvcLogicException.class)
90     public void testExecCommand_noPortFailed() throws SvcLogicException,
91             IllegalStateException, IllegalArgumentException {
92
93         params.put("Url", "test");
94         params.put("User", "test");
95         params.put("Password", "test");
96         params.put("Test", "fail");
97         adapter.execCommand(params, svcContext);
98     }
99
100     @Test(expected = SvcLogicException.class)
101     public void testExecCommandPty_noPortFailed() throws SvcLogicException,
102             IllegalStateException, IllegalArgumentException {
103
104         params.put("Url", "test");
105         params.put("User", "test");
106         params.put("Password", "test");
107         params.put("Test", "fail");
108         adapter.execCommandWithPty(params, svcContext);
109     }
110
111     @Test(expected = SvcLogicException.class)
112     public void testExecCommandResponse_noPortFailed() throws SvcLogicException,
113             IllegalStateException, IllegalArgumentException {
114
115         params.put("Url", "test");
116         params.put("User", "test");
117         params.put("Password", "test");
118         params.put("Test", "fail");
119         adapter.execWithStatusCheck(params, svcContext);
120     }
121
122     @Test(expected = SvcLogicException.class)
123     public void testExecCommand_noCmdFailed() throws SvcLogicException,
124             IllegalStateException, IllegalArgumentException {
125
126         params.put("Url", "test");
127         params.put("Port", "10");
128         adapter.execCommand(params, svcContext);
129     }
130
131     @Test(expected = SvcLogicException.class)
132     public void testExecCommandPty_noCmdFailed() throws SvcLogicException,
133             IllegalStateException, IllegalArgumentException {
134
135         params.put("Url", "test");
136         params.put("Port", "10");
137         adapter.execCommandWithPty(params, svcContext);
138     }
139
140     @Test(expected = SvcLogicException.class)
141     public void testExecCommandResponse_noCmdFailed() throws SvcLogicException,
142             IllegalStateException, IllegalArgumentException {
143
144         params.put("Url", "test");
145         params.put("Port", "10");
146         adapter.execWithStatusCheck(params, svcContext);
147     }
148
149     @Test(expected = SvcLogicException.class)
150     public void testExecCommandResponse_noSSHBasicFailed() throws SvcLogicException,
151             IllegalStateException, IllegalArgumentException {
152
153         params.put("Url", "test");
154         params.put("Port", "10");
155         params.put("User", "test");
156         params.put("Password", "test");
157         params.put("AuthType", "basic");
158         params.put("Cmd", "test");
159         adapter.execWithStatusCheck(params, svcContext);
160     }
161
162     @Test(expected = SvcLogicException.class)
163     public void testExecCommandResponse_noSSHKeyFailed() throws SvcLogicException,
164             IllegalStateException, IllegalArgumentException {
165
166         params.put("Url", "test");
167         params.put("Port", "10");
168         params.put("User", "test");
169         params.put("Password", "test");
170         params.put("AuthType", "key");
171         params.put("Cmd", "test");
172         adapter.execWithStatusCheck(params, svcContext);
173     }
174
175     @Test(expected = SvcLogicException.class)
176     public void testExecCommandResponse_noSSHNoneFailed() throws SvcLogicException,
177             IllegalStateException, IllegalArgumentException {
178
179         params.put("Url", "test");
180         params.put("Port", "10");
181         params.put("User", "test");
182         params.put("Password", "test");
183         params.put("AuthType", "none");
184         params.put("Cmd", "test");
185         params.put("ResponseType", "xml");
186         adapter.execWithStatusCheck(params, svcContext);
187     }
188
189     @Test(expected = SvcLogicException.class)
190     public void testExecCommandResponse_noSSHFailed() throws SvcLogicException,
191             IllegalStateException, IllegalArgumentException {
192
193         params.put("Url", "test");
194         params.put("Port", "10");
195         params.put("User", "test");
196         params.put("Password", "test");
197         params.put("Cmd", "test");
198         params.put("ResponseType", "json");
199         adapter.execWithStatusCheck(params, svcContext);
200     }
201
202     @Test(expected = IllegalArgumentException.class)
203     public void testExecCommandResponse_noSSHInvalidParam() throws SvcLogicException,
204             IllegalStateException, IllegalArgumentException {
205
206         params.put("Url", "test");
207         params.put("Port", "10");
208         params.put("User", "test");
209         params.put("Password", "test");
210         params.put("Cmd", "test");
211         params.put("ResponseType", "txt");
212         adapter.execWithStatusCheck(params, svcContext);
213     }
214
215     @Test(expected = IllegalArgumentException.class)
216     public void testExecCommandResponse_noSSHInvalidAuthParam() throws SvcLogicException,
217             IllegalStateException, IllegalArgumentException {
218
219         params.put("Url", "test");
220         params.put("Port", "10");
221         params.put("User", "test");
222         params.put("Password", "test");
223         params.put("Cmd", "test");
224         params.put("AuthType", "spring");
225         params.put("ResponseType", "json");
226         adapter.execWithStatusCheck(params, svcContext);
227     }
228 }