2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Modification Copyright (C) 2018 IBM.
10 * =============================================================================
11 * Licensed under the Apache License, Version 2.0 (the "License");
12 * you may not use this file except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * ============LICENSE_END=========================================================
26 package org.onap.appc.ccadaptor;
28 import java.util.HashMap;
30 import java.util.Properties;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
34 import org.powermock.reflect.Whitebox;
36 public class ConfigComponentAdaptorTest {
40 public void testGetCliRunningConfig() {
41 Properties props = null;
42 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
43 String Get_config_template = ("get_config_template");
44 String key = "GetCliRunningConfig";
45 Map<String, String> parameters = new HashMap<>();
46 parameters.put("Host_ip_address", "test");
47 parameters.put("User_name", "test");
48 parameters.put("Password", "password");
49 parameters.put("Port_number", "22");
50 parameters.put("Get_config_template", Get_config_template);
51 parameters.put("config-component-configUrl","testUrl");
52 parameters.put("config-component-configPassword","testPassword");
53 parameters.put("config-component-configUser","testUser");
55 SvcLogicContext ctx = new SvcLogicContext();
57 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
59 cca.configure(key, parameters, ctx);
63 public void testDownloadCliConfig() {
64 Properties props = null;
65 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
66 String Get_config_template = ("get_config_template");
67 String key = "DownloadCliConfig";
68 Map<String, String> parameters = new HashMap<>();
69 parameters.put("Host_ip_address", "test");
70 parameters.put("User_name", "test");
71 parameters.put("Password", "password");
72 parameters.put("Port_number", "22");
73 parameters.put("Get_config_template", Get_config_template);
75 SvcLogicContext ctx = new SvcLogicContext();
77 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
79 cca.configure(key, parameters, ctx);
83 public void testXmlDownload() {
84 Properties props = null;
85 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
86 String Get_config_template = ("get_config_template");
87 String key = "xml-download";
88 Map<String, String> parameters = new HashMap<>();
89 parameters.put("Host_ip_address", "test");
90 parameters.put("User_name", "test");
91 parameters.put("Password", "password");
92 parameters.put("Port_number", "22");
93 parameters.put("Get_config_template", Get_config_template);
95 SvcLogicContext ctx = new SvcLogicContext();
97 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
99 cca.configure(key, parameters, ctx);
103 public void testXmlGetrunningconfig() {
104 Properties props = null;
105 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
106 String Get_config_template = ("get_config_template");
107 String key = "xml-getrunningconfig";
108 Map<String, String> parameters = new HashMap<>();
109 parameters.put("Host_ip_address", "test");
110 parameters.put("User_name", "test");
111 parameters.put("Password", "password");
112 parameters.put("Port_number", "22");
113 parameters.put("Get_config_template", Get_config_template);
115 SvcLogicContext ctx = new SvcLogicContext();
117 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
119 cca.configure(key, parameters, ctx);
123 public void testEscapeSql() {
124 Properties props = null;
125 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
126 String Get_config_template = ("get_config_template");
127 String key = "escapeSql";
128 Map<String, String> parameters = new HashMap<>();
129 parameters.put("Host_ip_address", "test");
130 parameters.put("User_name", "test");
131 parameters.put("Password", "password");
132 parameters.put("Port_number", "22");
133 parameters.put("Get_config_template", Get_config_template);
135 SvcLogicContext ctx = new SvcLogicContext();
137 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
139 cca.configure(key, parameters, ctx);
143 public void testAll() {
144 Properties props = null;
145 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
146 String Get_config_template = ("test");
147 String Download_config_template = ("test");
148 String key = "GetCliRunningConfig";
149 Map<String, String> parameters = new HashMap<>();
150 parameters.put("Host_ip_address", "test");
151 parameters.put("User_name", "test");
152 parameters.put("Password", "password");
153 parameters.put("Port_number", "22");
154 parameters.put("Get_config_template", Get_config_template);
155 parameters.put("Protocol", "netconf");
156 parameters.put("Contents", "Contents");
157 parameters.put("Download_config_template", Download_config_template);
158 parameters.put("Config_contents", "test");
160 SvcLogicContext ctx = new SvcLogicContext();
162 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
164 cca.configure(key, parameters, ctx);
168 public void testAll1() {
169 Properties props = null;
170 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
172 Map<String, String> parameters = new HashMap<>();
173 parameters.put("Host_ip_address", "test");
174 SvcLogicContext ctx = new SvcLogicContext();
176 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
178 cca.configure(key, parameters, ctx);
182 public void testAll2() {
183 Properties props = null;
184 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
186 Map<String, String> parameters = new HashMap<String, String>();
187 parameters.put("Host_ip_address", "test");
188 SvcLogicContext ctx = new SvcLogicContext();
190 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
192 cca.configure(key, parameters, ctx);
196 public void testGetStringBetweenQuotes() throws Exception {
197 Properties props = null;
198 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
199 String result = Whitebox.invokeMethod(cca, "getStringBetweenQuotes", "\"testvalue\"");
200 Assert.assertEquals("testvalue", result);
204 public void testBuildXmlRequest() throws Exception {
205 Properties props = null;
206 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
207 Map<String, String> param = new HashMap<>();
208 Whitebox.invokeMethod(cca, "buildXmlRequest", param, "template");
212 public void testTrimResponse() throws Exception {
213 Properties props = null;
214 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
215 String result = Whitebox.invokeMethod(cca, "trimResponse", "testData");
216 Assert.assertEquals("", result);
219 String withConfigData = "<data>\n" +
220 "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n" +
221 "<version>1.1X.0</version>\n" +
223 "<name>node0</name>\n" +
224 "</configuration>\n" +
229 String compareString = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n"
230 + "<version>1.1X.0</version>\n"
232 + "<name>node0</name>\n"
233 + "</configuration>\n";
235 String result3 = Whitebox.invokeMethod(cca, "trimResponse", withConfigData);
236 Assert.assertEquals(compareString, result3);
238 String withData = "]]>]]>\n" +
239 "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" +
241 "<sgsn-mme xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
242 "<allocation-retention-priority xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
243 "<allocation-retention-priority>1</allocation-retention-priority>\n" +
244 "</allocation-retention-priority>\n" +
248 String compareStringWithData = "<sgsn-mme xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
249 "<allocation-retention-priority xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
250 "<allocation-retention-priority>1</allocation-retention-priority>\n" +
251 "</allocation-retention-priority>\n";
252 String result2 = Whitebox.invokeMethod(cca, "trimResponse", withData);
253 Assert.assertEquals(compareStringWithData,result2);
259 public void testBuildNetworkData2() throws Exception {
260 Properties props = null;
261 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
262 SvcLogicContext ctx = new SvcLogicContext();
263 String result = Whitebox.invokeMethod(cca, "buildNetworkData2", ctx, "template", "operation");
264 Assert.assertEquals("template", result);
268 public void testGetLastFewLinesOfFile() throws Exception {
269 Properties props = null;
270 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
271 Whitebox.invokeMethod(cca, "readFile", "test");
275 public void testConnect() throws Exception {
276 Properties props = null;
277 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
278 SvcLogicContext ctx = new SvcLogicContext();
279 cca.activate("key", ctx);
283 @Test(expected = Exception.class)
284 public void testActivate() throws Exception {
285 Properties props = null;
286 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
287 SvcLogicContext ctx = new SvcLogicContext();
288 String result = Whitebox.invokeMethod(cca, "activate", ctx, true);
289 Assert.assertEquals("template", result);
292 @Test(expected = Exception.class)
293 public void testAudit() throws Exception {
294 Properties props = null;
295 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
296 SvcLogicContext ctx = new SvcLogicContext();
297 String result = Whitebox.invokeMethod(cca, "audit", ctx, "test");
298 Assert.assertEquals("template", result);
301 @Test(expected = Exception.class)
302 public void testPrepare() throws Exception {
303 Properties props = null;
304 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
305 SvcLogicContext ctx = new SvcLogicContext();
306 String result = Whitebox.invokeMethod(cca, "prepare", ctx, "test", "test");
307 Assert.assertEquals("template", result);