2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.adapter.ansible.impl;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.fail;
29 import java.util.HashMap;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
37 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 public class TestAnsibleAdapterImpl {
42 private final String PENDING = "100";
43 private final String SUCCESS = "400";
44 private String message = "{\"Results\":{\"192.168.1.10\":{\"Id\":\"101\",\"StatusCode\":200,\"StatusMessage\":\"SUCCESS\"}},\"StatusCode\":200,\"StatusMessage\":\"FINISHED\"}";
46 private AnsibleAdapterImpl adapter;
47 private String TestId;
48 private boolean testMode = true;
49 private Map<String, String> params;
50 private SvcLogicContext svcContext;
54 public void setup() throws IllegalArgumentException {
56 svcContext = new SvcLogicContext();
57 adapter = new AnsibleAdapterImpl(testMode);
59 params = new HashMap<>();
60 params.put("AgentUrl", "https://192.168.1.1");
61 params.put("User", "test");
62 params.put("Password", "test");
66 public void tearDown() {
74 public void reqExec_shouldSetPending() throws IllegalStateException, IllegalArgumentException {
76 params.put("PlaybookName", "test_playbook.yaml");
79 adapter.reqExec(params, svcContext);
80 String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
81 TestId = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.Id");
82 System.out.println("Comparing " + PENDING + " and " + status);
83 assertEquals(PENDING, status);
84 } catch (SvcLogicException e) {
85 String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
86 fail(e.getMessage() + " Code = " + status);
87 } catch (Exception e) {
88 fail(e.getMessage() + " Unknown exception encountered ");
93 public void reqExecResult_shouldSetSuccess() throws IllegalStateException, IllegalArgumentException {
95 params.put("Id", "100");
97 for (String ukey : params.keySet()) {
98 System.out.println(String.format("Ansible Parameter %s = %s", ukey, params.get(ukey)));
102 adapter.reqExecResult(params, svcContext);
103 String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
104 assertEquals(SUCCESS, status);
105 } catch (SvcLogicException e) {
106 String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.result.code");
107 fail(e.getMessage() + " Code = " + status);
108 } catch (Exception e) {
109 fail(e.getMessage() + " Unknown exception encountered ");
114 public void reqExecLog_shouldSetMessage() throws IllegalStateException, IllegalArgumentException {
116 params.put("Id", "101");
119 adapter.reqExecLog(params, svcContext);
120 String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.log");
121 assertEquals(message, status);
122 } catch (SvcLogicException e) {
123 String status = svcContext.getAttribute("org.onap.appc.adapter.ansible.log");
124 fail(e.getMessage() + " Code = " + status);
125 } catch (Exception e) {
126 fail(e.getMessage() + " Unknown exception encountered ");