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.util.HashMap;
29 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;
36 public class ConfigComponentAdaptorTest {
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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");
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);
152 @Test(expected=Exception.class)
153 public void testAll1(){
154 Properties props = null;
155 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
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);
164 @Test(expected=Exception.class)
165 public void testAll2(){
166 Properties props = null;
167 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
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);
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);
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");
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);
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);
210 public void testGetLastFewLinesOfFile() throws Exception{
211 Properties props = null;
212 ConfigComponentAdaptor cca = new ConfigComponentAdaptor(props);
213 Whitebox.invokeMethod(cca, "readFile","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);
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);
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);
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);