a863efbf61ae72035bb77a3437c2171b0d27cefa
[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  * 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  * ============LICENSE_END=========================================================
22  */
23
24 package org.onap.appc.ccadaptor;
25
26 import java.util.HashMap;
27 import java.util.Map;
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;
33
34 public class ConfigComponentAdaptorTest {
35
36
37     @Test
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);
49
50         SvcLogicContext ctx = new SvcLogicContext();
51         ctx.setAttribute(
52             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
53             "test");
54         cca.configure(key, parameters, ctx);
55     }
56
57     @Test
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);
69
70         SvcLogicContext ctx = new SvcLogicContext();
71         ctx.setAttribute(
72             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
73             "test");
74         cca.configure(key, parameters, ctx);
75     }
76
77     @Test
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);
89
90         SvcLogicContext ctx = new SvcLogicContext();
91         ctx.setAttribute(
92             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
93             "test");
94         cca.configure(key, parameters, ctx);
95     }
96
97     @Test
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);
109
110         SvcLogicContext ctx = new SvcLogicContext();
111         ctx.setAttribute(
112             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
113             "test");
114         cca.configure(key, parameters, ctx);
115     }
116
117     @Test
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);
129
130         SvcLogicContext ctx = new SvcLogicContext();
131         ctx.setAttribute(
132             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
133             "test");
134         cca.configure(key, parameters, ctx);
135     }
136
137     @Test
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");
154
155         SvcLogicContext ctx = new SvcLogicContext();
156         ctx.setAttribute(
157             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
158             "test");
159         cca.configure(key, parameters, ctx);
160     }
161
162     @Test
163     public void testAll1() {
164         Properties props = null;
165         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
166         String key = "get";
167         Map<String, String> parameters = new HashMap<>();
168         parameters.put("Host_ip_address", "test");
169         SvcLogicContext ctx = new SvcLogicContext();
170         ctx.setAttribute(
171             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
172             "test");
173         cca.configure(key, parameters, ctx);
174     }
175
176     //@Test
177     public void testAll2() {
178         Properties props = null;
179         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
180         String key = "cli";
181         Map<String, String> parameters = new HashMap<String, String>();
182         parameters.put("Host_ip_address", "test");
183         SvcLogicContext ctx = new SvcLogicContext();
184         ctx.setAttribute(
185             "service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name",
186             "test");
187         cca.configure(key, parameters, ctx);
188     }
189
190     @Test
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);
196     }
197
198     @Test
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");
204     }
205
206     @Test
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);
212
213
214         String withConfigData = "<data>\n" +
215                 "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n" +
216                 "<version>1.1X.0</version>\n" +
217                 "<groups>\n" +
218                 "<name>node0</name>\n" +
219                 "</configuration>\n" +
220                 "</data>\n" +
221                 "</rpc-reply>\n" +
222                 "]]>]]>\n" +
223                 "";
224         String compareString = "<configuration xmlns=\"http://xml.juniper.net/xnm/1.1/xnm\">\n"
225                 + "<version>1.1X.0</version>\n"
226                 + "<groups>\n"
227                 + "<name>node0</name>\n"
228                 + "</configuration>\n";
229
230         String result3 = Whitebox.invokeMethod(cca, "trimResponse", withConfigData);
231         Assert.assertEquals(compareString, result3);
232
233         String withData = "]]>]]>\n" +
234                 "<rpc-reply xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\" message-id=\"1\">\n" +
235                 "<data>\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" +
240                 "</data>\n" +
241                 "</rpc-reply>\n" +
242                 "]]>]]";
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);
249
250
251     }
252
253     @Test
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);
260     }
261
262     //@Test
263     public void testGetLastFewLinesOfFile() throws Exception {
264         Properties props = null;
265         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
266         Whitebox.invokeMethod(cca, "readFile", "test");
267     }
268
269     @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);
275
276     }
277
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);
285     }
286
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);
294     }
295
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);
303     }
304
305 }