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);
215 public void testBuildNetworkData2() throws Exception {
216 Properties props = null;
217 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
218 SvcLogicContext ctx = new SvcLogicContext();
219 String result = Whitebox.invokeMethod(cca, "buildNetworkData2", ctx, "template", "operation");
220 Assert.assertEquals("template", result);
224 public void testGetLastFewLinesOfFile() throws Exception {
225 Properties props = null;
226 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
227 Whitebox.invokeMethod(cca, "readFile", "test");
231 public void testConnect() throws Exception {
232 Properties props = null;
233 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
234 SvcLogicContext ctx = new SvcLogicContext();
235 cca.activate("key", ctx);
239 @Test(expected = Exception.class)
240 public void testActivate() throws Exception {
241 Properties props = null;
242 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
243 SvcLogicContext ctx = new SvcLogicContext();
244 String result = Whitebox.invokeMethod(cca, "activate", ctx, true);
245 Assert.assertEquals("template", result);
248 @Test(expected = Exception.class)
249 public void testAudit() throws Exception {
250 Properties props = null;
251 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
252 SvcLogicContext ctx = new SvcLogicContext();
253 String result = Whitebox.invokeMethod(cca, "audit", ctx, "test");
254 Assert.assertEquals("template", result);
257 @Test(expected = Exception.class)
258 public void testPrepare() throws Exception {
259 Properties props = null;
260 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
261 SvcLogicContext ctx = new SvcLogicContext();
262 String result = Whitebox.invokeMethod(cca, "prepare", ctx, "test", "test");
263 Assert.assertEquals("template", result);