2 * ============LICENSE_START=======================================================
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
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.ccadaptor;
27 import java.io.IOException;
28 import java.util.HashMap;
30 import java.util.Properties;
32 import org.junit.Assert;
33 import org.junit.Test;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.powermock.reflect.Whitebox;
37 public class ConfigComponentAdaptorTest {
41 public void testGetCliRunningConfig(){
42 Properties props = null;
43 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
44 String Get_config_template = ("get_config_template");
45 String key = "GetCliRunningConfig";
46 Map<String, String> parameters = new HashMap<String, String>();
47 parameters.put("Host_ip_address", "test");
48 parameters.put("User_name", "test");
49 parameters.put("Password", "password");
50 parameters.put("Port_number", "22");
51 parameters.put("Get_config_template", Get_config_template);
53 SvcLogicContext ctx = new SvcLogicContext();
54 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
55 cca.configure(key, parameters, ctx);
59 public void testDownloadCliConfig(){
60 Properties props = null;
61 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
62 String Get_config_template = ("get_config_template");
63 String key = "DownloadCliConfig";
64 Map<String, String> parameters = new HashMap<String, String>();
65 parameters.put("Host_ip_address", "test");
66 parameters.put("User_name", "test");
67 parameters.put("Password", "password");
68 parameters.put("Port_number", "22");
69 parameters.put("Get_config_template", Get_config_template);
71 SvcLogicContext ctx = new SvcLogicContext();
72 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
73 cca.configure(key, parameters, ctx);
77 public void testXmlDownload(){
78 Properties props = null;
79 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
80 String Get_config_template = ("get_config_template");
81 String key = "xml-download";
82 Map<String, String> parameters = new HashMap<String, String>();
83 parameters.put("Host_ip_address", "test");
84 parameters.put("User_name", "test");
85 parameters.put("Password", "password");
86 parameters.put("Port_number", "22");
87 parameters.put("Get_config_template", Get_config_template);
89 SvcLogicContext ctx = new SvcLogicContext();
90 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
91 cca.configure(key, parameters, ctx);
95 public void testXmlGetrunningconfig(){
96 Properties props = null;
97 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
98 String Get_config_template = ("get_config_template");
99 String key = "xml-getrunningconfig";
100 Map<String, String> parameters = new HashMap<String, String>();
101 parameters.put("Host_ip_address", "test");
102 parameters.put("User_name", "test");
103 parameters.put("Password", "password");
104 parameters.put("Port_number", "22");
105 parameters.put("Get_config_template", Get_config_template);
107 SvcLogicContext ctx = new SvcLogicContext();
108 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
109 cca.configure(key, parameters, ctx);
113 public void testEscapeSql(){
114 Properties props = null;
115 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
116 String Get_config_template = ("get_config_template");
117 String key = "escapeSql";
118 Map<String, String> parameters = new HashMap<String, String>();
119 parameters.put("Host_ip_address", "test");
120 parameters.put("User_name", "test");
121 parameters.put("Password", "password");
122 parameters.put("Port_number", "22");
123 parameters.put("Get_config_template", Get_config_template);
125 SvcLogicContext ctx = new SvcLogicContext();
126 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
127 cca.configure(key, parameters, ctx);
131 public void testAll(){
132 Properties props = null;
133 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
134 String Get_config_template = ("test");
135 String Download_config_template = ("test");
136 String key = "GetCliRunningConfig";
137 Map<String, String> parameters = new HashMap<String,String>();
138 parameters.put("Host_ip_address", "test");
139 parameters.put("User_name", "test");
140 parameters.put("Password", "password");
141 parameters.put("Port_number", "22");
142 parameters.put("Protocol", "netconf");
143 parameters.put("Contents", "Contents");
144 parameters.put("Get_config_template", Get_config_template);
145 parameters.put("Download_config_template", Download_config_template);
146 parameters.put("Config_contents", "test");
148 SvcLogicContext ctx = new SvcLogicContext();
149 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
150 cca.configure(key, parameters, ctx);
154 public void testAll1(){
155 Properties props = null;
156 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
158 Map<String, String> parameters = new HashMap<String,String>();
159 parameters.put("Host_ip_address", "test");
160 SvcLogicContext ctx = new SvcLogicContext();
161 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
162 cca.configure(key, parameters, ctx);
166 public void testAll2(){
167 Properties props = null;
168 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
170 Map<String, String> parameters = new HashMap<String,String>();
171 parameters.put("Host_ip_address", "test");
172 SvcLogicContext ctx = new SvcLogicContext();
173 ctx.setAttribute("service-data.vnf-config-parameters-list.vnf-config-parameters[0].update-configuration[0].block-key-name", "test");
174 cca.configure(key, parameters, ctx);
178 public void testGetStringBetweenQuotes() throws Exception{
179 Properties props = null;
180 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
181 String result =Whitebox.invokeMethod(cca, "getStringBetweenQuotes","\"testvalue\"");
182 Assert.assertEquals("testvalue", result);
186 public void testBuildXmlRequest() throws Exception{
187 Properties props = null;
188 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
189 Map<String, String> param = new HashMap<String,String>();
190 Whitebox.invokeMethod(cca, "buildXmlRequest",param,"template");
194 public void testTrimResponse() throws Exception{
195 Properties props = null;
196 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
197 String result =Whitebox.invokeMethod(cca, "trimResponse","testData");
198 Assert.assertEquals("", result);
202 public void testBuildNetworkData2() throws Exception{
203 Properties props = null;
204 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
205 SvcLogicContext ctx = new SvcLogicContext();
206 String result =Whitebox.invokeMethod(cca, "buildNetworkData2",ctx,"template","operation");
207 Assert.assertEquals("template", result);
211 public void testGetLastFewLinesOfFile() throws Exception{
212 Properties props = null;
213 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
214 Whitebox.invokeMethod(cca, "readFile","test");
218 public void testConnect() throws Exception{
219 Properties props = null;
220 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
221 SvcLogicContext ctx = new SvcLogicContext();
222 cca.activate("key", ctx);
226 @Test(expected=Exception.class)
227 public void testActivate() throws Exception{
228 Properties props = null;
229 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
230 SvcLogicContext ctx = new SvcLogicContext();
231 String result =Whitebox.invokeMethod(cca, "activate",ctx,true);
232 Assert.assertEquals("template", result);
235 @Test(expected=Exception.class)
236 public void testAudit() throws Exception{
237 Properties props = null;
238 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
239 SvcLogicContext ctx = new SvcLogicContext();
240 String result =Whitebox.invokeMethod(cca, "audit",ctx,"test");
241 Assert.assertEquals("template", result);
244 @Test(expected=Exception.class)
245 public void testPrepare() throws Exception{
246 Properties props = null;
247 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
248 SvcLogicContext ctx = new SvcLogicContext();
249 String result =Whitebox.invokeMethod(cca, "prepare",ctx,"test","test");
250 Assert.assertEquals("template", result);