2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2018 Samsung Electronics. All rights reserved.
 
   6  * ================================================================================
 
   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.
 
  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("200", 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("200", 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("200", 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("200", 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("200", 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("NodeList", "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("NodeList", "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("NodeList", "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("NodeList", "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("NodeList", "*");
 
 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("NodeList", "*");
 
 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("NodeList", "*");
 
 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("NodeList", "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("NodeList", "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("NodeList", "*");
 
 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("NodeList", "*");
 
 779         adapter.reqExecSLS(params, svcContext);
 
 780         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 781         assertEquals(TestId, "test1");
 
 786     public void reqExecCommand_shouldSetSuccessReal() throws SvcLogicException,
 
 787             IllegalStateException, IllegalArgumentException {
 
 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();
 
 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());
 
 811     public void reqExecCommand_shouldSetSuccessRealSLSCommand() throws SvcLogicException,
 
 812             IllegalStateException, IllegalArgumentException {
 
 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");
 
 823         adapter = new SaltstackAdapterImpl();
 
 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());
 
 839     public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException,
 
 840             IllegalStateException, IllegalArgumentException {
 
 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");
 
 851         adapter = new SaltstackAdapterImpl();
 
 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());
 
 865     public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException,
 
 866             IllegalStateException, IllegalArgumentException {
 
 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");
 
 877         adapter = new SaltstackAdapterImpl();
 
 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());
 
 891     public void reqExecCommand_shouldSetSuccessEnvParam() throws SvcLogicException,
 
 892             IllegalStateException, IllegalArgumentException {
 
 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*}");
 
 904         adapter = new SaltstackAdapterImpl();
 
 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());
 
 918     public void reqExecCommand_shouldSetSuccessFileParam() throws SvcLogicException,
 
 919             IllegalStateException, IllegalArgumentException {
 
 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\"}");
 
 932         adapter = new SaltstackAdapterImpl();
 
 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());
 
 946     public void reqExecCommand_shouldSetSuccessPillarParam() throws SvcLogicException,
 
 947             IllegalStateException, IllegalArgumentException {
 
 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\"}");
 
 960         adapter = new SaltstackAdapterImpl();
 
 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());
 
 974     public void reqExecCommand_shouldSetSuccessMultiFileParam() throws SvcLogicException,
 
 975             IllegalStateException, IllegalArgumentException {
 
 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\"}");
 
 988         adapter = new SaltstackAdapterImpl();
 
 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());
 
1002     public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException,
 
1003             IllegalStateException, IllegalArgumentException {
 
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");
 
1014         adapter = new SaltstackAdapterImpl();
 
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());
 
1028     public void reqExecCommand_shouldSetSuccessSSLFileMultiFileParam() throws SvcLogicException,
 
1029             IllegalStateException, IllegalArgumentException {
 
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\"}");
 
1042         adapter = new SaltstackAdapterImpl();
 
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());