d60059e402786ea9f490d77104e0af9499ebcf60
[ccsdk/sli/adaptors.git] / saltstack-adapter / saltstack-adapter-provider / src / test / java / org / onap / appc / adapter / impl / TestSaltstackAdapterImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.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 final String PENDING = "100";
44     private final String SUCCESS = "400";
45     private String message = "{\"Results\":{\"192.168.1.10\":{\"Id\":\"101\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"}},\"StatusCode\":200,\"StatusMessage\":\"FINISHED\"}";
46
47     private SaltstackAdapterImpl adapter;
48     private String TestId;
49     private boolean testMode = true;
50     private Map<String, String> params;
51     private SvcLogicContext svcContext;
52
53
54     @Before
55     public void setup() throws IllegalArgumentException {
56         testMode = true;
57         svcContext = new SvcLogicContext();
58         adapter = new SaltstackAdapterImpl(testMode);
59
60         params = new HashMap<>();
61         params.put("AgentUrl", "https://192.168.1.1");
62         params.put("User", "test");
63         params.put("Password", "test");
64     }
65
66     @After
67     public void tearDown() {
68         testMode = false;
69         adapter = null;
70         params = null;
71         svcContext = null;
72     }
73
74     @Test(expected = SvcLogicException.class)
75     public void reqExecCommand_shouldSetFailed() throws SvcLogicException,
76             IllegalStateException, IllegalArgumentException {
77
78         params.put("HostName", "test");
79         params.put("Port", "10");
80         params.put("User", "test");
81         params.put("Password", "test");
82         params.put("Test", "fail");
83         adapter.reqExecCommand(params, svcContext);
84         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
85         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
86         assertEquals("101", status);
87     }
88
89     @Test(expected = SvcLogicException.class)
90     public void reqExecCommand_shouldSetUserFailed() throws SvcLogicException,
91             IllegalStateException, IllegalArgumentException {
92
93         params.put("HostName", "test");
94         params.put("Port", "10");
95         params.put("Password", "test");
96         params.put("Test", "fail");
97         adapter.reqExecCommand(params, svcContext);
98         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
99         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
100         assertEquals("101", status);
101     }
102
103     @Test(expected = SvcLogicException.class)
104     public void reqExecCommand_shouldSetHostFailed() throws SvcLogicException,
105             IllegalStateException, IllegalArgumentException {
106
107         params.put("Port", "10");
108         params.put("User", "test");
109         params.put("Password", "test");
110         params.put("Test", "fail");
111         adapter.reqExecCommand(params, svcContext);
112         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
113         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
114         assertEquals("101", status);
115     }
116
117     @Test(expected = SvcLogicException.class)
118     public void reqExecCommand_shouldSetPortFailed() throws SvcLogicException,
119             IllegalStateException, IllegalArgumentException {
120
121         params.put("HostName", "test");
122         params.put("User", "test");
123         params.put("Password", "test");
124         params.put("Test", "fail");
125         adapter.reqExecCommand(params, svcContext);
126         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
127         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
128         assertEquals("101", status);
129     }
130
131     @Test(expected = SvcLogicException.class)
132     public void reqExecCommand_shouldSetPasswordFailed() throws SvcLogicException,
133             IllegalStateException, IllegalArgumentException {
134
135         params.put("HostName", "test");
136         params.put("Port", "10");
137         params.put("User", "test");
138         params.put("Test", "fail");
139         adapter.reqExecCommand(params, svcContext);
140         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
141         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
142         assertEquals("101", status);
143     }
144
145     @Test(expected = SvcLogicException.class)
146     public void reqExecCommand_shouldSetMandatoryFailed() throws SvcLogicException,
147             IllegalStateException, IllegalArgumentException {
148
149         params.put("Test", "fail");
150         adapter.reqExecCommand(params, svcContext);
151         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
152         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
153         assertEquals("101", status);
154     }
155
156     @Test(expected = SvcLogicException.class)
157     public void reqExecCommand_NoResponseFile() throws SvcLogicException,
158             IllegalStateException, IllegalArgumentException {
159
160         params.put("HostName", "test");
161         params.put("Port", "10");
162         params.put("User", "test");
163         params.put("Password", "test");
164         params.put("Test", "success");
165         params.put("cmd", "test");
166         params.put("slsExec", "false");
167         try {
168             adapter.reqExecCommand(params, svcContext);
169             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
170             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
171             assertEquals("400", status);
172         } catch (NullPointerException e) {
173             fail(e.getMessage() + " Unknown exception encountered ");
174         }
175     }
176
177     @Test(expected = SvcLogicException.class)
178     public void reqExecCommand_NoResponseFileWithRetry() throws SvcLogicException,
179             IllegalStateException, IllegalArgumentException {
180
181         params.put("HostName", "test");
182         params.put("Port", "10");
183         params.put("User", "test");
184         params.put("Password", "test");
185         params.put("Test", "success");
186         params.put("retryDelay", "10");
187         params.put("retryCount", "10");
188         params.put("cmd", "test");
189         params.put("slsExec", "false");
190         try {
191             adapter.reqExecCommand(params, svcContext);
192             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
193             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
194             assertEquals("400", status);
195         } catch (NullPointerException e) {
196             fail(e.getMessage() + " Unknown exception encountered ");
197         }
198     }
199
200     @Test(expected = SvcLogicException.class)
201     public void reqExecCommand_NoResponseFileWithRetryZero() throws SvcLogicException,
202             IllegalStateException, IllegalArgumentException {
203
204         params.put("HostName", "test");
205         params.put("Port", "10");
206         params.put("User", "test");
207         params.put("Password", "test");
208         params.put("Test", "success");
209         params.put("retryDelay", "0");
210         params.put("retryCount", "0");
211         params.put("cmd", "test");
212         params.put("slsExec", "false");
213         try {
214             adapter.reqExecCommand(params, svcContext);
215             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
216             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
217             assertEquals("400", status);
218         } catch (NullPointerException e) {
219             fail(e.getMessage() + " Unknown exception encountered ");
220         }
221     }
222
223     @Test(expected = SvcLogicException.class)
224     public void reqExecCommand_NoResponseFileWithNoRetry() throws SvcLogicException,
225             IllegalStateException, IllegalArgumentException {
226
227         params.put("HostName", "test");
228         params.put("Port", "10");
229         params.put("User", "test");
230         params.put("Password", "test");
231         params.put("Test", "success");
232         params.put("retryDelay", "-1");
233         params.put("retryCount", "-1");
234         params.put("cmd", "test");
235         params.put("slsExec", "false");
236
237         try {
238             adapter.reqExecCommand(params, svcContext);
239             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
240             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
241             assertEquals("400", status);
242         } catch (NullPointerException e) {
243             fail(e.getMessage() + " Unknown exception encountered ");
244         }
245     }
246
247     @Test(expected = SvcLogicException.class)
248     public void reqExecCommand_shouldSetFailure() throws SvcLogicException,
249             IllegalStateException, IllegalArgumentException {
250
251         params.put("HostName", "test");
252         params.put("Port", "10");
253         params.put("User", "test");
254         params.put("Password", "test");
255         params.put("cmd", "test");
256         params.put("slsExec", "test");
257         params.put("Test", "fail");
258         try {
259             adapter.reqExecCommand(params, svcContext);
260             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
261             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
262             assertEquals("400", status);
263         } catch (NullPointerException e) {
264             fail(e.getMessage() + " Unknown exception encountered ");
265         }
266     }
267
268     @Test
269     public void reqExecCommand_shouldSetSuccessNoSLS() throws SvcLogicException,
270             IllegalStateException, IllegalArgumentException {
271
272         params.put("HostName", "test");
273         params.put("Port", "10");
274         params.put("User", "test");
275         params.put("Password", "test");
276         params.put("Test", "success");
277         params.put("fileName", "src/test/resources/test.json");
278         params.put("Id", "test1");
279         params.put("cmd", "test");
280         params.put("slsExec", "false");
281
282         adapter.reqExecCommand(params, svcContext);
283         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
284         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
285         assertEquals("250", status);
286         assertEquals(TestId, "test1");
287     }
288
289     @Test
290     public void reqExecCommand_shouldSetSuccessExecSLS() throws SvcLogicException,
291             IllegalStateException, IllegalArgumentException {
292
293         params.put("HostName", "test");
294         params.put("Port", "10");
295         params.put("User", "test");
296         params.put("Password", "test");
297         params.put("Test", "success");
298         params.put("fileName", "src/test/resources/test-sls.json");
299         params.put("Id", "test1");
300         params.put("cmd", "test");
301         params.put("slsExec", "true");
302
303         adapter.reqExecCommand(params, svcContext);
304         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
305         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
306         assertEquals("200", status);
307         assertEquals(TestId, "test1");
308     }
309
310     @Test(expected = SvcLogicException.class)
311     public void reqExecCommand_shouldSetFailExecSLS() throws SvcLogicException,
312             IllegalStateException, IllegalArgumentException {
313
314         params.put("HostName", "test");
315         params.put("Port", "10");
316         params.put("User", "test");
317         params.put("Password", "test");
318         params.put("Test", "success");
319         params.put("fileName", "src/test/resources/test.json");
320         params.put("Id", "test1");
321         params.put("cmd", "test");
322         params.put("slsExec", "true");
323
324         adapter.reqExecCommand(params, svcContext);
325         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
326         assertEquals(TestId, "test1");
327     }
328
329     @Test
330     public void reqExecCommand_shouldSetSuccessFileTxt() throws SvcLogicException,
331             IllegalStateException, IllegalArgumentException {
332
333         params.put("HostName", "test");
334         params.put("Port", "10");
335         params.put("User", "test");
336         params.put("Password", "test");
337         params.put("Test", "success");
338         params.put("fileName", "src/test/resources/test.txt");
339         params.put("Id", "txt");
340         params.put("cmd", "test");
341         params.put("slsExec", "false");
342
343         adapter.reqExecCommand(params, svcContext);
344         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
345         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
346         assertEquals("250", status);
347         assertEquals(TestId, "txt");
348     }
349
350     @Test
351     public void reqExecCommand_shouldSetSuccessFileNoExtension() throws SvcLogicException,
352             IllegalStateException, IllegalArgumentException {
353
354         params.put("HostName", "test");
355         params.put("Port", "10");
356         params.put("User", "test");
357         params.put("Password", "test");
358         params.put("Test", "success");
359         params.put("fileName", "src/test/resources/test");
360         params.put("Id", "txt");
361         params.put("cmd", "test");
362         params.put("slsExec", "false");
363
364         adapter.reqExecCommand(params, svcContext);
365         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
366         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
367         assertEquals("250", status);
368         assertEquals(TestId, "txt");
369     }
370
371     @Test
372     public void reqExecCommand_shouldSetSuccessFileInvalidJson() throws SvcLogicException,
373             IllegalStateException, IllegalArgumentException {
374
375         params.put("HostName", "test");
376         params.put("Port", "10");
377         params.put("User", "test");
378         params.put("Password", "test");
379         params.put("Test", "success");
380         params.put("fileName", "src/test/resources/test-invalid.json");
381         params.put("Id", "test1");
382         params.put("cmd", "test");
383         params.put("slsExec", "false");
384
385         adapter.reqExecCommand(params, svcContext);
386         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
387         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
388         assertEquals("250", status);
389     }
390
391     @Test(expected = SvcLogicException.class)
392     public void reqExecCommand_shouldSetFailFileInvalidFile() throws SvcLogicException,
393             IllegalStateException, IllegalArgumentException {
394
395         params.put("HostName", "test");
396         params.put("Port", "10");
397         params.put("User", "test");
398         params.put("Password", "test");
399         params.put("Test", "success");
400         params.put("fileName", "src/test/resources/test-none.json");
401         params.put("Id", "test1");
402
403         adapter.reqExecCommand(params, svcContext);
404     }
405
406     @Test
407     public void reqExecCommand_shouldSetSuccessFileJsonNoReqID() throws SvcLogicException,
408             IllegalStateException, IllegalArgumentException {
409
410         params.put("HostName", "test");
411         params.put("Port", "10");
412         params.put("User", "test");
413         params.put("Password", "test");
414         params.put("Test", "success");
415         params.put("fileName", "src/test/resources/test.json");
416         params.put("cmd", "test");
417         params.put("slsExec", "false");
418
419         adapter.reqExecCommand(params, svcContext);
420         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
421         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
422         assertEquals("250", status);
423     }
424
425     @Test
426     public void reqExecSLSFile_shouldSetSuccessJson() throws SvcLogicException,
427             IllegalStateException, IllegalArgumentException {
428
429         params.put("HostName", "test");
430         params.put("Port", "10");
431         params.put("User", "test");
432         params.put("Password", "test");
433         params.put("Test", "success");
434         params.put("slsFile", "src/test/resources/test.sls");
435         params.put("fileName", "src/test/resources/test-sls.json");
436         params.put("Id", "test1");
437         params.put("cmd", "test");
438
439         adapter.reqExecSLSFile(params, svcContext);
440         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
441         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
442         assertEquals("200", status);
443         assertEquals(TestId, "test1");
444     }
445
446     @Test(expected = SvcLogicException.class)
447     public void reqExecSLSFile_NoSLSfile() throws SvcLogicException,
448             IllegalStateException, IllegalArgumentException {
449
450         params.put("HostName", "test");
451         params.put("Port", "10");
452         params.put("User", "test");
453         params.put("Password", "test");
454         params.put("Test", "success");
455         params.put("slsFile", "src/test/resources/test-none.sls");
456         params.put("fileName", "src/test/resources/test-sls.json");
457         params.put("Id", "test1");
458
459         adapter.reqExecSLSFile(params, svcContext);
460         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
461         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
462         assertEquals(TestId, "test1");
463     }
464
465     @Test(expected = SvcLogicException.class)
466     public void reqExecSLSFile_NoExtn() throws SvcLogicException,
467             IllegalStateException, IllegalArgumentException {
468
469         params.put("HostName", "test");
470         params.put("Port", "10");
471         params.put("User", "test");
472         params.put("Password", "test");
473         params.put("Test", "success");
474         params.put("slsFile", "src/test/resources/test-none");
475         params.put("fileName", "src/test/resources/test-sls.json");
476         params.put("Id", "test1");
477
478         adapter.reqExecSLSFile(params, svcContext);
479         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
480         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
481         assertEquals(TestId, "test1");
482     }
483
484     @Test(expected = SvcLogicException.class)
485     public void reqExecSLSFile_NoResponsefile() throws SvcLogicException,
486             IllegalStateException, IllegalArgumentException {
487
488         params.put("HostName", "test");
489         params.put("Port", "10");
490         params.put("User", "test");
491         params.put("Password", "test");
492         params.put("Test", "success");
493         params.put("slsFile", "src/test/resources/test.json");
494         params.put("fileName", "src/test/resources/test-none.json");
495         params.put("Id", "test1");
496
497         adapter.reqExecSLSFile(params, svcContext);
498         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
499         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
500         assertEquals(TestId, "test1");
501     }
502
503     @Test(expected = SvcLogicException.class)
504     public void reqExecSLSFile_WithMinionSetNotSLSType() throws SvcLogicException,
505             IllegalStateException, IllegalArgumentException {
506
507         params.put("HostName", "test");
508         params.put("Port", "10");
509         params.put("User", "test");
510         params.put("Password", "test");
511         params.put("Test", "success");
512         params.put("slsFile", "src/test/resources/test.json");
513         params.put("fileName", "src/test/resources/test-sls.json");
514         params.put("Id", "test1");
515         params.put("cmd", "test");
516         params.put("applyTo", "minion1");
517
518         adapter.reqExecSLSFile(params, svcContext);
519         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
520         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
521         assertEquals("200", status);
522         assertEquals(TestId, "test1");
523     }
524
525     @Test
526     public void reqExecSLSFile_WithMinionSetSuccessSls() throws SvcLogicException,
527             IllegalStateException, IllegalArgumentException {
528
529         params.put("HostName", "test");
530         params.put("Port", "10");
531         params.put("User", "test");
532         params.put("Password", "test");
533         params.put("Test", "success");
534         params.put("slsFile", "src/test/resources/test.sls");
535         params.put("fileName", "src/test/resources/test-sls.json");
536         params.put("Id", "test1");
537         params.put("cmd", "test");
538         params.put("applyTo", "minion1");
539
540         adapter.reqExecSLSFile(params, svcContext);
541         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
542         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
543         assertEquals("200", status);
544         assertEquals(TestId, "test1");
545     }
546
547     @Test(expected = SvcLogicException.class)
548     public void reqExecSLSFile_WithMinionNoSLSfile() throws SvcLogicException,
549             IllegalStateException, IllegalArgumentException {
550
551         params.put("HostName", "test");
552         params.put("Port", "10");
553         params.put("User", "test");
554         params.put("Password", "test");
555         params.put("Test", "success");
556         params.put("slsFile", "src/test/resources/test-none.json");
557         params.put("fileName", "src/test/resources/test-sls.json");
558         params.put("Id", "test1");
559         params.put("applyTo", "minion1");
560
561         adapter.reqExecSLSFile(params, svcContext);
562         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
563         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
564         assertEquals(TestId, "test1");
565     }
566
567     @Test(expected = SvcLogicException.class)
568     public void reqExecSLSFile_WithMinionNoResponsefile() throws SvcLogicException,
569             IllegalStateException, IllegalArgumentException {
570
571         params.put("HostName", "test");
572         params.put("Port", "10");
573         params.put("User", "test");
574         params.put("Password", "test");
575         params.put("Test", "success");
576         params.put("slsFile", "src/test/resources/test.json");
577         params.put("fileName", "src/test/resources/test-none.json");
578         params.put("Id", "test1");
579         params.put("applyTo", "minion1");
580
581         adapter.reqExecSLSFile(params, svcContext);
582         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
583         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
584         assertEquals(TestId, "test1");
585     }
586
587     @Test
588     public void reqExecSLSFile_WithAllMinionSetSuccessJson() throws SvcLogicException,
589             IllegalStateException, IllegalArgumentException {
590
591         params.put("HostName", "test");
592         params.put("Port", "10");
593         params.put("User", "test");
594         params.put("Password", "test");
595         params.put("Test", "success");
596         params.put("slsFile", "src/test/resources/test.sls");
597         params.put("fileName", "src/test/resources/test-sls.json");
598         params.put("Id", "test1");
599         params.put("cmd", "test");
600         params.put("applyTo", "*");
601
602         adapter.reqExecSLSFile(params, svcContext);
603         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
604         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
605         assertEquals("200", status);
606         assertEquals(TestId, "test1");
607     }
608
609     @Test(expected = SvcLogicException.class)
610     public void reqExecSLSFile_WithAllMinionNoSLSfile() throws SvcLogicException,
611             IllegalStateException, IllegalArgumentException {
612
613         params.put("HostName", "test");
614         params.put("Port", "10");
615         params.put("User", "test");
616         params.put("Password", "test");
617         params.put("Test", "success");
618         params.put("slsFile", "src/test/resources/test-none.json");
619         params.put("fileName", "src/test/resources/test-sls.json");
620         params.put("Id", "test1");
621         params.put("applyTo", "*");
622
623         adapter.reqExecSLSFile(params, svcContext);
624         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
625         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
626         assertEquals(TestId, "test1");
627     }
628
629     @Test(expected = SvcLogicException.class)
630     public void reqExecSLSFile_WithAllMinionNoResponsefile() throws SvcLogicException,
631             IllegalStateException, IllegalArgumentException {
632
633         params.put("HostName", "test");
634         params.put("Port", "10");
635         params.put("User", "test");
636         params.put("Password", "test");
637         params.put("Test", "success");
638         params.put("slsFile", "src/test/resources/test.json");
639         params.put("fileName", "src/test/resources/test-none.json");
640         params.put("Id", "test1");
641         params.put("applyTo", "*");
642
643         adapter.reqExecSLSFile(params, svcContext);
644         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
645         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
646         assertEquals(TestId, "test1");
647     }
648
649
650     @Test
651     public void reqExecSLS_shouldSetSuccessJson() throws SvcLogicException,
652             IllegalStateException, IllegalArgumentException {
653
654         params.put("HostName", "test");
655         params.put("Port", "10");
656         params.put("User", "test");
657         params.put("Password", "test");
658         params.put("Test", "success");
659         params.put("slsName", "src/test.sls");
660         params.put("fileName", "src/test/resources/test-sls.json");
661         params.put("Id", "test1");
662         params.put("cmd", "test");
663
664         adapter.reqExecSLS(params, svcContext);
665         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
666         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
667         assertEquals("200", status);
668         assertEquals(TestId, "test1");
669     }
670
671     @Test
672     public void reqExecSLS_shouldSetNoExtn() throws SvcLogicException,
673             IllegalStateException, IllegalArgumentException {
674
675         params.put("HostName", "test");
676         params.put("Port", "10");
677         params.put("User", "test");
678         params.put("Password", "test");
679         params.put("Test", "success");
680         params.put("slsName", "src/test");
681         params.put("fileName", "src/test/resources/test-sls.json");
682         params.put("Id", "test1");
683         params.put("cmd", "test");
684
685         adapter.reqExecSLS(params, svcContext);
686         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
687         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
688         assertEquals("200", status);
689         assertEquals(TestId, "test1");
690     }
691
692     @Test(expected = SvcLogicException.class)
693     public void reqExecSLS_NoResponsefile() throws SvcLogicException,
694             IllegalStateException, IllegalArgumentException {
695
696         params.put("HostName", "test");
697         params.put("Port", "10");
698         params.put("User", "test");
699         params.put("Password", "test");
700         params.put("Test", "success");
701         params.put("slsName", "src/test/resources/test.json");
702         params.put("fileName", "src/test/resources/test-none.json");
703         params.put("Id", "test1");
704
705         adapter.reqExecSLS(params, svcContext);
706         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
707         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
708         assertEquals(TestId, "test1");
709     }
710
711
712     @Test
713     public void reqExecSLS_WithMinionSetSuccessSls() throws SvcLogicException,
714             IllegalStateException, IllegalArgumentException {
715
716         params.put("HostName", "test");
717         params.put("Port", "10");
718         params.put("User", "test");
719         params.put("Password", "test");
720         params.put("Test", "success");
721         params.put("slsName", "src/test/resources/test.sls");
722         params.put("fileName", "src/test/resources/test-sls.json");
723         params.put("Id", "test1");
724         params.put("cmd", "test");
725         params.put("applyTo", "minion1");
726
727         adapter.reqExecSLS(params, svcContext);
728         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
729         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
730         assertEquals("200", status);
731         assertEquals(TestId, "test1");
732     }
733
734
735     @Test(expected = SvcLogicException.class)
736     public void reqExecSLS_WithMinionNoResponsefile() throws SvcLogicException,
737             IllegalStateException, IllegalArgumentException {
738
739         params.put("HostName", "test");
740         params.put("Port", "10");
741         params.put("User", "test");
742         params.put("Password", "test");
743         params.put("Test", "success");
744         params.put("slsName", "src/test/resources/test.json");
745         params.put("fileName", "src/test/resources/test-none.json");
746         params.put("Id", "test1");
747         params.put("applyTo", "minion1");
748
749         adapter.reqExecSLS(params, svcContext);
750         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
751         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
752         assertEquals(TestId, "test1");
753     }
754
755     @Test
756     public void reqExecSLS_WithAllMinionSetSuccessJson() throws SvcLogicException,
757             IllegalStateException, IllegalArgumentException {
758
759         params.put("HostName", "test");
760         params.put("Port", "10");
761         params.put("User", "test");
762         params.put("Password", "test");
763         params.put("Test", "success");
764         params.put("slsName", "src/test/resources/test.sls");
765         params.put("fileName", "src/test/resources/test-sls.json");
766         params.put("Id", "test1");
767         params.put("cmd", "test");
768         params.put("applyTo", "*");
769
770         adapter.reqExecSLS(params, svcContext);
771         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
772         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
773         assertEquals("200", status);
774         assertEquals(TestId, "test1");
775     }
776
777
778     @Test(expected = SvcLogicException.class)
779     public void reqExecSLS_WithAllMinionNoResponsefile() throws SvcLogicException,
780             IllegalStateException, IllegalArgumentException {
781
782         params.put("HostName", "test");
783         params.put("Port", "10");
784         params.put("User", "test");
785         params.put("Password", "test");
786         params.put("Test", "success");
787         params.put("slsName", "src/test/resources/test.json");
788         params.put("fileName", "src/test/resources/test-none.json");
789         params.put("Id", "test1");
790         params.put("applyTo", "*");
791
792         adapter.reqExecSLS(params, svcContext);
793         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
794         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
795         assertEquals(TestId, "test1");
796     }
797
798
799     @Test
800     public void reqExecLog_shouldSetMessage() throws IllegalStateException, IllegalArgumentException {
801
802         params.put("Id", "101");
803
804         try {
805             adapter.reqExecLog(params, svcContext);
806             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log");
807             //assertEquals(message, status);
808             assertEquals(null, status);
809         } catch (SvcLogicException e) {
810             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log");
811             fail(e.getMessage() + " Code = " + status);
812         } catch (Exception e) {
813             fail(e.getMessage() + " Unknown exception encountered ");
814         }
815     }
816 }