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.ccadaptor;
26 import java.util.HashMap;
28 import java.util.Properties;
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
32 import org.powermock.reflect.Whitebox;
34 public class ConfigComponentAdaptorTest {
38 public void testGetCliRunningConfig() {
39 Properties props = null;
40 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
41 String Get_config_template = ("get_config_template");
42 String key = "GetCliRunningConfig";
43 Map<String, String> parameters = new HashMap<>();
44 parameters.put("Host_ip_address", "test");
45 parameters.put("User_name", "test");
46 parameters.put("Password", "password");
47 parameters.put("Port_number", "22");
48 parameters.put("Get_config_template", Get_config_template);
50 SvcLogicContext ctx = new SvcLogicContext();
52 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
54 cca.configure(key, parameters, ctx);
58 public void testDownloadCliConfig() {
59 Properties props = null;
60 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
61 String Get_config_template = ("get_config_template");
62 String key = "DownloadCliConfig";
63 Map<String, String> parameters = new HashMap<>();
64 parameters.put("Host_ip_address", "test");
65 parameters.put("User_name", "test");
66 parameters.put("Password", "password");
67 parameters.put("Port_number", "22");
68 parameters.put("Get_config_template", Get_config_template);
70 SvcLogicContext ctx = new SvcLogicContext();
72 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
74 cca.configure(key, parameters, ctx);
78 public void testXmlDownload() {
79 Properties props = null;
80 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
81 String Get_config_template = ("get_config_template");
82 String key = "xml-download";
83 Map<String, String> parameters = new HashMap<>();
84 parameters.put("Host_ip_address", "test");
85 parameters.put("User_name", "test");
86 parameters.put("Password", "password");
87 parameters.put("Port_number", "22");
88 parameters.put("Get_config_template", Get_config_template);
90 SvcLogicContext ctx = new SvcLogicContext();
92 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
94 cca.configure(key, parameters, ctx);
98 public void testXmlGetrunningconfig() {
99 Properties props = null;
100 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
101 String Get_config_template = ("get_config_template");
102 String key = "xml-getrunningconfig";
103 Map<String, String> parameters = new HashMap<>();
104 parameters.put("Host_ip_address", "test");
105 parameters.put("User_name", "test");
106 parameters.put("Password", "password");
107 parameters.put("Port_number", "22");
108 parameters.put("Get_config_template", Get_config_template);
110 SvcLogicContext ctx = new SvcLogicContext();
112 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
114 cca.configure(key, parameters, ctx);
118 public void testEscapeSql() {
119 Properties props = null;
120 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
121 String Get_config_template = ("get_config_template");
122 String key = "escapeSql";
123 Map<String, String> parameters = new HashMap<>();
124 parameters.put("Host_ip_address", "test");
125 parameters.put("User_name", "test");
126 parameters.put("Password", "password");
127 parameters.put("Port_number", "22");
128 parameters.put("Get_config_template", Get_config_template);
130 SvcLogicContext ctx = new SvcLogicContext();
132 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
134 cca.configure(key, parameters, ctx);
138 public void testAll() {
139 Properties props = null;
140 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
141 String Get_config_template = ("test");
142 String Download_config_template = ("test");
143 String key = "GetCliRunningConfig";
144 Map<String, String> parameters = new HashMap<>();
145 parameters.put("Host_ip_address", "test");
146 parameters.put("User_name", "test");
147 parameters.put("Password", "password");
148 parameters.put("Port_number", "22");
149 parameters.put("Get_config_template", Get_config_template);
150 parameters.put("Protocol", "netconf");
151 parameters.put("Contents", "Contents");
152 parameters.put("Download_config_template", Download_config_template);
153 parameters.put("Config_contents", "test");
155 SvcLogicContext ctx = new SvcLogicContext();
157 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
159 cca.configure(key, parameters, ctx);
163 public void testAll1() {
164 Properties props = null;
165 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
167 Map<String, String> parameters = new HashMap<>();
168 parameters.put("Host_ip_address", "test");
169 SvcLogicContext ctx = new SvcLogicContext();
171 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
173 cca.configure(key, parameters, ctx);
177 public void testAll2() {
178 Properties props = null;
179 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
181 Map<String, String> parameters = new HashMap<String, String>();
182 parameters.put("Host_ip_address", "test");
183 SvcLogicContext ctx = new SvcLogicContext();
185 "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
187 cca.configure(key, parameters, ctx);
191 public void testGetStringBetweenQuotes() throws Exception {
192 Properties props = null;
193 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
194 String result = Whitebox.invokeMethod(cca, "getStringBetweenQuotes", "\"testvalue\"");
195 Assert.assertEquals("testvalue", result);
199 public void testBuildXmlRequest() throws Exception {
200 Properties props = null;
201 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
202 Map<String, String> param = new HashMap<>();
203 Whitebox.invokeMethod(cca, "buildXmlRequest", param, "template");
207 public void testTrimResponse() throws Exception {
208 Properties props = null;
209 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
210 String result = Whitebox.invokeMethod(cca, "trimResponse", "testData");
211 Assert.assertEquals("", result);
214 String withConfigData = "<data>\n" +
215 "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n" +
216 "<version>1.1X.0</version>\n" +
218 "<name>node0</name>\n" +
219 "</configuration>\n" +
224 String compareString = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n"
225 + "<version>1.1X.0</version>\n"
227 + "<name>node0</name>\n"
228 + "</configuration>\n";
230 String result3 = Whitebox.invokeMethod(cca, "trimResponse", withConfigData);
231 Assert.assertEquals(compareString, result3);
233 String withData = "]]>]]>\n" +
234 "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" +
236 "<sgsn-mme xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
237 "<allocation-retention-priority xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
238 "<allocation-retention-priority>1</allocation-retention-priority>\n" +
239 "</allocation-retention-priority>\n" +
243 String compareStringWithData = "<sgsn-mme xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
244 "<allocation-retention-priority xmlns=\"urn:rdns:com:ericsson:oammodel:ericsson-sgsn-mme\">\n" +
245 "<allocation-retention-priority>1</allocation-retention-priority>\n" +
246 "</allocation-retention-priority>\n";
247 String result2 = Whitebox.invokeMethod(cca, "trimResponse", withData);
248 Assert.assertEquals(compareStringWithData,result2);
254 public void testBuildNetworkData2() throws Exception {
255 Properties props = null;
256 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
257 SvcLogicContext ctx = new SvcLogicContext();
258 String result = Whitebox.invokeMethod(cca, "buildNetworkData2", ctx, "template", "operation");
259 Assert.assertEquals("template", result);
263 public void testGetLastFewLinesOfFile() throws Exception {
264 Properties props = null;
265 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
266 Whitebox.invokeMethod(cca, "readFile", "test");
270 public void testConnect() throws Exception {
271 Properties props = null;
272 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
273 SvcLogicContext ctx = new SvcLogicContext();
274 cca.activate("key", ctx);
278 @Test(expected = Exception.class)
279 public void testActivate() throws Exception {
280 Properties props = null;
281 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
282 SvcLogicContext ctx = new SvcLogicContext();
283 String result = Whitebox.invokeMethod(cca, "activate", ctx, true);
284 Assert.assertEquals("template", result);
287 @Test(expected = Exception.class)
288 public void testAudit() throws Exception {
289 Properties props = null;
290 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
291 SvcLogicContext ctx = new SvcLogicContext();
292 String result = Whitebox.invokeMethod(cca, "audit", ctx, "test");
293 Assert.assertEquals("template", result);
296 @Test(expected = Exception.class)
297 public void testPrepare() throws Exception {
298 Properties props = null;
299 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
300 SvcLogicContext ctx = new SvcLogicContext();
301 String result = Whitebox.invokeMethod(cca, "prepare", ctx, "test", "test");
302 Assert.assertEquals("template", result);