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("withRetry", "true");
 
 183         params.put("Cmd", "test");
 
 184         params.put("SlsExec", "false");
 
 186             adapter.reqExecCommand(params, svcContext);
 
 187             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 188             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 189             assertEquals("400", status);
 
 190         } catch (NullPointerException e) {
 
 191             fail(e.getMessage() + " Unknown exception encountered ");
 
 195     @Test(expected = SvcLogicException.class)
 
 196     public void reqExecCommand_NoResponseFileWithRetryZero() throws SvcLogicException,
 
 197             IllegalStateException, IllegalArgumentException {
 
 199         params.put("HostName", "test");
 
 200         params.put("Port", "10");
 
 201         params.put("User", "test");
 
 202         params.put("Password", "test");
 
 203         params.put("Test", "success");
 
 204         params.put("withRetry", "0");
 
 205         params.put("Cmd", "test");
 
 206         params.put("SlsExec", "false");
 
 208             adapter.reqExecCommand(params, svcContext);
 
 209             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 210             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 211             assertEquals("400", status);
 
 212         } catch (NullPointerException e) {
 
 213             fail(e.getMessage() + " Unknown exception encountered ");
 
 217     @Test(expected = SvcLogicException.class)
 
 218     public void reqExecCommand_NoResponseFileWithNoRetry() throws SvcLogicException,
 
 219             IllegalStateException, IllegalArgumentException {
 
 221         params.put("HostName", "test");
 
 222         params.put("Port", "10");
 
 223         params.put("User", "test");
 
 224         params.put("Password", "test");
 
 225         params.put("Test", "success");
 
 226         params.put("withRetry", "false");
 
 227         params.put("Cmd", "test");
 
 228         params.put("SlsExec", "false");
 
 231             adapter.reqExecCommand(params, svcContext);
 
 232             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 233             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 234             assertEquals("400", status);
 
 235         } catch (NullPointerException e) {
 
 236             fail(e.getMessage() + " Unknown exception encountered ");
 
 240     @Test(expected = SvcLogicException.class)
 
 241     public void reqExecCommand_shouldSetFailure() throws SvcLogicException,
 
 242             IllegalStateException, IllegalArgumentException {
 
 244         params.put("HostName", "test");
 
 245         params.put("Port", "10");
 
 246         params.put("User", "test");
 
 247         params.put("Password", "test");
 
 248         params.put("Cmd", "test");
 
 249         params.put("SlsExec", "test");
 
 250         params.put("Test", "fail");
 
 252             adapter.reqExecCommand(params, svcContext);
 
 253             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 254             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 255             assertEquals("400", status);
 
 256         } catch (NullPointerException e) {
 
 257             fail(e.getMessage() + " Unknown exception encountered ");
 
 262     public void reqExecCommand_shouldSetSuccessNoSLS() throws SvcLogicException,
 
 263             IllegalStateException, IllegalArgumentException {
 
 265         params.put("HostName", "test");
 
 266         params.put("Port", "10");
 
 267         params.put("User", "test");
 
 268         params.put("Password", "test");
 
 269         params.put("Test", "success");
 
 270         params.put("fileName", "src/test/resources/test.json");
 
 271         params.put("Id", "test1");
 
 272         params.put("Cmd", "test");
 
 273         params.put("SlsExec", "false");
 
 275         adapter.reqExecCommand(params, svcContext);
 
 276         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 277         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 278         assertEquals("200", status);
 
 279         assertEquals(TestId, "test1");
 
 283     public void reqExecCommand_shouldSetSuccessExecSLS() throws SvcLogicException,
 
 284             IllegalStateException, IllegalArgumentException {
 
 286         params.put("HostName", "test");
 
 287         params.put("Port", "10");
 
 288         params.put("User", "test");
 
 289         params.put("Password", "test");
 
 290         params.put("Test", "success");
 
 291         params.put("fileName", "src/test/resources/test-sls.json");
 
 292         params.put("Id", "test1");
 
 293         params.put("Cmd", "test");
 
 294         params.put("SlsExec", "true");
 
 296         adapter.reqExecCommand(params, svcContext);
 
 297         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 298         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 299         assertEquals("200", status);
 
 300         assertEquals(TestId, "test1");
 
 303     @Test(expected = SvcLogicException.class)
 
 304     public void reqExecCommand_shouldSetFailExecSLS() throws SvcLogicException,
 
 305             IllegalStateException, IllegalArgumentException {
 
 307         params.put("HostName", "test");
 
 308         params.put("Port", "10");
 
 309         params.put("User", "test");
 
 310         params.put("Password", "test");
 
 311         params.put("Test", "success");
 
 312         params.put("fileName", "src/test/resources/test.json");
 
 313         params.put("Id", "test1");
 
 314         params.put("Cmd", "test");
 
 315         params.put("SlsExec", "true");
 
 317         adapter.reqExecCommand(params, svcContext);
 
 318         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 319         assertEquals(TestId, "test1");
 
 323     public void reqExecCommand_shouldSetSuccessFileTxt() throws SvcLogicException,
 
 324             IllegalStateException, IllegalArgumentException {
 
 326         params.put("HostName", "test");
 
 327         params.put("Port", "10");
 
 328         params.put("User", "test");
 
 329         params.put("Password", "test");
 
 330         params.put("Test", "success");
 
 331         params.put("fileName", "src/test/resources/test.txt");
 
 332         params.put("Id", "txt");
 
 333         params.put("Cmd", "test");
 
 334         params.put("SlsExec", "false");
 
 336         adapter.reqExecCommand(params, svcContext);
 
 337         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 338         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 339         assertEquals("200", status);
 
 340         assertEquals(TestId, "txt");
 
 344     public void reqExecCommand_shouldSetSuccessFileNoExtension() throws SvcLogicException,
 
 345             IllegalStateException, IllegalArgumentException {
 
 347         params.put("HostName", "test");
 
 348         params.put("Port", "10");
 
 349         params.put("User", "test");
 
 350         params.put("Password", "test");
 
 351         params.put("Test", "success");
 
 352         params.put("fileName", "src/test/resources/test");
 
 353         params.put("Id", "txt");
 
 354         params.put("Cmd", "test");
 
 355         params.put("SlsExec", "false");
 
 357         adapter.reqExecCommand(params, svcContext);
 
 358         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 359         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 360         assertEquals("200", status);
 
 361         assertEquals(TestId, "txt");
 
 365     public void reqExecCommand_shouldSetSuccessFileInvalidJson() throws SvcLogicException,
 
 366             IllegalStateException, IllegalArgumentException {
 
 368         params.put("HostName", "test");
 
 369         params.put("Port", "10");
 
 370         params.put("User", "test");
 
 371         params.put("Password", "test");
 
 372         params.put("Test", "success");
 
 373         params.put("fileName", "src/test/resources/test-invalid.json");
 
 374         params.put("Id", "test1");
 
 375         params.put("Cmd", "test");
 
 376         params.put("SlsExec", "false");
 
 378         adapter.reqExecCommand(params, svcContext);
 
 379         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 380         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 381         assertEquals("200", status);
 
 384     @Test(expected = SvcLogicException.class)
 
 385     public void reqExecCommand_shouldSetFailFileInvalidFile() throws SvcLogicException,
 
 386             IllegalStateException, IllegalArgumentException {
 
 388         params.put("HostName", "test");
 
 389         params.put("Port", "10");
 
 390         params.put("User", "test");
 
 391         params.put("Password", "test");
 
 392         params.put("Test", "success");
 
 393         params.put("fileName", "src/test/resources/test-none.json");
 
 394         params.put("Id", "test1");
 
 396         adapter.reqExecCommand(params, svcContext);
 
 400     public void reqExecCommand_shouldSetSuccessFileJsonNoReqID() throws SvcLogicException,
 
 401             IllegalStateException, IllegalArgumentException {
 
 403         params.put("HostName", "test");
 
 404         params.put("Port", "10");
 
 405         params.put("User", "test");
 
 406         params.put("Password", "test");
 
 407         params.put("Test", "success");
 
 408         params.put("fileName", "src/test/resources/test.json");
 
 409         params.put("Cmd", "test");
 
 410         params.put("SlsExec", "false");
 
 412         adapter.reqExecCommand(params, svcContext);
 
 413         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 414         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 415         assertEquals("200", status);
 
 419     public void reqExecSLSFile_shouldSetSuccessJson() throws SvcLogicException,
 
 420             IllegalStateException, IllegalArgumentException {
 
 422         params.put("HostName", "test");
 
 423         params.put("Port", "10");
 
 424         params.put("User", "test");
 
 425         params.put("Password", "test");
 
 426         params.put("Test", "success");
 
 427         params.put("SlsFile", "src/test/resources/test.sls");
 
 428         params.put("fileName", "src/test/resources/test-sls.json");
 
 429         params.put("Id", "test1");
 
 430         params.put("Cmd", "test");
 
 432         adapter.reqExecSLSFile(params, svcContext);
 
 433         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 434         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 435         assertEquals("200", status);
 
 436         assertEquals(TestId, "test1");
 
 439     @Test(expected = SvcLogicException.class)
 
 440     public void reqExecSLSFile_NoSLSfile() throws SvcLogicException,
 
 441             IllegalStateException, IllegalArgumentException {
 
 443         params.put("HostName", "test");
 
 444         params.put("Port", "10");
 
 445         params.put("User", "test");
 
 446         params.put("Password", "test");
 
 447         params.put("Test", "success");
 
 448         params.put("SlsFile", "src/test/resources/test-none.sls");
 
 449         params.put("fileName", "src/test/resources/test-sls.json");
 
 450         params.put("Id", "test1");
 
 452         adapter.reqExecSLSFile(params, svcContext);
 
 453         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 454         assertEquals(TestId, "test1");
 
 457     @Test(expected = SvcLogicException.class)
 
 458     public void reqExecSLSFile_NoExtn() throws SvcLogicException,
 
 459             IllegalStateException, IllegalArgumentException {
 
 461         params.put("HostName", "test");
 
 462         params.put("Port", "10");
 
 463         params.put("User", "test");
 
 464         params.put("Password", "test");
 
 465         params.put("Test", "success");
 
 466         params.put("SlsFile", "src/test/resources/test-none");
 
 467         params.put("fileName", "src/test/resources/test-sls.json");
 
 468         params.put("Id", "test1");
 
 470         adapter.reqExecSLSFile(params, svcContext);
 
 471         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 472         assertEquals(TestId, "test1");
 
 475     @Test(expected = SvcLogicException.class)
 
 476     public void reqExecSLSFile_NoResponsefile() throws SvcLogicException,
 
 477             IllegalStateException, IllegalArgumentException {
 
 479         params.put("HostName", "test");
 
 480         params.put("Port", "10");
 
 481         params.put("User", "test");
 
 482         params.put("Password", "test");
 
 483         params.put("Test", "success");
 
 484         params.put("SlsFile", "src/test/resources/test.json");
 
 485         params.put("fileName", "src/test/resources/test-none.json");
 
 486         params.put("Id", "test1");
 
 488         adapter.reqExecSLSFile(params, svcContext);
 
 489         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 490         assertEquals(TestId, "test1");
 
 493     @Test(expected = SvcLogicException.class)
 
 494     public void reqExecSLSFile_WithMinionSetNotSLSType() throws SvcLogicException,
 
 495             IllegalStateException, IllegalArgumentException {
 
 497         params.put("HostName", "test");
 
 498         params.put("Port", "10");
 
 499         params.put("User", "test");
 
 500         params.put("Password", "test");
 
 501         params.put("Test", "success");
 
 502         params.put("SlsFile", "src/test/resources/test.json");
 
 503         params.put("fileName", "src/test/resources/test-sls.json");
 
 504         params.put("Id", "test1");
 
 505         params.put("Cmd", "test");
 
 506         params.put("NodeList", "minion1");
 
 508         adapter.reqExecSLSFile(params, svcContext);
 
 509         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 510         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 511         assertEquals("200", status);
 
 512         assertEquals(TestId, "test1");
 
 516     public void reqExecSLSFile_WithMinionSetSuccessSls() throws SvcLogicException,
 
 517             IllegalStateException, IllegalArgumentException {
 
 519         params.put("HostName", "test");
 
 520         params.put("Port", "10");
 
 521         params.put("User", "test");
 
 522         params.put("Password", "test");
 
 523         params.put("Test", "success");
 
 524         params.put("SlsFile", "src/test/resources/test.sls");
 
 525         params.put("fileName", "src/test/resources/test-sls.json");
 
 526         params.put("Id", "test1");
 
 527         params.put("Cmd", "test");
 
 528         params.put("NodeList", "minion1");
 
 530         adapter.reqExecSLSFile(params, svcContext);
 
 531         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 532         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 533         assertEquals("200", status);
 
 534         assertEquals(TestId, "test1");
 
 537     @Test(expected = SvcLogicException.class)
 
 538     public void reqExecSLSFile_WithMinionNoSLSfile() throws SvcLogicException,
 
 539             IllegalStateException, IllegalArgumentException {
 
 541         params.put("HostName", "test");
 
 542         params.put("Port", "10");
 
 543         params.put("User", "test");
 
 544         params.put("Password", "test");
 
 545         params.put("Test", "success");
 
 546         params.put("SlsFile", "src/test/resources/test-none.json");
 
 547         params.put("fileName", "src/test/resources/test-sls.json");
 
 548         params.put("Id", "test1");
 
 549         params.put("NodeList", "minion1");
 
 551         adapter.reqExecSLSFile(params, svcContext);
 
 552         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 553         assertEquals(TestId, "test1");
 
 556     @Test(expected = SvcLogicException.class)
 
 557     public void reqExecSLSFile_WithMinionNoResponsefile() throws SvcLogicException,
 
 558             IllegalStateException, IllegalArgumentException {
 
 560         params.put("HostName", "test");
 
 561         params.put("Port", "10");
 
 562         params.put("User", "test");
 
 563         params.put("Password", "test");
 
 564         params.put("Test", "success");
 
 565         params.put("SlsFile", "src/test/resources/test.json");
 
 566         params.put("fileName", "src/test/resources/test-none.json");
 
 567         params.put("Id", "test1");
 
 568         params.put("NodeList", "minion1");
 
 570         adapter.reqExecSLSFile(params, svcContext);
 
 571         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 572         assertEquals(TestId, "test1");
 
 576     public void reqExecSLSFile_WithAllMinionSetSuccessJson() throws SvcLogicException,
 
 577             IllegalStateException, IllegalArgumentException {
 
 579         params.put("HostName", "test");
 
 580         params.put("Port", "10");
 
 581         params.put("User", "test");
 
 582         params.put("Password", "test");
 
 583         params.put("Test", "success");
 
 584         params.put("SlsFile", "src/test/resources/test.sls");
 
 585         params.put("fileName", "src/test/resources/test-sls.json");
 
 586         params.put("Id", "test1");
 
 587         params.put("Cmd", "test");
 
 588         params.put("NodeList", "*");
 
 590         adapter.reqExecSLSFile(params, svcContext);
 
 591         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 592         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 593         assertEquals("200", status);
 
 594         assertEquals(TestId, "test1");
 
 597     @Test(expected = SvcLogicException.class)
 
 598     public void reqExecSLSFile_WithAllMinionNoSLSfile() throws SvcLogicException,
 
 599             IllegalStateException, IllegalArgumentException {
 
 601         params.put("HostName", "test");
 
 602         params.put("Port", "10");
 
 603         params.put("User", "test");
 
 604         params.put("Password", "test");
 
 605         params.put("Test", "success");
 
 606         params.put("SlsFile", "src/test/resources/test-none.json");
 
 607         params.put("fileName", "src/test/resources/test-sls.json");
 
 608         params.put("Id", "test1");
 
 609         params.put("NodeList", "*");
 
 611         adapter.reqExecSLSFile(params, svcContext);
 
 612         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 613         assertEquals(TestId, "test1");
 
 616     @Test(expected = SvcLogicException.class)
 
 617     public void reqExecSLSFile_WithAllMinionNoResponsefile() throws SvcLogicException,
 
 618             IllegalStateException, IllegalArgumentException {
 
 620         params.put("HostName", "test");
 
 621         params.put("Port", "10");
 
 622         params.put("User", "test");
 
 623         params.put("Password", "test");
 
 624         params.put("Test", "success");
 
 625         params.put("SlsFile", "src/test/resources/test.json");
 
 626         params.put("fileName", "src/test/resources/test-none.json");
 
 627         params.put("Id", "test1");
 
 628         params.put("NodeList", "*");
 
 630         adapter.reqExecSLSFile(params, svcContext);
 
 631         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 632         assertEquals(TestId, "test1");
 
 637     public void reqExecSLS_shouldSetSuccessJson() throws SvcLogicException,
 
 638             IllegalStateException, IllegalArgumentException {
 
 640         params.put("HostName", "test");
 
 641         params.put("Port", "10");
 
 642         params.put("User", "test");
 
 643         params.put("Password", "test");
 
 644         params.put("Test", "success");
 
 645         params.put("SlsName", "src/test.sls");
 
 646         params.put("fileName", "src/test/resources/test-sls.json");
 
 647         params.put("Id", "test1");
 
 648         params.put("Cmd", "test");
 
 650         adapter.reqExecSLS(params, svcContext);
 
 651         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 652         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 653         assertEquals("200", status);
 
 654         assertEquals(TestId, "test1");
 
 658     public void reqExecSLS_shouldSetNoExtn() throws SvcLogicException,
 
 659             IllegalStateException, IllegalArgumentException {
 
 661         params.put("HostName", "test");
 
 662         params.put("Port", "10");
 
 663         params.put("User", "test");
 
 664         params.put("Password", "test");
 
 665         params.put("Test", "success");
 
 666         params.put("SlsName", "src/test");
 
 667         params.put("fileName", "src/test/resources/test-sls.json");
 
 668         params.put("Id", "test1");
 
 669         params.put("Cmd", "test");
 
 671         adapter.reqExecSLS(params, svcContext);
 
 672         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 673         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 674         assertEquals("200", status);
 
 675         assertEquals(TestId, "test1");
 
 678     @Test(expected = SvcLogicException.class)
 
 679     public void reqExecSLS_NoResponsefile() throws SvcLogicException,
 
 680             IllegalStateException, IllegalArgumentException {
 
 682         params.put("HostName", "test");
 
 683         params.put("Port", "10");
 
 684         params.put("User", "test");
 
 685         params.put("Password", "test");
 
 686         params.put("Test", "success");
 
 687         params.put("SlsName", "src/test/resources/test.json");
 
 688         params.put("fileName", "src/test/resources/test-none.json");
 
 689         params.put("Id", "test1");
 
 691         adapter.reqExecSLS(params, svcContext);
 
 692         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 693         assertEquals(TestId, "test1");
 
 698     public void reqExecSLS_WithMinionSetSuccessSls() throws SvcLogicException,
 
 699             IllegalStateException, IllegalArgumentException {
 
 701         params.put("HostName", "test");
 
 702         params.put("Port", "10");
 
 703         params.put("User", "test");
 
 704         params.put("Password", "test");
 
 705         params.put("Test", "success");
 
 706         params.put("SlsName", "src/test/resources/test.sls");
 
 707         params.put("fileName", "src/test/resources/test-sls.json");
 
 708         params.put("Id", "test1");
 
 709         params.put("Cmd", "test");
 
 710         params.put("NodeList", "minion1");
 
 712         adapter.reqExecSLS(params, svcContext);
 
 713         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 714         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 715         assertEquals("200", status);
 
 716         assertEquals(TestId, "test1");
 
 720     @Test(expected = SvcLogicException.class)
 
 721     public void reqExecSLS_WithMinionNoResponsefile() throws SvcLogicException,
 
 722             IllegalStateException, IllegalArgumentException {
 
 724         params.put("HostName", "test");
 
 725         params.put("Port", "10");
 
 726         params.put("User", "test");
 
 727         params.put("Password", "test");
 
 728         params.put("Test", "success");
 
 729         params.put("SlsName", "src/test/resources/test.json");
 
 730         params.put("fileName", "src/test/resources/test-none.json");
 
 731         params.put("Id", "test1");
 
 732         params.put("NodeList", "minion1");
 
 734         adapter.reqExecSLS(params, svcContext);
 
 735         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 736         assertEquals(TestId, "test1");
 
 740     public void reqExecSLS_WithAllMinionSetSuccessJson() throws SvcLogicException,
 
 741             IllegalStateException, IllegalArgumentException {
 
 743         params.put("HostName", "test");
 
 744         params.put("Port", "10");
 
 745         params.put("User", "test");
 
 746         params.put("Password", "test");
 
 747         params.put("Test", "success");
 
 748         params.put("SlsName", "src/test/resources/test.sls");
 
 749         params.put("fileName", "src/test/resources/test-sls.json");
 
 750         params.put("Id", "test1");
 
 751         params.put("Cmd", "test");
 
 752         params.put("NodeList", "*");
 
 754         adapter.reqExecSLS(params, svcContext);
 
 755         String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 756         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 757         assertEquals("200", status);
 
 758         assertEquals(TestId, "test1");
 
 762     @Test(expected = SvcLogicException.class)
 
 763     public void reqExecSLS_WithAllMinionNoResponsefile() throws SvcLogicException,
 
 764             IllegalStateException, IllegalArgumentException {
 
 766         params.put("HostName", "test");
 
 767         params.put("Port", "10");
 
 768         params.put("User", "test");
 
 769         params.put("Password", "test");
 
 770         params.put("Test", "success");
 
 771         params.put("SlsName", "src/test/resources/test.json");
 
 772         params.put("fileName", "src/test/resources/test-none.json");
 
 773         params.put("Id", "test1");
 
 774         params.put("NodeList", "*");
 
 776         adapter.reqExecSLS(params, svcContext);
 
 777         TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 778         assertEquals(TestId, "test1");
 
 783     public void reqExecCommand_shouldSetSuccessReal() throws SvcLogicException,
 
 784             IllegalStateException, IllegalArgumentException {
 
 786         params.put("HostName", "127.0.0.1");
 
 787         params.put("Port", "22");
 
 788         params.put("User", "sdn");
 
 789         params.put("Password", "foo");
 
 790         params.put("Id", "test1");
 
 791         params.put("Cmd", "ls -l");
 
 792         params.put("SlsExec", "false");
 
 793         params.put("Timeout", "120");
 
 794         adapter = new SaltstackAdapterImpl();
 
 796             adapter.reqExecCommand(params, svcContext);
 
 797             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 798             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 799             assertEquals("200", status);
 
 800             assertEquals(TestId, "test1");
 
 801         } catch (Exception e) {
 
 802             //if local ssh is not enabled
 
 803             System.out.print(e.getMessage());
 
 808     public void reqExecCommand_shouldSetSuccessRealSLSCommand() throws SvcLogicException,
 
 809             IllegalStateException, IllegalArgumentException {
 
 811         params.put("HostName", "<IP>");
 
 812         params.put("Port", "2222");
 
 813         params.put("User", "root");
 
 814         params.put("Password", "vagrant");
 
 815         params.put("Id", "test1");
 
 816         params.put("Cmd", "salt '*' test.ping --out=json --static");
 
 817         params.put("SlsExec", "false");
 
 818         params.put("Timeout", "120");
 
 820         adapter = new SaltstackAdapterImpl();
 
 822             adapter.reqExecCommand(params, svcContext);
 
 823             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 824             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 825             assertEquals("200", status);
 
 826             assertEquals(TestId, "test1");
 
 827             TestId = svcContext.getAttribute("test1.minion1");
 
 828             assertEquals(TestId, "true");
 
 829         } catch (Exception e) {
 
 830             //if saltstack ssh IP is not enabled
 
 831             System.out.print(e.getMessage());
 
 836     public void reqExecCommand_shouldSetSuccessRealCommand() throws SvcLogicException,
 
 837             IllegalStateException, IllegalArgumentException {
 
 839         params.put("HostName", "<IP>");
 
 840         params.put("Port", "2222");
 
 841         params.put("User", "root");
 
 842         params.put("Password", "vagrant");
 
 843         params.put("Id", "test1");
 
 844         params.put("Cmd", "cd /srv/salt/; salt '*' state.apply vim --out=json --static");
 
 845         params.put("SlsExec", "true");
 
 846         params.put("Timeout", "120");
 
 848         adapter = new SaltstackAdapterImpl();
 
 850             adapter.reqExecCommand(params, svcContext);
 
 851             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 852             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 853             assertEquals("200", status);
 
 854             assertEquals(TestId, "test1");
 
 855         } catch (Exception e) {
 
 856             //if saltstack ssh IP is not enabled
 
 857             System.out.print(e.getMessage());
 
 862     public void reqExecCommand_shouldSetSuccessRealSSL() throws SvcLogicException,
 
 863             IllegalStateException, IllegalArgumentException {
 
 865         params.put("HostName", "<IP>");
 
 866         params.put("Port", "2222");
 
 867         params.put("User", "root");
 
 868         params.put("Password", "vagrant");
 
 869         params.put("Id", "test1");
 
 870         params.put("SlsName", "vim");
 
 871         params.put("Timeout", "120");
 
 872         params.put("NodeList", "minion1");
 
 874         adapter = new SaltstackAdapterImpl();
 
 876             adapter.reqExecSLS(params, svcContext);
 
 877             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 878             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 879             assertEquals("200", status);
 
 880             assertEquals(TestId, "test1");
 
 881         } catch (Exception e) {
 
 882             //if saltstack ssh IP is not enabled
 
 883             System.out.print(e.getMessage());
 
 888     public void reqExecCommand_shouldSetSuccessEnvParam() throws SvcLogicException,
 
 889             IllegalStateException, IllegalArgumentException {
 
 891         params.put("HostName", "<IP>");
 
 892         params.put("Port", "2222");
 
 893         params.put("User", "root");
 
 894         params.put("Password", "vagrant");
 
 895         params.put("Id", "test1");
 
 896         params.put("SlsName", "vim");
 
 897         params.put("Timeout", "120");
 
 898         params.put("NodeList", "minion1");
 
 899         params.put("EnvParameters", "{\"exclude\": bar*}");
 
 901         adapter = new SaltstackAdapterImpl();
 
 903             adapter.reqExecSLS(params, svcContext);
 
 904             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 905             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 906             assertEquals("200", status);
 
 907             assertEquals(TestId, "test1");
 
 908         } catch (Exception e) {
 
 909             //if saltstack ssh IP is not enabled
 
 910             System.out.print(e.getMessage());
 
 915     public void reqExecCommand_shouldSetSuccessFileParam() throws SvcLogicException,
 
 916             IllegalStateException, IllegalArgumentException {
 
 918         params.put("HostName", "<IP>");
 
 919         params.put("Port", "2222");
 
 920         params.put("User", "root");
 
 921         params.put("Password", "vagrant");
 
 922         params.put("Id", "test1");
 
 923         params.put("SlsName", "vim");
 
 924         params.put("Timeout", "120");
 
 925         params.put("NodeList", "minion1");
 
 926         params.put("EnvParameters", "{\"exclude\": \"bar,baz\"}");
 
 927         params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
 
 929         adapter = new SaltstackAdapterImpl();
 
 931             adapter.reqExecSLS(params, svcContext);
 
 932             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 933             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 934             assertEquals("200", status);
 
 935             assertEquals(TestId, "test1");
 
 936         } catch (Exception e) {
 
 937             //if saltstack ssh IP is not enabled
 
 938             System.out.print(e.getMessage());
 
 943     public void reqExecCommand_shouldSetSuccessPillarParam() throws SvcLogicException,
 
 944             IllegalStateException, IllegalArgumentException {
 
 946         params.put("HostName", "<IP>");
 
 947         params.put("Port", "2222");
 
 948         params.put("User", "root");
 
 949         params.put("Password", "vagrant");
 
 950         params.put("Id", "test1");
 
 951         params.put("SlsName", "vim");
 
 952         params.put("Timeout", "120");
 
 953         params.put("NodeList", "minion1");
 
 954         params.put("EnvParameters", "{\"exclude\": \"bar,baz\", \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
 
 955         params.put("FileParameters", "{\"config.txt\":\"db_ip=10.1.1.1, sip_timer=10000\"}");
 
 957         adapter = new SaltstackAdapterImpl();
 
 959             adapter.reqExecSLS(params, svcContext);
 
 960             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 961             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 962             assertEquals("200", status);
 
 963             assertEquals(TestId, "test1");
 
 964         } catch (Exception e) {
 
 965             //if saltstack ssh IP is not enabled
 
 966             System.out.print(e.getMessage());
 
 971     public void reqExecCommand_shouldSetSuccessMultiFileParam() throws SvcLogicException,
 
 972             IllegalStateException, IllegalArgumentException {
 
 974         params.put("HostName", "<IP>");
 
 975         params.put("Port", "2222");
 
 976         params.put("User", "root");
 
 977         params.put("Password", "vagrant");
 
 978         params.put("Id", "test1");
 
 979         params.put("SlsName", "vim");
 
 980         params.put("Timeout", "120");
 
 981         params.put("NodeList", "minion1");
 
 982         params.put("EnvParameters", "{\"exclude\": bar*}");
 
 983         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\"}");
 
 985         adapter = new SaltstackAdapterImpl();
 
 987             adapter.reqExecSLS(params, svcContext);
 
 988             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
 989             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
 990             assertEquals("200", status);
 
 991             assertEquals(TestId, "test1");
 
 992         } catch (Exception e) {
 
 993             //if saltstack ssh IP is not enabled
 
 994             System.out.print(e.getMessage());
 
 999     public void reqExecCommand_shouldSetSuccessSSLFile() throws SvcLogicException,
 
1000             IllegalStateException, IllegalArgumentException {
 
1002         params.put("HostName", "<IP>");
 
1003         params.put("Port", "2222");
 
1004         params.put("User", "root");
 
1005         params.put("Password", "vagrant");
 
1006         params.put("Id", "test1");
 
1007         params.put("Timeout", "120");
 
1008         params.put("NodeList", "minion1");
 
1009         params.put("SlsFile", "src/test/resources/config.sls");
 
1011         adapter = new SaltstackAdapterImpl();
 
1013             adapter.reqExecSLSFile(params, svcContext);
 
1014             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
1015             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
1016             assertEquals("200", status);
 
1017             assertEquals(TestId, "test1");
 
1018         } catch (Exception e) {
 
1019             //if saltstack ssh IP is not enabled
 
1020             System.out.print(e.getMessage());
 
1025     public void reqExecCommand_shouldSetSuccessSSLFileMultiFileParam() throws SvcLogicException,
 
1026             IllegalStateException, IllegalArgumentException {
 
1028         params.put("HostName", "<IP>");
 
1029         params.put("Port", "2222");
 
1030         params.put("User", "root");
 
1031         params.put("Password", "vagrant");
 
1032         params.put("Id", "test1");
 
1033         params.put("Timeout", "120");
 
1034         params.put("NodeList", "minion1");
 
1035         params.put("SlsFile", "src/test/resources/config.sls");
 
1036         params.put("EnvParameters", "{\"exclude\": bar, \"pillar\":\"'{\\\"foo\\\": \\\"bar\\\"}'\"}");
 
1037         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\"}");
 
1039         adapter = new SaltstackAdapterImpl();
 
1041             adapter.reqExecSLSFile(params, svcContext);
 
1042             String status = svcContext.getAttribute("org.onap.appc.adapter.saltstack.result.code");
 
1043             TestId = svcContext.getAttribute("org.onap.appc.adapter.saltstack.Id");
 
1044             assertEquals("200", status);
 
1045             assertEquals(TestId, "test1");
 
1046         } catch (Exception e) {
 
1047             //if saltstack ssh IP is not enabled
 
1048             System.out.print(e.getMessage());