1 package jtest.org.onap.ccsdk.sli.plugins.sshapicall;
3 import org.junit.After;
4 import org.junit.Before;
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;
13 import java.io.BufferedReader;
14 import java.io.InputStreamReader;
15 import java.util.HashMap;
16 import java.util.HashSet;
20 import static org.junit.Assert.assertEquals;
22 public class TestSshApiCallNode {
24 private static final Logger log = LoggerFactory.getLogger(TestSshApiCallNode.class);
26 private SshApiCallNode adapter;
27 private String TestId;
28 private boolean testMode = true;
29 private Map<String, String> params;
30 private SvcLogicContext svcContext;
34 public void setup() throws IllegalArgumentException {
36 svcContext = new SvcLogicContext();
37 adapter = new SshApiCallNode();
39 params = new HashMap<>();
40 params.put("AgentUrl", "https://192.168.1.1");
41 params.put("User", "test");
42 params.put("Password", "test");
46 public void tearDown() {
53 @Test(expected = SvcLogicException.class)
54 public void testExecCommand_noUrlFailed() throws SvcLogicException,
55 IllegalStateException, IllegalArgumentException {
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);
65 @Test(expected = SvcLogicException.class)
66 public void testExecCommandPty_noUrlFailed() throws SvcLogicException,
67 IllegalStateException, IllegalArgumentException {
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);
77 @Test(expected = SvcLogicException.class)
78 public void testExecCommandResponse_noUrlFailed() throws SvcLogicException,
79 IllegalStateException, IllegalArgumentException {
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);
89 @Test(expected = SvcLogicException.class)
90 public void testExecCommand_noPortFailed() throws SvcLogicException,
91 IllegalStateException, IllegalArgumentException {
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);
100 @Test(expected = SvcLogicException.class)
101 public void testExecCommandPty_noPortFailed() throws SvcLogicException,
102 IllegalStateException, IllegalArgumentException {
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);
111 @Test(expected = SvcLogicException.class)
112 public void testExecCommandResponse_noPortFailed() throws SvcLogicException,
113 IllegalStateException, IllegalArgumentException {
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);
122 @Test(expected = SvcLogicException.class)
123 public void testExecCommand_noCmdFailed() throws SvcLogicException,
124 IllegalStateException, IllegalArgumentException {
126 params.put("Url", "test");
127 params.put("Port", "10");
128 adapter.execCommand(params, svcContext);
131 @Test(expected = SvcLogicException.class)
132 public void testExecCommandPty_noCmdFailed() throws SvcLogicException,
133 IllegalStateException, IllegalArgumentException {
135 params.put("Url", "test");
136 params.put("Port", "10");
137 adapter.execCommandWithPty(params, svcContext);
140 @Test(expected = SvcLogicException.class)
141 public void testExecCommandResponse_noCmdFailed() throws SvcLogicException,
142 IllegalStateException, IllegalArgumentException {
144 params.put("Url", "test");
145 params.put("Port", "10");
146 adapter.execWithStatusCheck(params, svcContext);
149 @Test(expected = SvcLogicException.class)
150 public void testExecCommandResponse_noSSHBasicFailed() throws SvcLogicException,
151 IllegalStateException, IllegalArgumentException {
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);
162 @Test(expected = SvcLogicException.class)
163 public void testExecCommandResponse_noSSHKeyFailed() throws SvcLogicException,
164 IllegalStateException, IllegalArgumentException {
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);
175 @Test(expected = SvcLogicException.class)
176 public void testExecCommandResponse_noSSHNoneFailed() throws SvcLogicException,
177 IllegalStateException, IllegalArgumentException {
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);
189 @Test(expected = SvcLogicException.class)
190 public void testExecCommandResponse_noSSHFailed() throws SvcLogicException,
191 IllegalStateException, IllegalArgumentException {
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);
202 @Test(expected = IllegalArgumentException.class)
203 public void testExecCommandResponse_noSSHInvalidParam() throws SvcLogicException,
204 IllegalStateException, IllegalArgumentException {
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);
215 @Test(expected = IllegalArgumentException.class)
216 public void testExecCommandResponse_noSSHInvalidAuthParam() throws SvcLogicException,
217 IllegalStateException, IllegalArgumentException {
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);