2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.ccsdk.adapter.impl;
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;
34 import java.util.HashMap;
37 import static org.junit.Assert.assertEquals;
38 import static org.junit.Assert.fail;
41 public class TestSaltstackAdapterImpl {
43 private SaltstackAdapterImpl adapter;
44 private String TestId;
45 private boolean testMode = true;
46 private Map<String, String> params;
47 private SvcLogicContext svcContext;
51 public void setup() throws IllegalArgumentException {
53 svcContext = new SvcLogicContext();
54 adapter = new SaltstackAdapterImpl(testMode);
56 params = new HashMap<>();
57 params.put("AgentUrl", "https://192.168.1.1");
58 params.put("User", "test");
59 params.put("Password", "test");
63 public void tearDown() {
70 @Test(expected = SvcLogicException.class)
71 public void reqExecCommand_shouldSetFailed() throws SvcLogicException,
72 IllegalStateException, IllegalArgumentException {
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);
85 @Test(expected = SvcLogicException.class)
86 public void reqExecCommand_shouldSetUserFailed() throws SvcLogicException,
87 IllegalStateException, IllegalArgumentException {
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);
99 @Test(expected = SvcLogicException.class)
100 public void reqExecCommand_shouldSetHostFailed() throws SvcLogicException,
101 IllegalStateException, IllegalArgumentException {
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);
113 @Test(expected = SvcLogicException.class)
114 public void reqExecCommand_shouldSetPortFailed() throws SvcLogicException,
115 IllegalStateException, IllegalArgumentException {
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);
127 @Test(expected = SvcLogicException.class)
128 public void reqExecCommand_shouldSetPasswordFailed() throws SvcLogicException,
129 IllegalStateException, IllegalArgumentException {
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);
141 @Test(expected = SvcLogicException.class)
142 public void reqExecCommand_shouldSetMandatoryFailed() throws SvcLogicException,
143 IllegalStateException, IllegalArgumentException {
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);
152 @Test(expected = SvcLogicException.class)
153 public void reqExecCommand_NoResponseFile() throws SvcLogicException,
154 IllegalStateException, IllegalArgumentException {
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");
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 ");
173 @Test(expected = SvcLogicException.class)
174 public void reqExecCommand_NoResponseFileWithRetry() throws SvcLogicException,
175 IllegalStateException, IllegalArgumentException {
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");
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 ");
196 @Test(expected = SvcLogicException.class)
197 public void reqExecCommand_NoResponseFileWithRetryZero() throws SvcLogicException,
198 IllegalStateException, IllegalArgumentException {
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");
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 ");
219 @Test(expected = SvcLogicException.class)
220 public void reqExecCommand_NoResponseFileWithNoRetry() throws SvcLogicException,
221 IllegalStateException, IllegalArgumentException {
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");
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 ");
243 @Test(expected = SvcLogicException.class)
244 public void reqExecCommand_shouldSetFailure() throws SvcLogicException,
245 IllegalStateException, IllegalArgumentException {
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");
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 ");
265 public void reqExecCommand_shouldSetSuccessNoSLS() throws SvcLogicException,
266 IllegalStateException, IllegalArgumentException {
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");
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("250", status);
282 assertEquals(TestId, "test1");
286 public void reqExecCommand_shouldSetSuccessExecSLS() throws SvcLogicException,
287 IllegalStateException, IllegalArgumentException {
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");
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");
306 @Test(expected = SvcLogicException.class)
307 public void reqExecCommand_shouldSetFailExecSLS() throws SvcLogicException,
308 IllegalStateException, IllegalArgumentException {
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");
320 adapter.reqExecCommand(params, svcContext);
321 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
322 assertEquals(TestId, "test1");
326 public void reqExecCommand_shouldSetSuccessFileTxt() throws SvcLogicException,
327 IllegalStateException, IllegalArgumentException {
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");
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("250", status);
343 assertEquals(TestId, "txt");
347 public void reqExecCommand_shouldSetSuccessFileNoExtension() throws SvcLogicException,
348 IllegalStateException, IllegalArgumentException {
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");
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("250", status);
364 assertEquals(TestId, "txt");
368 public void reqExecCommand_shouldSetSuccessFileInvalidJson() throws SvcLogicException,
369 IllegalStateException, IllegalArgumentException {
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");
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("250", status);
387 @Test(expected = SvcLogicException.class)
388 public void reqExecCommand_shouldSetFailFileInvalidFile() throws SvcLogicException,
389 IllegalStateException, IllegalArgumentException {
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");
399 adapter.reqExecCommand(params, svcContext);
403 public void reqExecCommand_shouldSetSuccessFileJsonNoReqID() throws SvcLogicException,
404 IllegalStateException, IllegalArgumentException {
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");
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("250", status);
422 public void reqExecSLSFile_shouldSetSuccessJson() throws SvcLogicException,
423 IllegalStateException, IllegalArgumentException {
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");
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");
442 @Test(expected = SvcLogicException.class)
443 public void reqExecSLSFile_NoSLSfile() throws SvcLogicException,
444 IllegalStateException, IllegalArgumentException {
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");
455 adapter.reqExecSLSFile(params, svcContext);
456 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
457 assertEquals(TestId, "test1");
460 @Test(expected = SvcLogicException.class)
461 public void reqExecSLSFile_NoExtn() throws SvcLogicException,
462 IllegalStateException, IllegalArgumentException {
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");
473 adapter.reqExecSLSFile(params, svcContext);
474 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
475 assertEquals(TestId, "test1");
478 @Test(expected = SvcLogicException.class)
479 public void reqExecSLSFile_NoResponsefile() throws SvcLogicException,
480 IllegalStateException, IllegalArgumentException {
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");
491 adapter.reqExecSLSFile(params, svcContext);
492 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
493 assertEquals(TestId, "test1");
496 @Test(expected = SvcLogicException.class)
497 public void reqExecSLSFile_WithMinionSetNotSLSType() throws SvcLogicException,
498 IllegalStateException, IllegalArgumentException {
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("applyTo", "minion1");
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");
519 public void reqExecSLSFile_WithMinionSetSuccessSls() throws SvcLogicException,
520 IllegalStateException, IllegalArgumentException {
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("applyTo", "minion1");
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");
540 @Test(expected = SvcLogicException.class)
541 public void reqExecSLSFile_WithMinionNoSLSfile() throws SvcLogicException,
542 IllegalStateException, IllegalArgumentException {
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("applyTo", "minion1");
554 adapter.reqExecSLSFile(params, svcContext);
555 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
556 assertEquals(TestId, "test1");
559 @Test(expected = SvcLogicException.class)
560 public void reqExecSLSFile_WithMinionNoResponsefile() throws SvcLogicException,
561 IllegalStateException, IllegalArgumentException {
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("applyTo", "minion1");
573 adapter.reqExecSLSFile(params, svcContext);
574 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
575 assertEquals(TestId, "test1");
579 public void reqExecSLSFile_WithAllMinionSetSuccessJson() throws SvcLogicException,
580 IllegalStateException, IllegalArgumentException {
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("applyTo", "*");
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");
600 @Test(expected = SvcLogicException.class)
601 public void reqExecSLSFile_WithAllMinionNoSLSfile() throws SvcLogicException,
602 IllegalStateException, IllegalArgumentException {
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("applyTo", "*");
614 adapter.reqExecSLSFile(params, svcContext);
615 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
616 assertEquals(TestId, "test1");
619 @Test(expected = SvcLogicException.class)
620 public void reqExecSLSFile_WithAllMinionNoResponsefile() throws SvcLogicException,
621 IllegalStateException, IllegalArgumentException {
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("applyTo", "*");
633 adapter.reqExecSLSFile(params, svcContext);
634 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
635 assertEquals(TestId, "test1");
640 public void reqExecSLS_shouldSetSuccessJson() throws SvcLogicException,
641 IllegalStateException, IllegalArgumentException {
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");
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");
661 public void reqExecSLS_shouldSetNoExtn() throws SvcLogicException,
662 IllegalStateException, IllegalArgumentException {
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");
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");
681 @Test(expected = SvcLogicException.class)
682 public void reqExecSLS_NoResponsefile() throws SvcLogicException,
683 IllegalStateException, IllegalArgumentException {
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");
694 adapter.reqExecSLS(params, svcContext);
695 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
696 assertEquals(TestId, "test1");
701 public void reqExecSLS_WithMinionSetSuccessSls() throws SvcLogicException,
702 IllegalStateException, IllegalArgumentException {
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("applyTo", "minion1");
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");
723 @Test(expected = SvcLogicException.class)
724 public void reqExecSLS_WithMinionNoResponsefile() throws SvcLogicException,
725 IllegalStateException, IllegalArgumentException {
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("applyTo", "minion1");
737 adapter.reqExecSLS(params, svcContext);
738 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
739 assertEquals(TestId, "test1");
743 public void reqExecSLS_WithAllMinionSetSuccessJson() throws SvcLogicException,
744 IllegalStateException, IllegalArgumentException {
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("applyTo", "*");
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");
765 @Test(expected = SvcLogicException.class)
766 public void reqExecSLS_WithAllMinionNoResponsefile() throws SvcLogicException,
767 IllegalStateException, IllegalArgumentException {
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("applyTo", "*");
779 adapter.reqExecSLS(params, svcContext);
780 TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
781 assertEquals(TestId, "test1");
786 public void reqExecLog_shouldSetMessage() throws IllegalStateException, IllegalArgumentException {
788 params.put("Id", "101");
791 adapter.reqExecLog(params, svcContext);
792 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log");
793 //assertEquals(message, status);
794 assertEquals(null, status);
795 } catch (SvcLogicException e) {
796 String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.log");
797 fail(e.getMessage() + " Code = " + status);
798 } catch (Exception e) {
799 fail(e.getMessage() + " Unknown exception encountered ");