ConfigComponentAdaptor sonar fixes part 2
[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 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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.ccadaptor;
26
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;
32
33 import java.util.HashMap;
34 import java.util.Map;
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;
40
41 public class ConfigComponentAdaptorTest {
42
43
44     @Test
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);
56
57         SvcLogicContext ctx = new SvcLogicContext();
58         ctx.setAttribute(
59             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
60             "test");
61         cca.configure(key, parameters, ctx);
62     }
63
64     @Test
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);
76
77         SvcLogicContext ctx = new SvcLogicContext();
78         ctx.setAttribute(
79             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
80             "test");
81         cca.configure(key, parameters, ctx);
82     }
83
84     @Test
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);
96
97         SvcLogicContext ctx = new SvcLogicContext();
98         ctx.setAttribute(
99             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
100             "test");
101         cca.configure(key, parameters, ctx);
102     }
103
104     @Test
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);
116
117         SvcLogicContext ctx = new SvcLogicContext();
118         ctx.setAttribute(
119             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
120             "test");
121         cca.configure(key, parameters, ctx);
122     }
123
124     @Test
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);
136
137         SvcLogicContext ctx = new SvcLogicContext();
138         ctx.setAttribute(
139             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
140             "test");
141         cca.configure(key, parameters, ctx);
142     }
143
144     @Test
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");
161
162         SvcLogicContext ctx = new SvcLogicContext();
163         ctx.setAttribute(
164             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
165             "test");
166         cca.configure(key, parameters, ctx);
167     }
168
169     @Test
170     public void testAll1() {
171         Properties props = null;
172         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
173         String key = "get";
174         Map<String, String> parameters = new HashMap<>();
175         parameters.put("Host_ip_address", "test");
176         SvcLogicContext ctx = new SvcLogicContext();
177         ctx.setAttribute(
178             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
179             "test");
180         cca.configure(key, parameters, ctx);
181     }
182
183     @Test
184     public void testAll2() {
185         Properties props = null;
186         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
187         String key = "cli";
188         Map<String, String> parameters = new HashMap<String, String>();
189         parameters.put("Host_ip_address", "test");
190         SvcLogicContext ctx = new SvcLogicContext();
191         ctx.setAttribute(
192             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
193             "test");
194         cca.configure(key, parameters, ctx);
195     }
196
197     @Test
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);
203     }
204
205     @Test
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");
211     }
212
213     @Test
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);
219     }
220
221     @Test
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);
228     }
229
230     //@Test
231     public void testGetLastFewLinesOfFile() throws Exception {
232         Properties props = null;
233         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
234         Whitebox.invokeMethod(cca, "readFile", "test");
235     }
236
237     @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);
243
244     }
245
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);
253     }
254
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);
262     }
263
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);
271     }
272 }