First part of onap rename
[appc.git] / appc-config / appc-config-adaptor / provider / src / test / java / org / openecomp / 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 java.util.HashMap;
28 import java.util.Map;
29 import java.util.Properties;
30
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<String, String>();
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
52         SvcLogicContext ctx = new SvcLogicContext();
53         ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "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<String, String>();
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("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
72         cca.configure(key, parameters, ctx);    
73     }
74     
75     @Test
76     public void testXmlDownload(){
77         Properties props = null;
78         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
79         String Get_config_template = ("get_config_template");
80         String key = "xml-download";
81         Map<String, String> parameters = new HashMap<String, String>();
82         parameters.put("Host_ip_address", "test");
83         parameters.put("User_name", "test");
84         parameters.put("Password", "password");
85         parameters.put("Port_number", "22");
86         parameters.put("Get_config_template", Get_config_template);
87
88         SvcLogicContext ctx = new SvcLogicContext();
89         ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
90         cca.configure(key, parameters, ctx);
91     }
92     
93     @Test
94     public void testXmlGetrunningconfig(){
95         Properties props = null;
96         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
97         String Get_config_template = ("get_config_template");
98         String key = "xml-getrunningconfig";
99         Map<String, String> parameters = new HashMap<String, String>();
100         parameters.put("Host_ip_address", "test");
101         parameters.put("User_name", "test");
102         parameters.put("Password", "password");
103         parameters.put("Port_number", "22");
104         parameters.put("Get_config_template", Get_config_template);
105
106         SvcLogicContext ctx = new SvcLogicContext();
107         ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
108         cca.configure(key, parameters, ctx);        
109     }
110     
111     @Test
112     public void testEscapeSql(){
113         Properties props = null;
114         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
115         String Get_config_template = ("get_config_template");
116         String key = "escapeSql";
117         Map<String, String> parameters = new HashMap<String, String>();
118         parameters.put("Host_ip_address", "test");
119         parameters.put("User_name", "test");
120         parameters.put("Password", "password");
121         parameters.put("Port_number", "22");
122         parameters.put("Get_config_template", Get_config_template);
123
124         SvcLogicContext ctx = new SvcLogicContext();
125         ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
126         cca.configure(key, parameters, ctx);
127     }
128     
129     @Test
130     public void testAll(){
131         Properties props = null;
132         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
133         String Get_config_template = ("test");
134         String Download_config_template = ("test");
135         String key = "GetCliRunningConfig";
136         Map<String, String> parameters = new HashMap<String,String>();
137         parameters.put("Host_ip_address", "test");
138         parameters.put("User_name", "test");
139         parameters.put("Password", "password");
140         parameters.put("Port_number", "22");
141         parameters.put("Protocol", "netconf");
142         parameters.put("Contents", "Contents");
143         parameters.put("Get_config_template", Get_config_template);
144         parameters.put("Download_config_template", Download_config_template);
145         parameters.put("Config_contents", "test");
146
147         SvcLogicContext ctx = new SvcLogicContext();
148         ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
149         cca.configure(key, parameters, ctx);        
150     }
151     
152     @Test(expected=Exception.class)
153     public void testAll1(){
154         Properties props = null;
155         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
156         String key = "get";
157         Map<String, String> parameters = new HashMap<String,String>();
158         parameters.put("Host_ip_address", "test");
159         SvcLogicContext ctx = new SvcLogicContext();
160         ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
161         cca.configure(key, parameters, ctx);        
162     }
163     
164     @Test(expected=Exception.class)
165     public void testAll2(){
166         Properties props = null;
167         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
168         String key = "cli";
169         Map<String, String> parameters = new HashMap<String,String>();
170         parameters.put("Host_ip_address", "test");
171         SvcLogicContext ctx = new SvcLogicContext();
172         ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
173         cca.configure(key, parameters, ctx);        
174     }
175     
176     @Test
177     public void testGetStringBetweenQuotes() throws Exception{
178         Properties props = null;
179         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
180         String result =Whitebox.invokeMethod(cca, "getStringBetweenQuotes","\"testvalue\"");
181         Assert.assertEquals("testvalue", result);
182     }
183     
184     @Test
185     public void testBuildXmlRequest() throws Exception{
186         Properties props = null;
187         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
188         Map<String, String> param = new HashMap<String,String>();
189         Whitebox.invokeMethod(cca, "buildXmlRequest",param,"template");    
190     }
191     
192     @Test
193     public void testTrimResponse() throws Exception{
194         Properties props = null;
195         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
196         String result =Whitebox.invokeMethod(cca, "trimResponse","testData");
197         Assert.assertEquals("", result);
198     }
199     
200     @Test
201     public void testBuildNetworkData2() throws Exception{
202         Properties props = null;
203         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
204         SvcLogicContext ctx = new SvcLogicContext();
205         String result =Whitebox.invokeMethod(cca, "buildNetworkData2",ctx,"template","operation");
206         Assert.assertEquals("template", result);
207     }
208     
209     //@Test
210     public void testGetLastFewLinesOfFile() throws Exception{
211         Properties props = null;
212         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
213         Whitebox.invokeMethod(cca, "readFile","test");    
214     }
215     
216     @Test
217     public void testConnect() throws Exception{
218         Properties props = null;
219         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
220         SvcLogicContext ctx = new SvcLogicContext();
221         cca.activate("key", ctx);
222
223     }
224     
225     @Test(expected=Exception.class)
226     public void testActivate() throws Exception{
227         Properties props = null;
228         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
229         SvcLogicContext ctx = new SvcLogicContext();
230         String result =Whitebox.invokeMethod(cca, "activate",ctx,true);
231         Assert.assertEquals("template", result);
232     }
233     
234     @Test(expected=Exception.class)
235     public void testAudit() throws Exception{
236         Properties props = null;
237         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
238         SvcLogicContext ctx = new SvcLogicContext();
239         String result =Whitebox.invokeMethod(cca, "audit",ctx,"test");
240         Assert.assertEquals("template", result);
241     }
242     
243     @Test(expected=Exception.class)
244     public void testPrepare() throws Exception{
245         Properties props = null;
246         ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
247         SvcLogicContext ctx = new SvcLogicContext();
248         String result =Whitebox.invokeMethod(cca, "prepare",ctx,"test","test");
249         Assert.assertEquals("template", result);
250     }
251 }