2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ================================================================================
 
   7  * Copyright (C) 2017 Amdocs
 
   8  * =============================================================================
 
   9  * Licensed under the Apache License, Version 2.0 (the "License");
 
  10  * you may not use this file except in compliance with the License.
 
  11  * You may obtain a copy of the License at
 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
 
  15  * Unless required by applicable law or agreed to in writing, software
 
  16  * distributed under the License is distributed on an "AS IS" BASIS,
 
  17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  18  * See the License for the specific language governing permissions and
 
  19  * limitations under the License.
 
  21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  22  * ============LICENSE_END=========================================================
 
  25 package org.onap.appc.adapter.ansible.impl;
 
  27 import static org.junit.Assert.assertEquals;
 
  28 import static org.junit.Assert.fail;
 
  30 import java.util.HashMap;
 
  33 import org.junit.After;
 
  34 import org.junit.Before;
 
  35 import org.junit.Test;
 
  36 import org.onap.ccsdk.sli.adaptors.ansible.impl.AnsibleAdapterImpl;
 
  37 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  38 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  41 public class TestAnsibleAdapterImpl {
 
  43     private final String PENDING = "100";
 
  44     private final String SUCCESS = "400";
 
  45     private String message = "{\"Results\":{\"192.168.1.10\":{\"Id\":\"101\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"}},\"StatusCode\":200,\"StatusMessage\":\"FINISHED\"}";
 
  47     private AnsibleAdapterImpl adapter;
 
  48     private String TestId;
 
  49     private boolean testMode = true;
 
  50     private Map<String, String> params;
 
  51     private SvcLogicContext svcContext;
 
  55     public void setup() throws IllegalArgumentException {
 
  57         svcContext = new SvcLogicContext();
 
  58         adapter = new AnsibleAdapterImpl(testMode);
 
  60         params = new HashMap<>();
 
  61         params.put("AgentUrl", "https://192.168.1.1");
 
  62         params.put("User", "test");
 
  63         params.put("Password", "test");
 
  67     public void tearDown() {
 
  75     public void reqExec_shouldSetPending() throws IllegalStateException, IllegalArgumentException {
 
  77         params.put("PlaybookName", "test_playbook.yaml");
 
  80             adapter.reqExec(params, svcContext);
 
  81             String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
 
  82             TestId = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.Id");
 
  83             System.out.println("Comparing " + PENDING + " and " + status);
 
  84             assertEquals(PENDING, status);
 
  85         } catch (SvcLogicException e) {
 
  86             String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
 
  87             fail(e.getMessage() + " Code = " + status);
 
  88         } catch (Exception e) {
 
  89             fail(e.getMessage() + " Unknown exception encountered ");
 
  94     public void reqExecResult_shouldSetSuccess() throws IllegalStateException, IllegalArgumentException {
 
  96         params.put("Id", "100");
 
  98         for (String ukey : params.keySet()) {
 
  99             System.out.println(String.format("Ansible Parameter %s = %s", ukey, params.get(ukey)));
 
 103             adapter.reqExecResult(params, svcContext);
 
 104             String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
 
 105             assertEquals(SUCCESS, status);
 
 106         } catch (SvcLogicException e) {
 
 107             String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
 
 108             fail(e.getMessage() + " Code = " + status);
 
 109         } catch (Exception e) {
 
 110             fail(e.getMessage() + " Unknown exception encountered ");
 
 115     public void reqExecLog_shouldSetMessage() throws IllegalStateException, IllegalArgumentException {
 
 117         params.put("Id", "101");
 
 120             adapter.reqExecLog(params, svcContext);
 
 121             String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.log");
 
 122             assertEquals(message, status);
 
 123         } catch (SvcLogicException e) {
 
 124             String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.log");
 
 125             fail(e.getMessage() + " Code = " + status);
 
 126         } catch (Exception e) {
 
 127             fail(e.getMessage() + " Unknown exception encountered ");