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 static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.core.Is.is;
27 import java.util.HashMap;
29 import org.glassfish.grizzly.http.server.HttpServer;
30 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
31 import org.glassfish.jersey.media.multipart.MultiPartFeature;
32 import org.glassfish.jersey.server.ResourceConfig;
33 import org.junit.Test;
34 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
36 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class TestRestapiCallNode {
42 private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
46 public void testDelete() throws SvcLogicException {
47 SvcLogicContext ctx = new SvcLogicContext();
49 Map<String, String> p = new HashMap<>();
50 p.put("restapiUrl", "https://echo.getpostman.com/delete");
51 p.put("restapiUser", "user1");
52 p.put("restapiPassword", "pwd1");
53 p.put("httpMethod", "delete");
54 p.put("skipSending", "true");
56 RestapiCallNode rcn = new RestapiCallNode();
57 rcn.sendRequest(p, ctx);
61 public void testDeleteWithPayload() throws SvcLogicException {
62 SvcLogicContext ctx = new SvcLogicContext();
64 ctx.setAttribute("prop.name", "site1");
67 Map<String, String> p = new HashMap<>();
68 p.put("templateFileName", "src/test/resources/sdwan-site.json");
69 p.put("restapiUrl", "https://echo.getpostman.com/delete");
70 p.put("restapiUser", "user1");
71 p.put("restapiPassword", "pwd1");
72 p.put("httpMethod", "delete");
73 p.put("skipSending", "true");
75 RestapiCallNode rcn = new RestapiCallNode();
76 rcn.sendRequest(p, ctx);
80 public void testJsonSdwanVpnTopologyTemplate() throws SvcLogicException {
81 SvcLogicContext ctx = new SvcLogicContext();
83 ctx.setAttribute("prop.topology", "topoType");
85 ctx.setAttribute("prop.roles_length", "1");
86 ctx.setAttribute("prop.roles[0]", "role1");
88 ctx.setAttribute("prop.siteAttachement_length", "2");
90 ctx.setAttribute("prop.siteAttachement[0].siteId", "site1");
91 ctx.setAttribute("prop.siteAttachement[0].roles_length", "0");
92 ctx.setAttribute("prop.siteAttachement[0].roles[0]", "role1");
93 ctx.setAttribute("prop.siteAttachement[0].roles[1]", "role3");
95 ctx.setAttribute("prop.siteAttachement[1].siteId", "site2");
96 ctx.setAttribute("prop.siteAttachement[1].roles_length", "1");
97 ctx.setAttribute("prop.siteAttachement[1].roles[0]", "role2");
99 Map<String, String> p = new HashMap<>();
100 p.put("templateFileName", "src/test/resources/sdwan-vpn-topology.json");
101 p.put("restapiUrl", "http://echo.getpostman.com");
102 p.put("restapiUser", "user1");
103 p.put("restapiPassword", "abc123");
104 p.put("format", "json");
105 p.put("httpMethod", "post");
106 p.put("responsePrefix", "response");
107 p.put("skipSending", "true");
109 RestapiCallNode rcn = new RestapiCallNode();
110 rcn.sendRequest(p, ctx);
114 public void testJsonSdwanSiteTemplate() throws SvcLogicException {
115 SvcLogicContext ctx = new SvcLogicContext();
117 ctx.setAttribute("prop.name", "site1");
120 Map<String, String> p = new HashMap<>();
121 p.put("templateFileName", "src/test/resources/sdwan-site.json");
122 p.put("restapiUrl", "http://echo.getpostman.com");
123 p.put("restapiUser", "user1");
124 p.put("restapiPassword", "abc123");
125 p.put("format", "json");
126 p.put("httpMethod", "post");
127 p.put("responsePrefix", "response");
128 p.put("skipSending", "true");
130 RestapiCallNode rcn = new RestapiCallNode();
131 rcn.sendRequest(p, ctx);
135 public void testJsonTemplate() throws SvcLogicException {
136 SvcLogicContext ctx = new SvcLogicContext();
137 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
138 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
139 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
140 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
141 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
142 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
143 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
144 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
145 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
146 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
147 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
148 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
149 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
150 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
151 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
152 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
153 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
154 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
155 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
156 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
157 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
158 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
160 Map<String, String> p = new HashMap<>();
161 p.put("templateFileName", "src/test/resources/test-template.json");
162 p.put("restapiUrl", "http://echo.getpostman.com");
163 p.put("restapiUser", "user1");
164 p.put("restapiPassword", "abc123");
165 p.put("format", "json");
166 p.put("httpMethod", "post");
167 p.put("responsePrefix", "response");
168 p.put("skipSending", "true");
170 RestapiCallNode rcn = new RestapiCallNode();
171 rcn.sendRequest(p, ctx);
175 public void testInvalidRepeatTimes() throws SvcLogicException {
176 SvcLogicContext ctx = new SvcLogicContext();
177 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
178 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
179 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
180 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
181 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
182 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
183 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
184 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
186 Map<String, String> p = new HashMap<>();
187 p.put("templateFileName", "src/test/resources/test-template.json");
188 p.put("restapiUrl", "http://echo.getpostman.com");
189 p.put("restapiUser", "user1");
190 p.put("restapiPassword", "abc123");
191 p.put("format", "json");
192 p.put("httpMethod", "post");
193 p.put("responsePrefix", "response");
194 p.put("skipSending", "true");
196 RestapiCallNode rcn = new RestapiCallNode();
197 rcn.sendRequest(p, ctx);
200 @Test(expected = SvcLogicException.class)
201 public void testInvalidTemplatePath() throws SvcLogicException {
202 SvcLogicContext ctx = new SvcLogicContext();
203 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
204 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
205 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
206 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
207 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
208 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
209 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
210 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
212 Map<String, String> p = new HashMap<>();
213 p.put("templateFileName", "src/test/resourcess/test-template.json");
214 p.put("restapiUrl", "http://echo.getpostman.com");
215 p.put("restapiUser", "user1");
216 p.put("restapiPassword", "abc123");
217 p.put("format", "json");
218 p.put("httpMethod", "post");
219 p.put("responsePrefix", "response");
220 p.put("skipSending", "true");
222 RestapiCallNode rcn = new RestapiCallNode();
223 rcn.sendRequest(p, ctx);
226 @Test(expected = SvcLogicException.class)
227 public void testWithoutSkipSending() throws SvcLogicException {
228 SvcLogicContext ctx = new SvcLogicContext();
229 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
230 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
231 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
232 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
233 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
234 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
235 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
236 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
238 Map<String, String> p = new HashMap<>();
239 p.put("templateFileName", "src/test/resources/test-template.json");
240 p.put("restapiUrl", "http://echo.getpostman.com");
241 p.put("restapiUser", "user1");
242 p.put("restapiPassword", "abc123");
243 p.put("format", "json");
244 p.put("httpMethod", "post");
245 p.put("responsePrefix", "response");
246 p.put("skipSending", "false");
248 RestapiCallNode rcn = new RestapiCallNode();
249 rcn.sendRequest(p, ctx);
252 @Test(expected = SvcLogicException.class)
253 public void testFormData() throws SvcLogicException {
254 SvcLogicContext ctx = new SvcLogicContext();
255 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
256 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
257 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
258 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
259 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
260 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
261 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
262 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
264 Map<String, String> p = new HashMap<>();
265 p.put("templateFileName", "src/test/resources/test-template.json");
266 p.put("restapiUrl", "http://echo.getpostman.com");
267 p.put("restapiUser", "user1");
268 p.put("restapiPassword", "abc123");
269 p.put("format", "json");
270 p.put("httpMethod", "post");
271 p.put("responsePrefix", "response");
272 p.put("skipSending", "false");
273 p.put("multipartFormData", "true");
274 p.put("multipartFile", "src/test/resources/test-template.json");
276 RestapiCallNode rcn = new RestapiCallNode();
277 rcn.sendRequest(p, ctx);
280 @Test(expected = SvcLogicException.class)
281 public void testWithInvalidURI() throws SvcLogicException {
282 SvcLogicContext ctx = new SvcLogicContext();
283 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
284 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
285 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
286 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
287 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
288 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
289 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
290 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
292 Map<String, String> p = new HashMap<>();
293 p.put("templateFileName", "src/test/resources/test-template.json");
294 p.put("restapiUrl", "http://echo. getpostman.com");
295 p.put("restapiUser", "user1");
296 p.put("restapiPassword", "abc123");
297 p.put("format", "json");
298 p.put("httpMethod", "post");
299 p.put("responsePrefix", "response");
300 p.put("skipSending", "false");
302 RestapiCallNode rcn = new RestapiCallNode();
303 rcn.sendRequest(p, ctx);
307 public void testVpnJsonTemplate() throws SvcLogicException {
308 SvcLogicContext ctx = new SvcLogicContext();
309 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
310 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
312 Map<String, String> p = new HashMap<>();
313 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
314 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
315 p.put("restapiUser", "admin");
316 p.put("restapiPassword", "admin123");
317 p.put("format", "json");
318 p.put("httpMethod", "post");
319 p.put("responsePrefix", "restapi-result");
320 p.put("skipSending", "true");
322 RestapiCallNode rcn = new RestapiCallNode();
323 rcn.sendRequest(p, ctx);
327 public void testSiteJsonTemplate() throws SvcLogicException {
328 SvcLogicContext ctx = new SvcLogicContext();
329 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
330 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
332 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
333 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
334 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
335 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
336 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
337 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
338 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
339 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
340 ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
341 ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
342 ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
343 ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
345 ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
346 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
347 ctx.setAttribute("prop.l3vpn.entry2-id", "1");
348 ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
349 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
350 ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
351 ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
352 ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
353 ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
354 ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
355 ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
356 ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
358 Map<String, String> p = new HashMap<>();
359 p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
360 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
361 p.put("restapiUser", "admin");
362 p.put("restapiPassword", "admin123");
363 p.put("format", "json");
364 p.put("httpMethod", "post");
365 p.put("responsePrefix", "restapi-result");
366 p.put("skipSending", "true");
368 RestapiCallNode rcn = new RestapiCallNode();
369 rcn.sendRequest(p, ctx);
373 public void testVrfJsonTemplate() throws SvcLogicException {
374 SvcLogicContext ctx = new SvcLogicContext();
375 ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
376 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
377 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
378 ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
379 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
380 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
382 Map<String, String> p = new HashMap<>();
383 p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
384 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
385 p.put("restapiUser", "admin");
386 p.put("restapiPassword", "admin123");
387 p.put("format", "json");
388 p.put("httpMethod", "post");
389 p.put("responsePrefix", "restapi-result");
390 p.put("skipSending", "true");
392 RestapiCallNode rcn = new RestapiCallNode();
393 rcn.sendRequest(p, ctx);
397 public void testDeleteVpnJsonTemplate() throws SvcLogicException {
398 SvcLogicContext ctx = new SvcLogicContext();
399 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
400 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
402 Map<String, String> p = new HashMap<>();
403 //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
404 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
405 + "/vpnservice=10000000-0000-0000-0000-000000000001");
406 p.put("restapiUser", "admin");
407 p.put("restapiPassword", "admin123");
408 p.put("format", "json");
409 p.put("httpMethod", "delete");
410 p.put("responsePrefix", "restapi-result");
411 p.put("skipSending", "true");
413 RestapiCallNode rcn = new RestapiCallNode();
414 rcn.sendRequest(p, ctx);
418 public void testL2DciTemplate() throws SvcLogicException {
419 SvcLogicContext ctx = new SvcLogicContext();
420 ctx.setAttribute("prop.dci-connects.id", "Id1");
421 ctx.setAttribute("prop.dci-connects.name", "Name1");
422 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
423 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
424 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
425 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
426 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
427 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
428 ctx.setAttribute("prop.dci-connects.vni", "1");
430 Map<String, String> p = new HashMap<>();
431 p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
432 p.put("restapiUrl", "http://echo.getpostman.com");
433 p.put("restapiUser", "user1");
434 p.put("restapiPassword", "abc123");
435 p.put("format", "json");
436 p.put("httpMethod", "post");
437 p.put("responsePrefix", "response");
438 p.put("skipSending", "true");
440 RestapiCallNode rcn = new RestapiCallNode();
441 rcn.sendRequest(p, ctx);
445 public void testL3DciTemplate() throws SvcLogicException {
446 SvcLogicContext ctx = new SvcLogicContext();
447 ctx.setAttribute("prop.dci-connects.id", "Id1");
448 ctx.setAttribute("prop.dci-connects.name", "Name1");
449 ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
450 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
451 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
452 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
453 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
454 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
455 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
456 ctx.setAttribute("prop.dci-connects.vni", "1");
458 Map<String, String> p = new HashMap<>();
459 p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
460 p.put("restapiUrl", "http://echo.getpostman.com");
461 p.put("restapiUser", "user1");
462 p.put("restapiPassword", "abc123");
463 p.put("format", "json");
464 p.put("httpMethod", "post");
465 p.put("responsePrefix", "response");
466 p.put("skipSending", "true");
468 RestapiCallNode rcn = new RestapiCallNode();
469 rcn.sendRequest(p, ctx);
474 public void testControllerTokenTemplate() throws SvcLogicException {
475 SvcLogicContext ctx = new SvcLogicContext();
476 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
477 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
479 Map<String, String> p = new HashMap<>();
480 p.put("templateFileName", "src/test/resources/actokentemplate.json");
481 p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
482 p.put("format", "json");
483 p.put("httpMethod", "post");
484 p.put("responsePrefix", "restapi-result");
485 p.put("skipSending", "true");
487 RestapiCallNode rcn = new RestapiCallNode();
488 rcn.sendRequest(p, ctx);
493 public void testDeleteNoneAsContentType() throws SvcLogicException {
494 SvcLogicContext ctx = new SvcLogicContext();
496 Map<String, String> p = new HashMap<>();
497 p.put("restapiUrl", "https://echo.getpostman.com/delete");
498 p.put("restapiUser", "user1");
499 p.put("restapiPassword", "pwd1");
500 p.put("httpMethod", "delete");
501 p.put("format", "none");
502 p.put("skipSending", "true");
504 RestapiCallNode rcn = new RestapiCallNode();
505 rcn.sendRequest(p, ctx);
509 public void testPostNoneAsContentType() throws SvcLogicException {
510 SvcLogicContext ctx = new SvcLogicContext();
511 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
512 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
514 Map<String, String> p = new HashMap<>();
515 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
516 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
517 p.put("restapiUser", "admin");
518 p.put("restapiPassword", "admin123");
519 p.put("format", "none");
520 p.put("httpMethod", "post");
521 p.put("responsePrefix", "restapi-result");
522 p.put("skipSending", "true");
524 RestapiCallNode rcn = new RestapiCallNode();
525 rcn.sendRequest(p, ctx);
529 public void testDeleteOAuthType() throws SvcLogicException {
530 SvcLogicContext ctx = new SvcLogicContext();
532 Map<String, String> p = new HashMap<>();
533 p.put("restapiUrl", "https://echo.getpostman.com/delete");
534 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
535 p.put("oAuthConsumerSecret", "secret");
536 p.put("oAuthSignatureMethod", "plainTEXT");
537 p.put("oAuthVersion", "1.0");
538 p.put("httpMethod", "delete");
539 p.put("format", "none");
540 p.put("skipSending", "true");
542 RestapiCallNode rcn = new RestapiCallNode();
543 rcn.sendRequest(p, ctx);
547 public void testDeleteAuthTypeBasic() throws SvcLogicException {
548 SvcLogicContext ctx = new SvcLogicContext();
550 Map<String, String> p = new HashMap<>();
551 p.put("restapiUrl", "https://echo.getpostman.com/delete");
552 p.put("authType", "basic");
553 p.put("restapiUser", "admin");
554 p.put("restapiPassword", "admin123");
555 p.put("httpMethod", "delete");
556 p.put("format", "none");
557 p.put("skipSending", "true");
559 RestapiCallNode rcn = new RestapiCallNode();
560 rcn.sendRequest(p, ctx);
564 public void testDeleteAuthTypeDigest() throws SvcLogicException {
565 SvcLogicContext ctx = new SvcLogicContext();
567 Map<String, String> p = new HashMap<>();
568 p.put("restapiUrl", "https://echo.getpostman.com/delete");
569 p.put("authType", "digest");
570 p.put("restapiUser", "admin");
571 p.put("restapiPassword", "admin123");
572 p.put("httpMethod", "delete");
573 p.put("format", "none");
574 p.put("skipSending", "true");
576 RestapiCallNode rcn = new RestapiCallNode();
577 rcn.sendRequest(p, ctx);
581 public void testDeleteAuthTypeOAuth() throws SvcLogicException {
582 SvcLogicContext ctx = new SvcLogicContext();
584 Map<String, String> p = new HashMap<>();
585 p.put("restapiUrl", "https://echo.getpostman.com/delete");
586 p.put("authType", "oauth");
587 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
588 p.put("oAuthConsumerSecret", "secret");
589 p.put("oAuthSignatureMethod", "plainTEXT");
590 p.put("oAuthVersion", "1.0");
591 p.put("httpMethod", "delete");
592 p.put("format", "none");
593 p.put("skipSending", "true");
595 RestapiCallNode rcn = new RestapiCallNode();
596 rcn.sendRequest(p, ctx);
600 public void testDeleteAuthTypeNoneOAuth() throws SvcLogicException {
601 SvcLogicContext ctx = new SvcLogicContext();
603 Map<String, String> p = new HashMap<>();
604 p.put("restapiUrl", "https://echo.getpostman.com/delete");
605 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
606 p.put("oAuthConsumerSecret", "secret");
607 p.put("oAuthSignatureMethod", "plainTEXT");
608 p.put("oAuthVersion", "1.0");
609 p.put("httpMethod", "delete");
610 p.put("format", "none");
611 p.put("skipSending", "true");
613 RestapiCallNode rcn = new RestapiCallNode();
614 rcn.sendRequest(p, ctx);
617 public void testDeleteAuthTypeNoneBasic() throws SvcLogicException {
618 SvcLogicContext ctx = new SvcLogicContext();
620 Map<String, String> p = new HashMap<>();
621 p.put("restapiUrl", "https://echo.getpostman.com/delete");
622 p.put("restapiUser", "admin");
623 p.put("restapiPassword", "admin123");
624 p.put("httpMethod", "delete");
625 p.put("format", "none");
626 p.put("skipSending", "true");
628 RestapiCallNode rcn = new RestapiCallNode();
629 rcn.sendRequest(p, ctx);
632 @Test(expected = SvcLogicException.class)
633 public void testInvalidDeleteAuthTypeOAuth() throws SvcLogicException {
634 SvcLogicContext ctx = new SvcLogicContext();
636 Map<String, String> p = new HashMap<>();
637 p.put("restapiUrl", "https://echo.getpostman.com/delete");
638 p.put("authType", "oauth");
639 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
640 p.put("oAuthConsumerSecret", "secret");
641 p.put("httpMethod", "delete");
642 p.put("format", "none");
643 p.put("skipSending", "true");
645 RestapiCallNode rcn = new RestapiCallNode();
646 rcn.sendRequest(p, ctx);
649 @Test(expected = SvcLogicException.class)
650 public void testInvalidDeleteAuthTypeBasic() throws SvcLogicException {
651 SvcLogicContext ctx = new SvcLogicContext();
653 Map<String, String> p = new HashMap<>();
654 p.put("restapiUrl", "https://echo.getpostman.com/delete");
655 p.put("authType", "basic");
656 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
657 p.put("oAuthConsumerSecret", "secret");
658 p.put("httpMethod", "delete");
659 p.put("format", "none");
660 p.put("skipSending", "true");
662 RestapiCallNode rcn = new RestapiCallNode();
663 rcn.sendRequest(p, ctx);
666 @Test(expected = SvcLogicException.class)
667 public void testInvalidDeleteAuthTypeDigest() throws SvcLogicException {
668 SvcLogicContext ctx = new SvcLogicContext();
670 Map<String, String> p = new HashMap<>();
671 p.put("restapiUrl", "https://echo.getpostman.com/delete");
672 p.put("authType", "digest");
673 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
674 p.put("oAuthConsumerSecret", "secret");
675 p.put("httpMethod", "delete");
676 p.put("format", "none");
677 p.put("skipSending", "true");
679 RestapiCallNode rcn = new RestapiCallNode();
680 rcn.sendRequest(p, ctx);
684 public void testMultipartFormData() throws SvcLogicException {
685 final ResourceConfig resourceConfig = new ResourceConfig(
686 MultipartServerMock.class, MultiPartFeature.class);
687 HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
688 URI.create("http://localhost:8080/"),resourceConfig);
690 Map<String, String> p = new HashMap<>();
691 p.put("multipartFormData", "true");
692 p.put("format", "none");
693 p.put("multipartFile", "src/test/resources/test-template.json");
694 p.put("restapiUrl", "http://localhost:8080/file-upload/upload");
696 SvcLogicContext ctx = new SvcLogicContext();
697 RestapiCallNode rcn = new RestapiCallNode();
698 rcn.sendRequest(p, ctx);
699 assertThat(ctx.getAttribute("response-code"), is("200"));
700 assertThat(ctx.getAttribute("httpResponse"), is( "test-template.json"));
701 server.shutdownNow();
705 public void testCookieResponse() throws SvcLogicException {
706 final ResourceConfig resourceConfig = new ResourceConfig(
707 MockCookieAuthServer.class);
708 HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
709 URI.create("http://localhost:8080/"),resourceConfig);
711 Map<String, String> p = new HashMap<>();
712 p.put("format", "none");
713 p.put("httpMethod", "get");
714 p.put("restapiUrl", "http://localhost:8080/get-cookie/cookie");
715 p.put("dumpHeaders", "true");
717 SvcLogicContext ctx = new SvcLogicContext();
718 RestapiCallNode rcn = new RestapiCallNode();
719 rcn.sendRequest(p, ctx);
720 assertThat(ctx.getAttribute("response-code"), is("200"));
721 assertThat(ctx.getAttribute("header.Set-Cookie"), is("cookieResponse=cookieValueInReturn;Version=1"));
722 server.shutdownNow();