updated existing test case to increase coverage
[appc.git] / appc-config / appc-config-adaptor / provider / src / test / java / org / onap / appc / ccadaptor / ConfigComponentAdaptorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
14  *
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  *
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.
22  *
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.ccadaptor;
27
28 import java.util.HashMap;
29 import java.util.Map;
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;
35
36 public class ConfigComponentAdaptorTest {
37
38
39     @Test
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");
54         
55         SvcLogicContext ctx = new SvcLogicContext();
56         ctx.setAttribute(
57             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
58             "test");
59         cca.configure(key, parameters, ctx);
60     }
61
62     @Test
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);
74
75         SvcLogicContext ctx = new SvcLogicContext();
76         ctx.setAttribute(
77             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
78             "test");
79         cca.configure(key, parameters, ctx);
80     }
81
82     @Test
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);
94
95         SvcLogicContext ctx = new SvcLogicContext();
96         ctx.setAttribute(
97             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
98             "test");
99         cca.configure(key, parameters, ctx);
100     }
101
102     @Test
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);
114
115         SvcLogicContext ctx = new SvcLogicContext();
116         ctx.setAttribute(
117             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
118             "test");
119         cca.configure(key, parameters, ctx);
120     }
121
122     @Test
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);
134
135         SvcLogicContext ctx = new SvcLogicContext();
136         ctx.setAttribute(
137             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
138             "test");
139         cca.configure(key, parameters, ctx);
140     }
141
142     @Test
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");
159
160         SvcLogicContext ctx = new SvcLogicContext();
161         ctx.setAttribute(
162             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
163             "test");
164         cca.configure(key, parameters, ctx);
165     }
166
167     @Test
168     public void testAll1() {
169         Properties props = null;
170         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
171         String key = "get";
172         Map<String, String> parameters = new HashMap<>();
173         parameters.put("Host_ip_address", "test");
174         SvcLogicContext ctx = new SvcLogicContext();
175         ctx.setAttribute(
176             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
177             "test");
178         cca.configure(key, parameters, ctx);
179     }
180
181     //@Test
182     public void testAll2() {
183         Properties props = null;
184         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
185         String key = "cli";
186         Map<String, String> parameters = new HashMap<String, String>();
187         parameters.put("Host_ip_address", "test");
188         SvcLogicContext ctx = new SvcLogicContext();
189         ctx.setAttribute(
190             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
191             "test");
192         cca.configure(key, parameters, ctx);
193     }
194
195     @Test
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);
201     }
202
203     @Test
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");
209     }
210
211     @Test
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);
217
218
219         String withConfigData = "<data>\n" +
220                 "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n" +
221                 "<version>1.1X.0</version>\n" +
222                 "<groups>\n" +
223                 "<name>node0</name>\n" +
224                 "</configuration>\n" +
225                 "</data>\n" +
226                 "</rpc-reply>\n" +
227                 "]]>]]>\n" +
228                 "";
229         String compareString = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n"
230                 + "<version>1.1X.0</version>\n"
231                 + "<groups>\n"
232                 + "<name>node0</name>\n"
233                 + "</configuration>\n";
234
235         String result3 = Whitebox.invokeMethod(cca, "trimResponse", withConfigData);
236         Assert.assertEquals(compareString, result3);
237
238         String withData = "]]>]]>\n" +
239                 "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" +
240                 "<data>\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" +
245                 "</data>\n" +
246                 "</rpc-reply>\n" +
247                 "]]>]]";
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);
254
255
256     }
257
258     @Test
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);
265     }
266
267     //@Test
268     public void testGetLastFewLinesOfFile() throws Exception {
269         Properties props = null;
270         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
271         Whitebox.invokeMethod(cca, "readFile", "test");
272     }
273
274     @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);
280
281     }
282
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);
290     }
291
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);
299     }
300
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);
308     }
309
310 }