50530ecd853edee00add19811a3125aa513858ac
[ccsdk/sli/adaptors.git] / saltstack-adapter / saltstack-adapter-provider / src / test / java / org / onap / ccsdk / adapter / impl / TestSaltstackAdapterImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2018 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.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
33
34 import java.util.HashMap;
35 import java.util.Map;
36
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.fail;
39
40
41 public class TestSaltstackAdapterImpl {
42
43     private SaltstackAdapterImpl adapter;
44     private String TestId;
45     private boolean testMode = true;
46     private Map<String, String> params;
47     private SvcLogicContext svcContext;
48
49
50     @Before
51     public void setup() throws IllegalArgumentException {
52         testMode = true;
53         svcContext = new SvcLogicContext();
54         adapter = new SaltstackAdapterImpl(testMode);
55
56         params = new HashMap<>();
57         params.put("AgentUrl", "https://192.168.1.1");
58         params.put("User", "test");
59         params.put("Password", "test");
60     }
61
62     @After
63     public void tearDown() {
64         testMode = false;
65         adapter = null;
66         params = null;
67         svcContext = null;
68     }
69
70     @Test(expected = SvcLogicException.class)
71     public void reqExecCommand_shouldSetFailed() throws SvcLogicException,
72             IllegalStateException, IllegalArgumentException {
73
74         params.put("HostName", "test");
75         params.put("Port", "10");
76         params.put("User", "test");
77         params.put("Password", "test");
78         params.put("Test", "fail");
79         adapter.reqExecCommand(params, svcContext);
80         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
81         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
82         assertEquals("101", status);
83     }
84
85     @Test(expected = SvcLogicException.class)
86     public void reqExecCommand_shouldSetUserFailed() throws SvcLogicException,
87             IllegalStateException, IllegalArgumentException {
88
89         params.put("HostName", "test");
90         params.put("Port", "10");
91         params.put("Password", "test");
92         params.put("Test", "fail");
93         adapter.reqExecCommand(params, svcContext);
94         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
95         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
96         assertEquals("101", status);
97     }
98
99     @Test(expected = SvcLogicException.class)
100     public void reqExecCommand_shouldSetHostFailed() throws SvcLogicException,
101             IllegalStateException, IllegalArgumentException {
102
103         params.put("Port", "10");
104         params.put("User", "test");
105         params.put("Password", "test");
106         params.put("Test", "fail");
107         adapter.reqExecCommand(params, svcContext);
108         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
109         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
110         assertEquals("101", status);
111     }
112
113     @Test(expected = SvcLogicException.class)
114     public void reqExecCommand_shouldSetPortFailed() throws SvcLogicException,
115             IllegalStateException, IllegalArgumentException {
116
117         params.put("HostName", "test");
118         params.put("User", "test");
119         params.put("Password", "test");
120         params.put("Test", "fail");
121         adapter.reqExecCommand(params, svcContext);
122         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
123         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
124         assertEquals("101", status);
125     }
126
127     @Test(expected = SvcLogicException.class)
128     public void reqExecCommand_shouldSetPasswordFailed() throws SvcLogicException,
129             IllegalStateException, IllegalArgumentException {
130
131         params.put("HostName", "test");
132         params.put("Port", "10");
133         params.put("User", "test");
134         params.put("Test", "fail");
135         adapter.reqExecCommand(params, svcContext);
136         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
137         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
138         assertEquals("101", status);
139     }
140
141     @Test(expected = SvcLogicException.class)
142     public void reqExecCommand_shouldSetMandatoryFailed() throws SvcLogicException,
143             IllegalStateException, IllegalArgumentException {
144
145         params.put("Test", "fail");
146         adapter.reqExecCommand(params, svcContext);
147         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
148         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
149         assertEquals("101", status);
150     }
151
152     @Test(expected = SvcLogicException.class)
153     public void reqExecCommand_NoResponseFile() throws SvcLogicException,
154             IllegalStateException, IllegalArgumentException {
155
156         params.put("HostName", "test");
157         params.put("Port", "10");
158         params.put("User", "test");
159         params.put("Password", "test");
160         params.put("Test", "success");
161         params.put("Cmd", "test");
162         params.put("SlsExec", "false");
163         try {
164             adapter.reqExecCommand(params, svcContext);
165             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
166             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
167             assertEquals("400", status);
168         } catch (NullPointerException e) {
169             fail(e.getMessage() + " Unknown exception encountered ");
170         }
171     }
172
173     @Test(expected = SvcLogicException.class)
174     public void reqExecCommand_NoResponseFileWithRetry() throws SvcLogicException,
175             IllegalStateException, IllegalArgumentException {
176
177         params.put("HostName", "test");
178         params.put("Port", "10");
179         params.put("User", "test");
180         params.put("Password", "test");
181         params.put("Test", "success");
182         params.put("retryDelay", "10");
183         params.put("retryCount", "10");
184         params.put("Cmd", "test");
185         params.put("SlsExec", "false");
186         try {
187             adapter.reqExecCommand(params, svcContext);
188             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
189             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
190             assertEquals("400", status);
191         } catch (NullPointerException e) {
192             fail(e.getMessage() + " Unknown exception encountered ");
193         }
194     }
195
196     @Test(expected = SvcLogicException.class)
197     public void reqExecCommand_NoResponseFileWithRetryZero() throws SvcLogicException,
198             IllegalStateException, IllegalArgumentException {
199
200         params.put("HostName", "test");
201         params.put("Port", "10");
202         params.put("User", "test");
203         params.put("Password", "test");
204         params.put("Test", "success");
205         params.put("retryDelay", "0");
206         params.put("retryCount", "0");
207         params.put("Cmd", "test");
208         params.put("SlsExec", "false");
209         try {
210             adapter.reqExecCommand(params, svcContext);
211             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
212             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
213             assertEquals("400", status);
214         } catch (NullPointerException e) {
215             fail(e.getMessage() + " Unknown exception encountered ");
216         }
217     }
218
219     @Test(expected = SvcLogicException.class)
220     public void reqExecCommand_NoResponseFileWithNoRetry() throws SvcLogicException,
221             IllegalStateException, IllegalArgumentException {
222
223         params.put("HostName", "test");
224         params.put("Port", "10");
225         params.put("User", "test");
226         params.put("Password", "test");
227         params.put("Test", "success");
228         params.put("retryDelay", "-1");
229         params.put("retryCount", "-1");
230         params.put("Cmd", "test");
231         params.put("SlsExec", "false");
232
233         try {
234             adapter.reqExecCommand(params, svcContext);
235             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
236             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
237             assertEquals("400", status);
238         } catch (NullPointerException e) {
239             fail(e.getMessage() + " Unknown exception encountered ");
240         }
241     }
242
243     @Test(expected = SvcLogicException.class)
244     public void reqExecCommand_shouldSetFailure() throws SvcLogicException,
245             IllegalStateException, IllegalArgumentException {
246
247         params.put("HostName", "test");
248         params.put("Port", "10");
249         params.put("User", "test");
250         params.put("Password", "test");
251         params.put("Cmd", "test");
252         params.put("SlsExec", "test");
253         params.put("Test", "fail");
254         try {
255             adapter.reqExecCommand(params, svcContext);
256             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
257             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
258             assertEquals("400", status);
259         } catch (NullPointerException e) {
260             fail(e.getMessage() + " Unknown exception encountered ");
261         }
262     }
263
264     @Test
265     public void reqExecCommand_shouldSetSuccessNoSLS() throws SvcLogicException,
266             IllegalStateException, IllegalArgumentException {
267
268         params.put("HostName", "test");
269         params.put("Port", "10");
270         params.put("User", "test");
271         params.put("Password", "test");
272         params.put("Test", "success");
273         params.put("fileName", "src/test/resources/test.json");
274         params.put("Id", "test1");
275         params.put("Cmd", "test");
276         params.put("SlsExec", "false");
277
278         adapter.reqExecCommand(params, svcContext);
279         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
280         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
281         assertEquals("200", status);
282         assertEquals(TestId, "test1");
283     }
284
285     @Test
286     public void reqExecCommand_shouldSetSuccessExecSLS() throws SvcLogicException,
287             IllegalStateException, IllegalArgumentException {
288
289         params.put("HostName", "test");
290         params.put("Port", "10");
291         params.put("User", "test");
292         params.put("Password", "test");
293         params.put("Test", "success");
294         params.put("fileName", "src/test/resources/test-sls.json");
295         params.put("Id", "test1");
296         params.put("Cmd", "test");
297         params.put("SlsExec", "true");
298
299         adapter.reqExecCommand(params, svcContext);
300         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
301         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
302         assertEquals("200", status);
303         assertEquals(TestId, "test1");
304     }
305
306     @Test(expected = SvcLogicException.class)
307     public void reqExecCommand_shouldSetFailExecSLS() throws SvcLogicException,
308             IllegalStateException, IllegalArgumentException {
309
310         params.put("HostName", "test");
311         params.put("Port", "10");
312         params.put("User", "test");
313         params.put("Password", "test");
314         params.put("Test", "success");
315         params.put("fileName", "src/test/resources/test.json");
316         params.put("Id", "test1");
317         params.put("Cmd", "test");
318         params.put("SlsExec", "true");
319
320         adapter.reqExecCommand(params, svcContext);
321         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
322         assertEquals(TestId, "test1");
323     }
324
325     @Test
326     public void reqExecCommand_shouldSetSuccessFileTxt() throws SvcLogicException,
327             IllegalStateException, IllegalArgumentException {
328
329         params.put("HostName", "test");
330         params.put("Port", "10");
331         params.put("User", "test");
332         params.put("Password", "test");
333         params.put("Test", "success");
334         params.put("fileName", "src/test/resources/test.txt");
335         params.put("Id", "txt");
336         params.put("Cmd", "test");
337         params.put("SlsExec", "false");
338
339         adapter.reqExecCommand(params, svcContext);
340         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
341         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
342         assertEquals("200", status);
343         assertEquals(TestId, "txt");
344     }
345
346     @Test
347     public void reqExecCommand_shouldSetSuccessFileNoExtension() throws SvcLogicException,
348             IllegalStateException, IllegalArgumentException {
349
350         params.put("HostName", "test");
351         params.put("Port", "10");
352         params.put("User", "test");
353         params.put("Password", "test");
354         params.put("Test", "success");
355         params.put("fileName", "src/test/resources/test");
356         params.put("Id", "txt");
357         params.put("Cmd", "test");
358         params.put("SlsExec", "false");
359
360         adapter.reqExecCommand(params, svcContext);
361         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
362         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
363         assertEquals("200", status);
364         assertEquals(TestId, "txt");
365     }
366
367     @Test
368     public void reqExecCommand_shouldSetSuccessFileInvalidJson() throws SvcLogicException,
369             IllegalStateException, IllegalArgumentException {
370
371         params.put("HostName", "test");
372         params.put("Port", "10");
373         params.put("User", "test");
374         params.put("Password", "test");
375         params.put("Test", "success");
376         params.put("fileName", "src/test/resources/test-invalid.json");
377         params.put("Id", "test1");
378         params.put("Cmd", "test");
379         params.put("SlsExec", "false");
380
381         adapter.reqExecCommand(params, svcContext);
382         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
383         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
384         assertEquals("200", status);
385     }
386
387     @Test(expected = SvcLogicException.class)
388     public void reqExecCommand_shouldSetFailFileInvalidFile() throws SvcLogicException,
389             IllegalStateException, IllegalArgumentException {
390
391         params.put("HostName", "test");
392         params.put("Port", "10");
393         params.put("User", "test");
394         params.put("Password", "test");
395         params.put("Test", "success");
396         params.put("fileName", "src/test/resources/test-none.json");
397         params.put("Id", "test1");
398
399         adapter.reqExecCommand(params, svcContext);
400     }
401
402     @Test
403     public void reqExecCommand_shouldSetSuccessFileJsonNoReqID() throws SvcLogicException,
404             IllegalStateException, IllegalArgumentException {
405
406         params.put("HostName", "test");
407         params.put("Port", "10");
408         params.put("User", "test");
409         params.put("Password", "test");
410         params.put("Test", "success");
411         params.put("fileName", "src/test/resources/test.json");
412         params.put("Cmd", "test");
413         params.put("SlsExec", "false");
414
415         adapter.reqExecCommand(params, svcContext);
416         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
417         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
418         assertEquals("200", status);
419     }
420
421     @Test
422     public void reqExecSLSFile_shouldSetSuccessJson() throws SvcLogicException,
423             IllegalStateException, IllegalArgumentException {
424
425         params.put("HostName", "test");
426         params.put("Port", "10");
427         params.put("User", "test");
428         params.put("Password", "test");
429         params.put("Test", "success");
430         params.put("SlsFile", "src/test/resources/test.sls");
431         params.put("fileName", "src/test/resources/test-sls.json");
432         params.put("Id", "test1");
433         params.put("Cmd", "test");
434
435         adapter.reqExecSLSFile(params, svcContext);
436         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
437         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
438         assertEquals("200", status);
439         assertEquals(TestId, "test1");
440     }
441
442     @Test(expected = SvcLogicException.class)
443     public void reqExecSLSFile_NoSLSfile() throws SvcLogicException,
444             IllegalStateException, IllegalArgumentException {
445
446         params.put("HostName", "test");
447         params.put("Port", "10");
448         params.put("User", "test");
449         params.put("Password", "test");
450         params.put("Test", "success");
451         params.put("SlsFile", "src/test/resources/test-none.sls");
452         params.put("fileName", "src/test/resources/test-sls.json");
453         params.put("Id", "test1");
454
455         adapter.reqExecSLSFile(params, svcContext);
456         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
457         assertEquals(TestId, "test1");
458     }
459
460     @Test(expected = SvcLogicException.class)
461     public void reqExecSLSFile_NoExtn() throws SvcLogicException,
462             IllegalStateException, IllegalArgumentException {
463
464         params.put("HostName", "test");
465         params.put("Port", "10");
466         params.put("User", "test");
467         params.put("Password", "test");
468         params.put("Test", "success");
469         params.put("SlsFile", "src/test/resources/test-none");
470         params.put("fileName", "src/test/resources/test-sls.json");
471         params.put("Id", "test1");
472
473         adapter.reqExecSLSFile(params, svcContext);
474         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
475         assertEquals(TestId, "test1");
476     }
477
478     @Test(expected = SvcLogicException.class)
479     public void reqExecSLSFile_NoResponsefile() throws SvcLogicException,
480             IllegalStateException, IllegalArgumentException {
481
482         params.put("HostName", "test");
483         params.put("Port", "10");
484         params.put("User", "test");
485         params.put("Password", "test");
486         params.put("Test", "success");
487         params.put("SlsFile", "src/test/resources/test.json");
488         params.put("fileName", "src/test/resources/test-none.json");
489         params.put("Id", "test1");
490
491         adapter.reqExecSLSFile(params, svcContext);
492         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
493         assertEquals(TestId, "test1");
494     }
495
496     @Test(expected = SvcLogicException.class)
497     public void reqExecSLSFile_WithMinionSetNotSLSType() throws SvcLogicException,
498             IllegalStateException, IllegalArgumentException {
499
500         params.put("HostName", "test");
501         params.put("Port", "10");
502         params.put("User", "test");
503         params.put("Password", "test");
504         params.put("Test", "success");
505         params.put("SlsFile", "src/test/resources/test.json");
506         params.put("fileName", "src/test/resources/test-sls.json");
507         params.put("Id", "test1");
508         params.put("Cmd", "test");
509         params.put("NodeList", "minion1");
510
511         adapter.reqExecSLSFile(params, svcContext);
512         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
513         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
514         assertEquals("200", status);
515         assertEquals(TestId, "test1");
516     }
517
518     @Test
519     public void reqExecSLSFile_WithMinionSetSuccessSls() throws SvcLogicException,
520             IllegalStateException, IllegalArgumentException {
521
522         params.put("HostName", "test");
523         params.put("Port", "10");
524         params.put("User", "test");
525         params.put("Password", "test");
526         params.put("Test", "success");
527         params.put("SlsFile", "src/test/resources/test.sls");
528         params.put("fileName", "src/test/resources/test-sls.json");
529         params.put("Id", "test1");
530         params.put("Cmd", "test");
531         params.put("NodeList", "minion1");
532
533         adapter.reqExecSLSFile(params, svcContext);
534         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
535         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
536         assertEquals("200", status);
537         assertEquals(TestId, "test1");
538     }
539
540     @Test(expected = SvcLogicException.class)
541     public void reqExecSLSFile_WithMinionNoSLSfile() throws SvcLogicException,
542             IllegalStateException, IllegalArgumentException {
543
544         params.put("HostName", "test");
545         params.put("Port", "10");
546         params.put("User", "test");
547         params.put("Password", "test");
548         params.put("Test", "success");
549         params.put("SlsFile", "src/test/resources/test-none.json");
550         params.put("fileName", "src/test/resources/test-sls.json");
551         params.put("Id", "test1");
552         params.put("NodeList", "minion1");
553
554         adapter.reqExecSLSFile(params, svcContext);
555         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
556         assertEquals(TestId, "test1");
557     }
558
559     @Test(expected = SvcLogicException.class)
560     public void reqExecSLSFile_WithMinionNoResponsefile() throws SvcLogicException,
561             IllegalStateException, IllegalArgumentException {
562
563         params.put("HostName", "test");
564         params.put("Port", "10");
565         params.put("User", "test");
566         params.put("Password", "test");
567         params.put("Test", "success");
568         params.put("SlsFile", "src/test/resources/test.json");
569         params.put("fileName", "src/test/resources/test-none.json");
570         params.put("Id", "test1");
571         params.put("NodeList", "minion1");
572
573         adapter.reqExecSLSFile(params, svcContext);
574         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
575         assertEquals(TestId, "test1");
576     }
577
578     @Test
579     public void reqExecSLSFile_WithAllMinionSetSuccessJson() throws SvcLogicException,
580             IllegalStateException, IllegalArgumentException {
581
582         params.put("HostName", "test");
583         params.put("Port", "10");
584         params.put("User", "test");
585         params.put("Password", "test");
586         params.put("Test", "success");
587         params.put("SlsFile", "src/test/resources/test.sls");
588         params.put("fileName", "src/test/resources/test-sls.json");
589         params.put("Id", "test1");
590         params.put("Cmd", "test");
591         params.put("NodeList", "*");
592
593         adapter.reqExecSLSFile(params, svcContext);
594         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
595         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
596         assertEquals("200", status);
597         assertEquals(TestId, "test1");
598     }
599
600     @Test(expected = SvcLogicException.class)
601     public void reqExecSLSFile_WithAllMinionNoSLSfile() throws SvcLogicException,
602             IllegalStateException, IllegalArgumentException {
603
604         params.put("HostName", "test");
605         params.put("Port", "10");
606         params.put("User", "test");
607         params.put("Password", "test");
608         params.put("Test", "success");
609         params.put("SlsFile", "src/test/resources/test-none.json");
610         params.put("fileName", "src/test/resources/test-sls.json");
611         params.put("Id", "test1");
612         params.put("NodeList", "*");
613
614         adapter.reqExecSLSFile(params, svcContext);
615         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
616         assertEquals(TestId, "test1");
617     }
618
619     @Test(expected = SvcLogicException.class)
620     public void reqExecSLSFile_WithAllMinionNoResponsefile() throws SvcLogicException,
621             IllegalStateException, IllegalArgumentException {
622
623         params.put("HostName", "test");
624         params.put("Port", "10");
625         params.put("User", "test");
626         params.put("Password", "test");
627         params.put("Test", "success");
628         params.put("SlsFile", "src/test/resources/test.json");
629         params.put("fileName", "src/test/resources/test-none.json");
630         params.put("Id", "test1");
631         params.put("NodeList", "*");
632
633         adapter.reqExecSLSFile(params, svcContext);
634         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
635         assertEquals(TestId, "test1");
636     }
637
638
639     @Test
640     public void reqExecSLS_shouldSetSuccessJson() throws SvcLogicException,
641             IllegalStateException, IllegalArgumentException {
642
643         params.put("HostName", "test");
644         params.put("Port", "10");
645         params.put("User", "test");
646         params.put("Password", "test");
647         params.put("Test", "success");
648         params.put("SlsName", "src/test.sls");
649         params.put("fileName", "src/test/resources/test-sls.json");
650         params.put("Id", "test1");
651         params.put("Cmd", "test");
652
653         adapter.reqExecSLS(params, svcContext);
654         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
655         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
656         assertEquals("200", status);
657         assertEquals(TestId, "test1");
658     }
659
660     @Test
661     public void reqExecSLS_shouldSetNoExtn() throws SvcLogicException,
662             IllegalStateException, IllegalArgumentException {
663
664         params.put("HostName", "test");
665         params.put("Port", "10");
666         params.put("User", "test");
667         params.put("Password", "test");
668         params.put("Test", "success");
669         params.put("SlsName", "src/test");
670         params.put("fileName", "src/test/resources/test-sls.json");
671         params.put("Id", "test1");
672         params.put("Cmd", "test");
673
674         adapter.reqExecSLS(params, svcContext);
675         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
676         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
677         assertEquals("200", status);
678         assertEquals(TestId, "test1");
679     }
680
681     @Test(expected = SvcLogicException.class)
682     public void reqExecSLS_NoResponsefile() throws SvcLogicException,
683             IllegalStateException, IllegalArgumentException {
684
685         params.put("HostName", "test");
686         params.put("Port", "10");
687         params.put("User", "test");
688         params.put("Password", "test");
689         params.put("Test", "success");
690         params.put("SlsName", "src/test/resources/test.json");
691         params.put("fileName", "src/test/resources/test-none.json");
692         params.put("Id", "test1");
693
694         adapter.reqExecSLS(params, svcContext);
695         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
696         assertEquals(TestId, "test1");
697     }
698
699
700     @Test
701     public void reqExecSLS_WithMinionSetSuccessSls() throws SvcLogicException,
702             IllegalStateException, IllegalArgumentException {
703
704         params.put("HostName", "test");
705         params.put("Port", "10");
706         params.put("User", "test");
707         params.put("Password", "test");
708         params.put("Test", "success");
709         params.put("SlsName", "src/test/resources/test.sls");
710         params.put("fileName", "src/test/resources/test-sls.json");
711         params.put("Id", "test1");
712         params.put("Cmd", "test");
713         params.put("NodeList", "minion1");
714
715         adapter.reqExecSLS(params, svcContext);
716         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
717         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
718         assertEquals("200", status);
719         assertEquals(TestId, "test1");
720     }
721
722
723     @Test(expected = SvcLogicException.class)
724     public void reqExecSLS_WithMinionNoResponsefile() throws SvcLogicException,
725             IllegalStateException, IllegalArgumentException {
726
727         params.put("HostName", "test");
728         params.put("Port", "10");
729         params.put("User", "test");
730         params.put("Password", "test");
731         params.put("Test", "success");
732         params.put("SlsName", "src/test/resources/test.json");
733         params.put("fileName", "src/test/resources/test-none.json");
734         params.put("Id", "test1");
735         params.put("NodeList", "minion1");
736
737         adapter.reqExecSLS(params, svcContext);
738         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
739         assertEquals(TestId, "test1");
740     }
741
742     @Test
743     public void reqExecSLS_WithAllMinionSetSuccessJson() throws SvcLogicException,
744             IllegalStateException, IllegalArgumentException {
745
746         params.put("HostName", "test");
747         params.put("Port", "10");
748         params.put("User", "test");
749         params.put("Password", "test");
750         params.put("Test", "success");
751         params.put("SlsName", "src/test/resources/test.sls");
752         params.put("fileName", "src/test/resources/test-sls.json");
753         params.put("Id", "test1");
754         params.put("Cmd", "test");
755         params.put("NodeList", "*");
756
757         adapter.reqExecSLS(params, svcContext);
758         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
759         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
760         assertEquals("200", status);
761         assertEquals(TestId, "test1");
762     }
763
764
765     @Test(expected = SvcLogicException.class)
766     public void reqExecSLS_WithAllMinionNoResponsefile() throws SvcLogicException,
767             IllegalStateException, IllegalArgumentException {
768
769         params.put("HostName", "test");
770         params.put("Port", "10");
771         params.put("User", "test");
772         params.put("Password", "test");
773         params.put("Test", "success");
774         params.put("SlsName", "src/test/resources/test.json");
775         params.put("fileName", "src/test/resources/test-none.json");
776         params.put("Id", "test1");
777         params.put("NodeList", "*");
778
779         adapter.reqExecSLS(params, svcContext);
780         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
781         assertEquals(TestId, "test1");
782     }
783
784
785     @Test
786     public void reqExecCommand_shouldSetSuccessReal() throws SvcLogicException,
787             IllegalStateException, IllegalArgumentException {
788
789         params.put("HostName", "127.0.0.1");
790         params.put("Port", "22");
791         params.put("User", "sdn");
792         params.put("Password", "foo");
793         params.put("Id", "test1");
794         params.put("Cmd", "ls -l");
795         params.put("SlsExec", "false");
796         params.put("Timeout", "120");
797         adapter = new SaltstackAdapterImpl();
798         try {
799             adapter.reqExecCommand(params, svcContext);
800             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
801             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
802             assertEquals("200", status);
803             assertEquals(TestId, "test1");
804         } catch (Exception e) {
805             //if local ssh is not enabled
806             System.out.print(e.getMessage());
807         }
808     }
809
810     @Test
811     public void reqExecCommand_shouldSetSuccessRealSLSCommand() throws SvcLogicException,
812             IllegalStateException, IllegalArgumentException {
813
814         params.put("HostName", "<IP>");
815         params.put("Port", "2222");
816         params.put("User", "root");
817         params.put("Password", "vagrant");
818         params.put("Id", "test1");
819         params.put("Cmd", "salt '*' test.ping --out=json --static");
820         params.put("SlsExec", "false");
821         params.put("Timeout", "120");
822
823         adapter = new SaltstackAdapterImpl();
824         try {
825             adapter.reqExecCommand(params, svcContext);
826             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
827             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
828             assertEquals("200", status);
829             assertEquals(TestId, "test1");
830             TestId = svcContext.getAttribute("test1.minion1");
831             assertEquals(TestId, "true");
832         } catch (Exception e) {
833             //if saltstack ssh IP is not enabled
834             System.out.print(e.getMessage());
835         }
836     }
837
838     @Test
839     public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException,
840             IllegalStateException, IllegalArgumentException {
841
842         params.put("HostName", "<IP>");
843         params.put("Port", "2222");
844         params.put("User", "root");
845         params.put("Password", "vagrant");
846         params.put("Id", "test1");
847         params.put("Cmd", "cd /srv/salt/; salt '*' state.apply vim --out=json --static");
848         params.put("SlsExec", "true");
849         params.put("Timeout", "120");
850
851         adapter = new SaltstackAdapterImpl();
852         try {
853             adapter.reqExecCommand(params, svcContext);
854             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
855             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
856             assertEquals("200", status);
857             assertEquals(TestId, "test1");
858         } catch (Exception e) {
859             //if saltstack ssh IP is not enabled
860             System.out.print(e.getMessage());
861         }
862     }
863
864     @Test
865     public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException,
866             IllegalStateException, IllegalArgumentException {
867
868         params.put("HostName", "<IP>");
869         params.put("Port", "2222");
870         params.put("User", "root");
871         params.put("Password", "vagrant");
872         params.put("Id", "test1");
873         params.put("SlsName", "vim");
874         params.put("Timeout", "120");
875         params.put("NodeList", "minion1");
876
877         adapter = new SaltstackAdapterImpl();
878         try {
879             adapter.reqExecSLS(params, svcContext);
880             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
881             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
882             assertEquals("200", status);
883             assertEquals(TestId, "test1");
884         } catch (Exception e) {
885             //if saltstack ssh IP is not enabled
886             System.out.print(e.getMessage());
887         }
888     }
889
890     @Test
891     public void reqExecCommand_shouldSetSuccessEnvParam() throws SvcLogicException,
892             IllegalStateException, IllegalArgumentException {
893
894         params.put("HostName", "<IP>");
895         params.put("Port", "2222");
896         params.put("User", "root");
897         params.put("Password", "vagrant");
898         params.put("Id", "test1");
899         params.put("SlsName", "vim");
900         params.put("Timeout", "120");
901         params.put("NodeList", "minion1");
902         params.put("EnvParameters", "{\"exclude\": bar*}");
903
904         adapter = new SaltstackAdapterImpl();
905         try {
906             adapter.reqExecSLS(params, svcContext);
907             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
908             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
909             assertEquals("200", status);
910             assertEquals(TestId, "test1");
911         } catch (Exception e) {
912             //if saltstack ssh IP is not enabled
913             System.out.print(e.getMessage());
914         }
915     }
916
917     @Test
918     public void reqExecCommand_shouldSetSuccessFileParam() throws SvcLogicException,
919             IllegalStateException, IllegalArgumentException {
920
921         params.put("HostName", "<IP>");
922         params.put("Port", "2222");
923         params.put("User", "root");
924         params.put("Password", "vagrant");
925         params.put("Id", "test1");
926         params.put("SlsName", "vim");
927         params.put("Timeout", "120");
928         params.put("NodeList", "minion1");
929         params.put("EnvParameters", "{\"exclude\": \"bar,baz\"}");
930         params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
931
932         adapter = new SaltstackAdapterImpl();
933         try {
934             adapter.reqExecSLS(params, svcContext);
935             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
936             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
937             assertEquals("200", status);
938             assertEquals(TestId, "test1");
939         } catch (Exception e) {
940             //if saltstack ssh IP is not enabled
941             System.out.print(e.getMessage());
942         }
943     }
944
945     @Test
946     public void reqExecCommand_shouldSetSuccessPillarParam() throws SvcLogicException,
947             IllegalStateException, IllegalArgumentException {
948
949         params.put("HostName", "<IP>");
950         params.put("Port", "2222");
951         params.put("User", "root");
952         params.put("Password", "vagrant");
953         params.put("Id", "test1");
954         params.put("SlsName", "vim");
955         params.put("Timeout", "120");
956         params.put("NodeList", "minion1");
957         params.put("EnvParameters", "{\"exclude\": \"bar,baz\", \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
958         params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
959
960         adapter = new SaltstackAdapterImpl();
961         try {
962             adapter.reqExecSLS(params, svcContext);
963             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
964             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
965             assertEquals("200", status);
966             assertEquals(TestId, "test1");
967         } catch (Exception e) {
968             //if saltstack ssh IP is not enabled
969             System.out.print(e.getMessage());
970         }
971     }
972
973     @Test
974     public void reqExecCommand_shouldSetSuccessMultiFileParam() throws SvcLogicException,
975             IllegalStateException, IllegalArgumentException {
976
977         params.put("HostName", "<IP>");
978         params.put("Port", "2222");
979         params.put("User", "root");
980         params.put("Password", "vagrant");
981         params.put("Id", "test1");
982         params.put("SlsName", "vim");
983         params.put("Timeout", "120");
984         params.put("NodeList", "minion1");
985         params.put("EnvParameters", "{\"exclude\": bar*}");
986         params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
987
988         adapter = new SaltstackAdapterImpl();
989         try {
990             adapter.reqExecSLS(params, svcContext);
991             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
992             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
993             assertEquals("200", status);
994             assertEquals(TestId, "test1");
995         } catch (Exception e) {
996             //if saltstack ssh IP is not enabled
997             System.out.print(e.getMessage());
998         }
999     }
1000
1001     @Test
1002     public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException,
1003             IllegalStateException, IllegalArgumentException {
1004
1005         params.put("HostName", "<IP>");
1006         params.put("Port", "2222");
1007         params.put("User", "root");
1008         params.put("Password", "vagrant");
1009         params.put("Id", "test1");
1010         params.put("Timeout", "120");
1011         params.put("NodeList", "minion1");
1012         params.put("SlsFile", "src/test/resources/config.sls");
1013
1014         adapter = new SaltstackAdapterImpl();
1015         try {
1016             adapter.reqExecSLSFile(params, svcContext);
1017             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
1018             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
1019             assertEquals("200", status);
1020             assertEquals(TestId, "test1");
1021         } catch (Exception e) {
1022             //if saltstack ssh IP is not enabled
1023             System.out.print(e.getMessage());
1024         }
1025     }
1026
1027     @Test
1028     public void reqExecCommand_shouldSetSuccessSSLFileMultiFileParam() throws SvcLogicException,
1029             IllegalStateException, IllegalArgumentException {
1030
1031         params.put("HostName", "<IP>");
1032         params.put("Port", "2222");
1033         params.put("User", "root");
1034         params.put("Password", "vagrant");
1035         params.put("Id", "test1");
1036         params.put("Timeout", "120");
1037         params.put("NodeList", "minion1");
1038         params.put("SlsFile", "src/test/resources/config.sls");
1039         params.put("EnvParameters", "{\"exclude\": bar, \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
1040         params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\" , \"config-tep.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
1041
1042         adapter = new SaltstackAdapterImpl();
1043         try {
1044             adapter.reqExecSLSFile(params, svcContext);
1045             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
1046             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
1047             assertEquals("200", status);
1048             assertEquals(TestId, "test1");
1049         } catch (Exception e) {
1050             //if saltstack ssh IP is not enabled
1051             System.out.print(e.getMessage());
1052         }
1053     }
1054 }