2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package jtest.org.onap.ccsdk.sli.plugins.restapicall;
24 import java.util.HashMap;
27 import org.junit.Test;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class TestRestapiCallNode {
36 private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
40 public void testDelete() throws SvcLogicException {
41 SvcLogicContext ctx = new SvcLogicContext();
43 Map<String, String> p = new HashMap<String, String>();
44 p.put("restapiUrl", "https://echo.getpostman.com/delete");
45 p.put("restapiUser", "user1");
46 p.put("restapiPassword", "pwd1");
47 p.put("httpMethod", "delete");
48 p.put("skipSending", "true");
50 RestapiCallNode rcn = new RestapiCallNode();
51 rcn.sendRequest(p, ctx);
55 public void testJsonTemplate() throws SvcLogicException {
56 SvcLogicContext ctx = new SvcLogicContext();
57 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
58 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
59 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
60 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
61 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
62 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
63 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
64 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
65 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
66 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
67 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
68 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
69 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
70 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
71 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
72 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
73 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
74 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
75 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
76 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
77 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
78 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
80 Map<String, String> p = new HashMap<String, String>();
81 p.put("templateFileName", "src/test/resources/test-template.json");
82 p.put("restapiUrl", "http://echo.getpostman.com");
83 p.put("restapiUser", "user1");
84 p.put("restapiPassword", "abc123");
85 p.put("format", "json");
86 p.put("httpMethod", "post");
87 p.put("responsePrefix", "response");
88 p.put("skipSending", "true");
90 RestapiCallNode rcn = new RestapiCallNode();
91 rcn.sendRequest(p, ctx);
94 @Test(expected = SvcLogicException.class)
95 public void testInvalidRepeatTimes() throws SvcLogicException {
96 SvcLogicContext ctx = new SvcLogicContext();
97 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
98 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
99 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
100 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
101 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
102 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
103 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
104 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
106 Map<String, String> p = new HashMap<String, String>();
107 p.put("templateFileName", "src/test/resources/test-template.json");
108 p.put("restapiUrl", "http://echo.getpostman.com");
109 p.put("restapiUser", "user1");
110 p.put("restapiPassword", "abc123");
111 p.put("format", "json");
112 p.put("httpMethod", "post");
113 p.put("responsePrefix", "response");
114 p.put("skipSending", "true");
116 RestapiCallNode rcn = new RestapiCallNode();
117 rcn.sendRequest(p, ctx);
120 @Test(expected = SvcLogicException.class)
121 public void testInvalidTemplatePath() throws SvcLogicException {
122 SvcLogicContext ctx = new SvcLogicContext();
123 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
124 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
125 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
126 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
127 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
128 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
129 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
130 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
132 Map<String, String> p = new HashMap<String, String>();
133 p.put("templateFileName", "src/test/resourcess/test-template.json");
134 p.put("restapiUrl", "http://echo.getpostman.com");
135 p.put("restapiUser", "user1");
136 p.put("restapiPassword", "abc123");
137 p.put("format", "json");
138 p.put("httpMethod", "post");
139 p.put("responsePrefix", "response");
140 p.put("skipSending", "true");
142 RestapiCallNode rcn = new RestapiCallNode();
143 rcn.sendRequest(p, ctx);
146 @Test(expected = SvcLogicException.class)
147 public void testWithoutSkipSending() throws SvcLogicException {
148 SvcLogicContext ctx = new SvcLogicContext();
149 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
150 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
151 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
152 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
153 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
154 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
155 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
156 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
158 Map<String, String> p = new HashMap<String, String>();
159 p.put("templateFileName", "src/test/resources/test-template.json");
160 p.put("restapiUrl", "http://echo.getpostman.com");
161 p.put("restapiUser", "user1");
162 p.put("restapiPassword", "abc123");
163 p.put("format", "json");
164 p.put("httpMethod", "post");
165 p.put("responsePrefix", "response");
166 p.put("skipSending", "false");
168 RestapiCallNode rcn = new RestapiCallNode();
169 rcn.sendRequest(p, ctx);
173 @Test(expected = SvcLogicException.class)
174 public void testWithInvalidURI() throws SvcLogicException {
175 SvcLogicContext ctx = new SvcLogicContext();
176 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
177 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
178 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
179 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
180 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
181 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
182 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
183 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
185 Map<String, String> p = new HashMap<String, String>();
186 p.put("templateFileName", "src/test/resources/test-template.json");
187 p.put("restapiUrl", "http://echo. getpostman.com");
188 p.put("restapiUser", "user1");
189 p.put("restapiPassword", "abc123");
190 p.put("format", "json");
191 p.put("httpMethod", "post");
192 p.put("responsePrefix", "response");
193 p.put("skipSending", "false");
195 RestapiCallNode rcn = new RestapiCallNode();
196 rcn.sendRequest(p, ctx);
200 public void testVpnJsonTemplate() throws SvcLogicException {
201 SvcLogicContext ctx = new SvcLogicContext();
202 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
203 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
205 Map<String, String> p = new HashMap<String, String>();
206 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
207 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
208 p.put("restapiUser", "admin");
209 p.put("restapiPassword", "admin123");
210 p.put("format", "json");
211 p.put("httpMethod", "post");
212 p.put("responsePrefix", "restapi-result");
213 p.put("skipSending", "true");
215 RestapiCallNode rcn = new RestapiCallNode();
216 rcn.sendRequest(p, ctx);
220 public void testSiteJsonTemplate() throws SvcLogicException {
221 SvcLogicContext ctx = new SvcLogicContext();
222 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
223 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
225 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
226 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
227 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
228 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
229 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
230 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
231 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
232 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
233 ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
234 ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
235 ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
236 ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
238 ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
239 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
240 ctx.setAttribute("prop.l3vpn.entry2-id", "1");
241 ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
242 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
243 ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
244 ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
245 ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
246 ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
247 ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
248 ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
249 ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
251 Map<String, String> p = new HashMap<String, String>();
252 p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
253 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
254 p.put("restapiUser", "admin");
255 p.put("restapiPassword", "admin123");
256 p.put("format", "json");
257 p.put("httpMethod", "post");
258 p.put("responsePrefix", "restapi-result");
259 p.put("skipSending", "true");
261 RestapiCallNode rcn = new RestapiCallNode();
262 rcn.sendRequest(p, ctx);
266 public void testVrfJsonTemplate() throws SvcLogicException {
267 SvcLogicContext ctx = new SvcLogicContext();
268 ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
269 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
270 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
271 ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
272 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
273 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
275 Map<String, String> p = new HashMap<String, String>();
276 p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
277 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
278 p.put("restapiUser", "admin");
279 p.put("restapiPassword", "admin123");
280 p.put("format", "json");
281 p.put("httpMethod", "post");
282 p.put("responsePrefix", "restapi-result");
283 p.put("skipSending", "true");
285 RestapiCallNode rcn = new RestapiCallNode();
286 rcn.sendRequest(p, ctx);
290 public void testDeleteVpnJsonTemplate() throws SvcLogicException {
291 SvcLogicContext ctx = new SvcLogicContext();
292 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
293 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
295 Map<String, String> p = new HashMap<String, String>();
296 //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
297 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
298 + "/vpnservice=10000000-0000-0000-0000-000000000001");
299 p.put("restapiUser", "admin");
300 p.put("restapiPassword", "admin123");
301 p.put("format", "json");
302 p.put("httpMethod", "delete");
303 p.put("responsePrefix", "restapi-result");
304 p.put("skipSending", "true");
306 RestapiCallNode rcn = new RestapiCallNode();
307 rcn.sendRequest(p, ctx);
311 public void testL2DciTemplate() throws SvcLogicException {
312 SvcLogicContext ctx = new SvcLogicContext();
313 ctx.setAttribute("prop.dci-connects.id", "Id1");
314 ctx.setAttribute("prop.dci-connects.name", "Name1");
315 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
316 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
317 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
318 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
319 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
320 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
321 ctx.setAttribute("prop.dci-connects.vni", "1");
323 Map<String, String> p = new HashMap<String, String>();
324 p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
325 p.put("restapiUrl", "http://echo.getpostman.com");
326 p.put("restapiUser", "user1");
327 p.put("restapiPassword", "abc123");
328 p.put("format", "json");
329 p.put("httpMethod", "post");
330 p.put("responsePrefix", "response");
331 p.put("skipSending", "true");
333 RestapiCallNode rcn = new RestapiCallNode();
334 rcn.sendRequest(p, ctx);
338 public void testL3DciTemplate() throws SvcLogicException {
339 SvcLogicContext ctx = new SvcLogicContext();
340 ctx.setAttribute("prop.dci-connects.id", "Id1");
341 ctx.setAttribute("prop.dci-connects.name", "Name1");
342 ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
343 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
344 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
345 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
346 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
347 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
348 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
349 ctx.setAttribute("prop.dci-connects.vni", "1");
351 Map<String, String> p = new HashMap<String, String>();
352 p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
353 p.put("restapiUrl", "http://echo.getpostman.com");
354 p.put("restapiUser", "user1");
355 p.put("restapiPassword", "abc123");
356 p.put("format", "json");
357 p.put("httpMethod", "post");
358 p.put("responsePrefix", "response");
359 p.put("skipSending", "true");
361 RestapiCallNode rcn = new RestapiCallNode();
362 rcn.sendRequest(p, ctx);
367 public void testControllerTokenTemplate() throws SvcLogicException {
368 SvcLogicContext ctx = new SvcLogicContext();
369 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
370 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
372 Map<String, String> p = new HashMap<String, String>();
373 p.put("templateFileName", "src/test/resources/actokentemplate.json");
374 p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
375 p.put("format", "json");
376 p.put("httpMethod", "post");
377 p.put("responsePrefix", "restapi-result");
378 p.put("skipSending", "true");
380 RestapiCallNode rcn = new RestapiCallNode();
381 rcn.sendRequest(p, ctx);