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.openecomp.appc.adapter.ansible.impl;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNotNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
33 import java.io.IOException;
34 import java.lang.reflect.Field;
35 import java.util.HashMap;
36 import java.util.List;
38 import java.util.Properties;
41 import org.junit.Before;
42 import org.junit.BeforeClass;
43 import org.junit.Ignore;
44 import org.junit.Test;
45 import org.openecomp.appc.Constants;
46 import org.openecomp.appc.configuration.ConfigurationFactory;
47 import org.openecomp.appc.exceptions.APPCException;
48 import org.openecomp.sdnc.sli.SvcLogicContext;
49 import org.openecomp.sdnc.sli.SvcLogicException;
52 import org.openecomp.appc.adapter.ansible.AnsibleAdapter;
53 import org.openecomp.appc.adapter.ansible.impl.AnsibleAdapterImpl;
55 public class TestAnsibleAdapterImpl {
58 private AnsibleAdapterImpl adapter;
59 private String TestId;
60 private boolean testMode = true;
62 @SuppressWarnings("nls")
64 public static void once() throws NoSuchFieldException, SecurityException, NoSuchMethodException {
69 public void setup() throws IllegalArgumentException, IllegalAccessException {
71 adapter = new AnsibleAdapterImpl(testMode);
75 public void testA() throws IOException, IllegalStateException, IllegalArgumentException,
78 Map<String, String> params = new HashMap<>();
79 params.put("AgentUrl", "https://192.168.1.1");
80 params.put("User", "test");
81 params.put("Password", "test");
82 params.put("PlaybookName", "test_playbook.yaml");
84 SvcLogicContext svcContext = new SvcLogicContext();
86 String Pending = "100";
87 adapter.reqExec(params, svcContext);
88 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
89 TestId=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.Id");
90 System.out.println("Comparing " + Pending + " and " + status);
91 assertEquals(Pending,status);
93 catch(SvcLogicException e){
94 String message =svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.message");
95 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
96 fail(e.getMessage() + " Code = " + status);
99 fail(e.getMessage() + " Unknown exception encountered " );
105 public void testB() throws IOException, IllegalStateException, IllegalArgumentException,
108 Map<String, String> params = new HashMap<>();
110 params.put("AgentUrl", "https://192.168.1.1");
111 params.put("User", "test");
112 params.put("Password", "test");
113 params.put("Id", "100");
115 for (String ukey: params.keySet()){
116 System.out.println(String.format("Ansible Parameter %s = %s", ukey, params.get(ukey)));
119 SvcLogicContext svcContext = new SvcLogicContext();
122 adapter.reqExecResult(params, svcContext);
123 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
124 assertEquals("400",status);
126 catch(SvcLogicException e){
127 String message = svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.message");
128 String status=svcContext.getAttribute("org.openecomp.appc.adapter.ansible.result.code");
129 fail(e.getMessage() + " Code = " + status);
132 fail(e.getMessage() + " Unknown exception encountered " );