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.ccadaptor;
27 import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.GET_CONFIG_TEMPLATE_PARAM;
28 import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.HOST_IP_PARAM;
29 import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.PASSWORD_PARAM;
30 import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.PORT_NUMBER_PARAM;
31 import static org.onap.appc.ccadaptor.ConfigComponentAdaptor.USERNAME_PARAM;
33 import java.util.HashMap;
35 import java.util.Properties;
36 import org.junit.Assert;
37 import org.junit.Test;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.powermock.reflect.Whitebox;
41 public class ConfigComponentAdaptorTest {
45 public void testGetCliRunningConfig() {
46 Properties props = null;
47 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
48 String Get_config_template = ("get_config_template");
49 String key = "GetCliRunningConfig";
50 Map<String, String> parameters = new HashMap<>();
51 parameters.put(HOST_IP_PARAM, "test");
52 parameters.put(USERNAME_PARAM, "test");
53 parameters.put(PASSWORD_PARAM, "password");
54 parameters.put(PORT_NUMBER_PARAM, "22");
55 parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template);
57 SvcLogicContext ctx = new SvcLogicContext();
59 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
61 cca.configure(key, parameters, ctx);
65 public void testDownloadCliConfig() {
66 Properties props = null;
67 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
68 String Get_config_template = ("get_config_template");
69 String key = "DownloadCliConfig";
70 Map<String, String> parameters = new HashMap<>();
71 parameters.put(HOST_IP_PARAM, "test");
72 parameters.put(USERNAME_PARAM, "test");
73 parameters.put(PASSWORD_PARAM, "password");
74 parameters.put(PORT_NUMBER_PARAM, "22");
75 parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template);
77 SvcLogicContext ctx = new SvcLogicContext();
79 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
81 cca.configure(key, parameters, ctx);
85 public void testXmlDownload() {
86 Properties props = null;
87 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
88 String Get_config_template = ("get_config_template");
89 String key = "xml-download";
90 Map<String, String> parameters = new HashMap<>();
91 parameters.put(HOST_IP_PARAM, "test");
92 parameters.put(USERNAME_PARAM, "test");
93 parameters.put(PASSWORD_PARAM, "password");
94 parameters.put(PORT_NUMBER_PARAM, "22");
95 parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template);
97 SvcLogicContext ctx = new SvcLogicContext();
99 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
101 cca.configure(key, parameters, ctx);
105 public void testXmlGetrunningconfig() {
106 Properties props = null;
107 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
108 String Get_config_template = ("get_config_template");
109 String key = "xml-getrunningconfig";
110 Map<String, String> parameters = new HashMap<>();
111 parameters.put(HOST_IP_PARAM, "test");
112 parameters.put(USERNAME_PARAM, "test");
113 parameters.put(PASSWORD_PARAM, "password");
114 parameters.put(PORT_NUMBER_PARAM, "22");
115 parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template);
117 SvcLogicContext ctx = new SvcLogicContext();
119 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
121 cca.configure(key, parameters, ctx);
125 public void testEscapeSql() {
126 Properties props = null;
127 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
128 String Get_config_template = ("get_config_template");
129 String key = "escapeSql";
130 Map<String, String> parameters = new HashMap<>();
131 parameters.put(HOST_IP_PARAM, "test");
132 parameters.put(USERNAME_PARAM, "test");
133 parameters.put(PASSWORD_PARAM, "password");
134 parameters.put(PORT_NUMBER_PARAM, "22");
135 parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template);
137 SvcLogicContext ctx = new SvcLogicContext();
139 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
141 cca.configure(key, parameters, ctx);
145 public void testAll() {
146 Properties props = null;
147 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
148 String Get_config_template = ("test");
149 String Download_config_template = ("test");
150 String key = "GetCliRunningConfig";
151 Map<String, String> parameters = new HashMap<>();
152 parameters.put(HOST_IP_PARAM, "test");
153 parameters.put(USERNAME_PARAM, "test");
154 parameters.put(PASSWORD_PARAM, "password");
155 parameters.put(PORT_NUMBER_PARAM, "22");
156 parameters.put("Protocol", "netconf");
157 parameters.put("Contents", "Contents");
158 parameters.put(GET_CONFIG_TEMPLATE_PARAM, Get_config_template);
159 parameters.put("Download_config_template", Download_config_template);
160 parameters.put("Config_contents", "test");
162 SvcLogicContext ctx = new SvcLogicContext();
164 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
166 cca.configure(key, parameters, ctx);
170 public void testAll1() {
171 Properties props = null;
172 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
174 Map<String, String> parameters = new HashMap<>();
175 parameters.put("Host_ip_address", "test");
176 SvcLogicContext ctx = new SvcLogicContext();
178 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
180 cca.configure(key, parameters, ctx);
184 public void testAll2() {
185 Properties props = null;
186 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
188 Map<String, String> parameters = new HashMap<String, String>();
189 parameters.put("Host_ip_address", "test");
190 SvcLogicContext ctx = new SvcLogicContext();
192 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
194 cca.configure(key, parameters, ctx);
198 public void testGetStringBetweenQuotes() throws Exception {
199 Properties props = null;
200 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
201 String result = Whitebox.invokeMethod(cca, "getStringBetweenQuotes", "\"testvalue\"");
202 Assert.assertEquals("testvalue", result);
206 public void testBuildXmlRequest() throws Exception {
207 Properties props = null;
208 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
209 Map<String, String> param = new HashMap<>();
210 Whitebox.invokeMethod(cca, "buildXmlRequest", param, "template");
214 public void testTrimResponse() throws Exception {
215 Properties props = null;
216 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
217 String result = Whitebox.invokeMethod(cca, "trimResponse", "testData");
218 Assert.assertEquals("", result);
222 public void testBuildNetworkData2() throws Exception {
223 Properties props = null;
224 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
225 SvcLogicContext ctx = new SvcLogicContext();
226 String result = Whitebox.invokeMethod(cca, "buildNetworkData2", ctx, "template", "operation");
227 Assert.assertEquals("template", result);
231 public void testGetLastFewLinesOfFile() throws Exception {
232 Properties props = null;
233 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
234 Whitebox.invokeMethod(cca, "readFile", "test");
238 public void testConnect() throws Exception {
239 Properties props = null;
240 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
241 SvcLogicContext ctx = new SvcLogicContext();
242 cca.activate("key", ctx);
246 @Test(expected = Exception.class)
247 public void testActivate() throws Exception {
248 Properties props = null;
249 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
250 SvcLogicContext ctx = new SvcLogicContext();
251 String result = Whitebox.invokeMethod(cca, "activate", ctx, true);
252 Assert.assertEquals("template", result);
255 @Test(expected = Exception.class)
256 public void testAudit() throws Exception {
257 Properties props = null;
258 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
259 SvcLogicContext ctx = new SvcLogicContext();
260 String result = Whitebox.invokeMethod(cca, "audit", ctx, "test");
261 Assert.assertEquals("template", result);
264 @Test(expected = Exception.class)
265 public void testPrepare() throws Exception {
266 Properties props = null;
267 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
268 SvcLogicContext ctx = new SvcLogicContext();
269 String result = Whitebox.invokeMethod(cca, "prepare", ctx, "test", "test");
270 Assert.assertEquals("template", result);