2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.adapter.ansible.impl;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.junit.Assert.fail;
31 import java.io.IOException;
32 import java.lang.reflect.Field;
33 import java.util.HashMap;
34 import java.util.List;
36 import java.util.Properties;
39 import org.junit.Before;
40 import org.junit.BeforeClass;
41 import org.junit.Ignore;
42 import org.junit.Test;
43 import org.openecomp.appc.Constants;
44 import org.openecomp.appc.configuration.ConfigurationFactory;
45 import org.openecomp.appc.exceptions.APPCException;
46 import org.openecomp.sdnc.sli.SvcLogicContext;
47 import org.openecomp.sdnc.sli.SvcLogicException;
50 import org.openecomp.appc.adapter.ansible.AnsibleAdapter;
51 import org.openecomp.appc.adapter.ansible.impl.AnsibleAdapterImpl;
53 public class TestAnsibleAdapterImpl {
56 private AnsibleAdapterImpl adapter;
57 private String TestId;
58 private boolean testMode = true;
60 @SuppressWarnings("nls")
62 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
67 public void setup() throws IllegalArgumentException, IllegalAccessException {
69 adapter = new AnsibleAdapterImpl(testMode);
73 public void testA() throws IOException, IllegalStateException, IllegalArgumentException,
76 Map<String, String> params = new HashMap<>();
77 params.put("AgentUrl", "https://192.168.1.1");
78 params.put("User", "test");
79 params.put("Password", "test");
80 params.put("PlaybookName", "test_playbook.yaml");
82 SvcLogicContext svcContext = new SvcLogicContext();
84 String Pending = "100";
85 adapter.reqExec(params, svcContext);
86 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
87 TestId=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.Id");
88 System.out.println("Comparing " + Pending + " and " + status);
89 assertEquals(Pending,status);
91 catch(SvcLogicException e){
92 String message =svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.message");
93 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
94 fail(e.getMessage() + " Code = " + status);
97 fail(e.getMessage() + " Unknown exception encountered " );
103 public void testB() throws IOException, IllegalStateException, IllegalArgumentException,
106 Map<String, String> params = new HashMap<>();
108 params.put("AgentUrl", "https://192.168.1.1");
109 params.put("User", "test");
110 params.put("Password", "test");
111 params.put("Id", "100");
113 for (String ukey: params.keySet()){
114 System.out.println(String.format("Ansible Parameter %s = %s", ukey, params.get(ukey)));
117 SvcLogicContext svcContext = new SvcLogicContext();
120 adapter.reqExecResult(params, svcContext);
121 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
122 assertEquals("400",status);
124 catch(SvcLogicException e){
125 String message = svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.message");
126 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
127 fail(e.getMessage() + " Code = " + status);
130 fail(e.getMessage() + " Unknown exception encountered " );