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;
25 import java.util.HashMap;
28 import org.glassfish.grizzly.http.server.HttpServer;
29 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
30 import org.glassfish.jersey.media.multipart.MultiPartFeature;
31 import org.junit.Test;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
35 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory;
37 import org.glassfish.jersey.server.ResourceConfig;
39 import static org.hamcrest.MatcherAssert.assertThat;
40 import static org.hamcrest.core.Is.is;
42 public class TestRestapiCallNode {
44 private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
48 public void testDelete() throws SvcLogicException {
49 SvcLogicContext ctx = new SvcLogicContext();
51 Map<String, String> p = new HashMap<String, String>();
52 p.put("restapiUrl", "https://echo.getpostman.com/delete");
53 p.put("restapiUser", "user1");
54 p.put("restapiPassword", "pwd1");
55 p.put("httpMethod", "delete");
56 p.put("skipSending", "true");
58 RestapiCallNode rcn = new RestapiCallNode();
59 rcn.sendRequest(p, ctx);
63 public void testJsonSdwanVpnTopologyTemplate() throws SvcLogicException {
64 SvcLogicContext ctx = new SvcLogicContext();
66 ctx.setAttribute("prop.topology", "topoType");
68 ctx.setAttribute("prop.roles_length", "1");
69 ctx.setAttribute("prop.roles[0]", "role1");
71 ctx.setAttribute("prop.siteAttachement_length", "2");
73 ctx.setAttribute("prop.siteAttachement[0].siteId", "site1");
74 ctx.setAttribute("prop.siteAttachement[0].roles_length", "0");
75 ctx.setAttribute("prop.siteAttachement[0].roles[0]", "role1");
76 ctx.setAttribute("prop.siteAttachement[0].roles[1]", "role3");
78 ctx.setAttribute("prop.siteAttachement[1].siteId", "site2");
79 ctx.setAttribute("prop.siteAttachement[1].roles_length", "1");
80 ctx.setAttribute("prop.siteAttachement[1].roles[0]", "role2");
82 Map<String, String> p = new HashMap<String, String>();
83 p.put("templateFileName", "src/test/resources/sdwan-vpn-topology.json");
84 p.put("restapiUrl", "http://echo.getpostman.com");
85 p.put("restapiUser", "user1");
86 p.put("restapiPassword", "abc123");
87 p.put("format", "json");
88 p.put("httpMethod", "post");
89 p.put("responsePrefix", "response");
90 p.put("skipSending", "true");
92 RestapiCallNode rcn = new RestapiCallNode();
93 rcn.sendRequest(p, ctx);
97 public void testJsonSdwanSiteTemplate() throws SvcLogicException {
98 SvcLogicContext ctx = new SvcLogicContext();
100 ctx.setAttribute("prop.name", "site1");
103 Map<String, String> p = new HashMap<String, String>();
104 p.put("templateFileName", "src/test/resources/sdwan-site.json");
105 p.put("restapiUrl", "http://echo.getpostman.com");
106 p.put("restapiUser", "user1");
107 p.put("restapiPassword", "abc123");
108 p.put("format", "json");
109 p.put("httpMethod", "post");
110 p.put("responsePrefix", "response");
111 p.put("skipSending", "true");
113 RestapiCallNode rcn = new RestapiCallNode();
114 rcn.sendRequest(p, ctx);
118 public void testJsonTemplate() throws SvcLogicException {
119 SvcLogicContext ctx = new SvcLogicContext();
120 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
121 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
122 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
123 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
124 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
125 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
126 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
127 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
128 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
129 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
130 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
131 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
132 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
133 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
134 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
135 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
136 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
137 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
138 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
139 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
140 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
141 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
143 Map<String, String> p = new HashMap<String, String>();
144 p.put("templateFileName", "src/test/resources/test-template.json");
145 p.put("restapiUrl", "http://echo.getpostman.com");
146 p.put("restapiUser", "user1");
147 p.put("restapiPassword", "abc123");
148 p.put("format", "json");
149 p.put("httpMethod", "post");
150 p.put("responsePrefix", "response");
151 p.put("skipSending", "true");
153 RestapiCallNode rcn = new RestapiCallNode();
154 rcn.sendRequest(p, ctx);
158 public void testInvalidRepeatTimes() throws SvcLogicException {
159 SvcLogicContext ctx = new SvcLogicContext();
160 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
161 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
162 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
163 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
164 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
165 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
166 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
167 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
169 Map<String, String> p = new HashMap<String, String>();
170 p.put("templateFileName", "src/test/resources/test-template.json");
171 p.put("restapiUrl", "http://echo.getpostman.com");
172 p.put("restapiUser", "user1");
173 p.put("restapiPassword", "abc123");
174 p.put("format", "json");
175 p.put("httpMethod", "post");
176 p.put("responsePrefix", "response");
177 p.put("skipSending", "true");
179 RestapiCallNode rcn = new RestapiCallNode();
180 rcn.sendRequest(p, ctx);
183 @Test(expected = SvcLogicException.class)
184 public void testInvalidTemplatePath() throws SvcLogicException {
185 SvcLogicContext ctx = new SvcLogicContext();
186 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
187 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
188 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
189 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
190 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
191 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
192 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
193 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
195 Map<String, String> p = new HashMap<String, String>();
196 p.put("templateFileName", "src/test/resourcess/test-template.json");
197 p.put("restapiUrl", "http://echo.getpostman.com");
198 p.put("restapiUser", "user1");
199 p.put("restapiPassword", "abc123");
200 p.put("format", "json");
201 p.put("httpMethod", "post");
202 p.put("responsePrefix", "response");
203 p.put("skipSending", "true");
205 RestapiCallNode rcn = new RestapiCallNode();
206 rcn.sendRequest(p, ctx);
209 @Test(expected = SvcLogicException.class)
210 public void testWithoutSkipSending() throws SvcLogicException {
211 SvcLogicContext ctx = new SvcLogicContext();
212 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
213 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
214 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
215 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
216 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
217 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
218 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
219 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
221 Map<String, String> p = new HashMap<String, String>();
222 p.put("templateFileName", "src/test/resources/test-template.json");
223 p.put("restapiUrl", "http://echo.getpostman.com");
224 p.put("restapiUser", "user1");
225 p.put("restapiPassword", "abc123");
226 p.put("format", "json");
227 p.put("httpMethod", "post");
228 p.put("responsePrefix", "response");
229 p.put("skipSending", "false");
231 RestapiCallNode rcn = new RestapiCallNode();
232 rcn.sendRequest(p, ctx);
235 @Test(expected = SvcLogicException.class)
236 public void testFormData() throws SvcLogicException {
237 SvcLogicContext ctx = new SvcLogicContext();
238 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
239 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
240 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
241 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
242 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
243 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
244 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
245 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
247 Map<String, String> p = new HashMap<String, String>();
248 p.put("templateFileName", "src/test/resources/test-template.json");
249 p.put("restapiUrl", "http://echo.getpostman.com");
250 p.put("restapiUser", "user1");
251 p.put("restapiPassword", "abc123");
252 p.put("format", "json");
253 p.put("httpMethod", "post");
254 p.put("responsePrefix", "response");
255 p.put("skipSending", "false");
256 p.put("multipartFormData", "true");
257 p.put("multipartFile", "src/test/resources/test-template.json");
259 RestapiCallNode rcn = new RestapiCallNode();
260 rcn.sendRequest(p, ctx);
263 @Test(expected = SvcLogicException.class)
264 public void testWithInvalidURI() throws SvcLogicException {
265 SvcLogicContext ctx = new SvcLogicContext();
266 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
267 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
268 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
269 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
270 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
271 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
272 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
273 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
275 Map<String, String> p = new HashMap<String, String>();
276 p.put("templateFileName", "src/test/resources/test-template.json");
277 p.put("restapiUrl", "http://echo. getpostman.com");
278 p.put("restapiUser", "user1");
279 p.put("restapiPassword", "abc123");
280 p.put("format", "json");
281 p.put("httpMethod", "post");
282 p.put("responsePrefix", "response");
283 p.put("skipSending", "false");
285 RestapiCallNode rcn = new RestapiCallNode();
286 rcn.sendRequest(p, ctx);
290 public void testVpnJsonTemplate() 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 p.put("restapiUser", "admin");
299 p.put("restapiPassword", "admin123");
300 p.put("format", "json");
301 p.put("httpMethod", "post");
302 p.put("responsePrefix", "restapi-result");
303 p.put("skipSending", "true");
305 RestapiCallNode rcn = new RestapiCallNode();
306 rcn.sendRequest(p, ctx);
310 public void testSiteJsonTemplate() throws SvcLogicException {
311 SvcLogicContext ctx = new SvcLogicContext();
312 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
313 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
315 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
316 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
317 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
318 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
319 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
320 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
321 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
322 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
323 ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
324 ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
325 ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
326 ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
328 ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
329 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
330 ctx.setAttribute("prop.l3vpn.entry2-id", "1");
331 ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
332 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
333 ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
334 ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
335 ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
336 ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
337 ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
338 ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
339 ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
341 Map<String, String> p = new HashMap<String, String>();
342 p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
343 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
344 p.put("restapiUser", "admin");
345 p.put("restapiPassword", "admin123");
346 p.put("format", "json");
347 p.put("httpMethod", "post");
348 p.put("responsePrefix", "restapi-result");
349 p.put("skipSending", "true");
351 RestapiCallNode rcn = new RestapiCallNode();
352 rcn.sendRequest(p, ctx);
356 public void testVrfJsonTemplate() throws SvcLogicException {
357 SvcLogicContext ctx = new SvcLogicContext();
358 ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
359 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
360 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
361 ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
362 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
363 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
365 Map<String, String> p = new HashMap<String, String>();
366 p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
367 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
368 p.put("restapiUser", "admin");
369 p.put("restapiPassword", "admin123");
370 p.put("format", "json");
371 p.put("httpMethod", "post");
372 p.put("responsePrefix", "restapi-result");
373 p.put("skipSending", "true");
375 RestapiCallNode rcn = new RestapiCallNode();
376 rcn.sendRequest(p, ctx);
380 public void testDeleteVpnJsonTemplate() throws SvcLogicException {
381 SvcLogicContext ctx = new SvcLogicContext();
382 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
383 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
385 Map<String, String> p = new HashMap<String, String>();
386 //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
387 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
388 + "/vpnservice=10000000-0000-0000-0000-000000000001");
389 p.put("restapiUser", "admin");
390 p.put("restapiPassword", "admin123");
391 p.put("format", "json");
392 p.put("httpMethod", "delete");
393 p.put("responsePrefix", "restapi-result");
394 p.put("skipSending", "true");
396 RestapiCallNode rcn = new RestapiCallNode();
397 rcn.sendRequest(p, ctx);
401 public void testL2DciTemplate() throws SvcLogicException {
402 SvcLogicContext ctx = new SvcLogicContext();
403 ctx.setAttribute("prop.dci-connects.id", "Id1");
404 ctx.setAttribute("prop.dci-connects.name", "Name1");
405 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
406 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
407 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
408 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
409 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
410 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
411 ctx.setAttribute("prop.dci-connects.vni", "1");
413 Map<String, String> p = new HashMap<String, String>();
414 p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
415 p.put("restapiUrl", "http://echo.getpostman.com");
416 p.put("restapiUser", "user1");
417 p.put("restapiPassword", "abc123");
418 p.put("format", "json");
419 p.put("httpMethod", "post");
420 p.put("responsePrefix", "response");
421 p.put("skipSending", "true");
423 RestapiCallNode rcn = new RestapiCallNode();
424 rcn.sendRequest(p, ctx);
428 public void testL3DciTemplate() throws SvcLogicException {
429 SvcLogicContext ctx = new SvcLogicContext();
430 ctx.setAttribute("prop.dci-connects.id", "Id1");
431 ctx.setAttribute("prop.dci-connects.name", "Name1");
432 ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
433 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
434 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
435 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
436 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
437 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
438 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
439 ctx.setAttribute("prop.dci-connects.vni", "1");
441 Map<String, String> p = new HashMap<String, String>();
442 p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
443 p.put("restapiUrl", "http://echo.getpostman.com");
444 p.put("restapiUser", "user1");
445 p.put("restapiPassword", "abc123");
446 p.put("format", "json");
447 p.put("httpMethod", "post");
448 p.put("responsePrefix", "response");
449 p.put("skipSending", "true");
451 RestapiCallNode rcn = new RestapiCallNode();
452 rcn.sendRequest(p, ctx);
457 public void testControllerTokenTemplate() throws SvcLogicException {
458 SvcLogicContext ctx = new SvcLogicContext();
459 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
460 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
462 Map<String, String> p = new HashMap<String, String>();
463 p.put("templateFileName", "src/test/resources/actokentemplate.json");
464 p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
465 p.put("format", "json");
466 p.put("httpMethod", "post");
467 p.put("responsePrefix", "restapi-result");
468 p.put("skipSending", "true");
470 RestapiCallNode rcn = new RestapiCallNode();
471 rcn.sendRequest(p, ctx);
476 public void testDeleteNoneAsContentType() throws SvcLogicException {
477 SvcLogicContext ctx = new SvcLogicContext();
479 Map<String, String> p = new HashMap<String, String>();
480 p.put("restapiUrl", "https://echo.getpostman.com/delete");
481 p.put("restapiUser", "user1");
482 p.put("restapiPassword", "pwd1");
483 p.put("httpMethod", "delete");
484 p.put("format", "none");
485 p.put("skipSending", "true");
487 RestapiCallNode rcn = new RestapiCallNode();
488 rcn.sendRequest(p, ctx);
492 public void testPostNoneAsContentType() throws SvcLogicException {
493 SvcLogicContext ctx = new SvcLogicContext();
494 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
495 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
497 Map<String, String> p = new HashMap<String, String>();
498 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
499 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
500 p.put("restapiUser", "admin");
501 p.put("restapiPassword", "admin123");
502 p.put("format", "none");
503 p.put("httpMethod", "post");
504 p.put("responsePrefix", "restapi-result");
505 p.put("skipSending", "true");
507 RestapiCallNode rcn = new RestapiCallNode();
508 rcn.sendRequest(p, ctx);
512 public void testDeleteOAuthType() throws SvcLogicException {
513 SvcLogicContext ctx = new SvcLogicContext();
515 Map<String, String> p = new HashMap<String, String>();
516 p.put("restapiUrl", "https://echo.getpostman.com/delete");
517 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
518 p.put("oAuthConsumerSecret", "secret");
519 p.put("oAuthSignatureMethod", "plainTEXT");
520 p.put("oAuthVersion", "1.0");
521 p.put("httpMethod", "delete");
522 p.put("format", "none");
523 p.put("skipSending", "true");
525 RestapiCallNode rcn = new RestapiCallNode();
526 rcn.sendRequest(p, ctx);
530 public void testDeleteAuthTypeBasic() throws SvcLogicException {
531 SvcLogicContext ctx = new SvcLogicContext();
533 Map<String, String> p = new HashMap<String, String>();
534 p.put("restapiUrl", "https://echo.getpostman.com/delete");
535 p.put("authType", "basic");
536 p.put("restapiUser", "admin");
537 p.put("restapiPassword", "admin123");
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 testDeleteAuthTypeDigest() throws SvcLogicException {
548 SvcLogicContext ctx = new SvcLogicContext();
550 Map<String, String> p = new HashMap<String, String>();
551 p.put("restapiUrl", "https://echo.getpostman.com/delete");
552 p.put("authType", "digest");
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 testDeleteAuthTypeOAuth() throws SvcLogicException {
565 SvcLogicContext ctx = new SvcLogicContext();
567 Map<String, String> p = new HashMap<String, String>();
568 p.put("restapiUrl", "https://echo.getpostman.com/delete");
569 p.put("authType", "oauth");
570 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
571 p.put("oAuthConsumerSecret", "secret");
572 p.put("oAuthSignatureMethod", "plainTEXT");
573 p.put("oAuthVersion", "1.0");
574 p.put("httpMethod", "delete");
575 p.put("format", "none");
576 p.put("skipSending", "true");
578 RestapiCallNode rcn = new RestapiCallNode();
579 rcn.sendRequest(p, ctx);
583 public void testDeleteAuthTypeNoneOAuth() throws SvcLogicException {
584 SvcLogicContext ctx = new SvcLogicContext();
586 Map<String, String> p = new HashMap<String, String>();
587 p.put("restapiUrl", "https://echo.getpostman.com/delete");
588 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
589 p.put("oAuthConsumerSecret", "secret");
590 p.put("oAuthSignatureMethod", "plainTEXT");
591 p.put("oAuthVersion", "1.0");
592 p.put("httpMethod", "delete");
593 p.put("format", "none");
594 p.put("skipSending", "true");
596 RestapiCallNode rcn = new RestapiCallNode();
597 rcn.sendRequest(p, ctx);
600 public void testDeleteAuthTypeNoneBasic() throws SvcLogicException {
601 SvcLogicContext ctx = new SvcLogicContext();
603 Map<String, String> p = new HashMap<String, String>();
604 p.put("restapiUrl", "https://echo.getpostman.com/delete");
605 p.put("restapiUser", "admin");
606 p.put("restapiPassword", "admin123");
607 p.put("httpMethod", "delete");
608 p.put("format", "none");
609 p.put("skipSending", "true");
611 RestapiCallNode rcn = new RestapiCallNode();
612 rcn.sendRequest(p, ctx);
615 @Test(expected = SvcLogicException.class)
616 public void testInvalidDeleteAuthTypeOAuth() throws SvcLogicException {
617 SvcLogicContext ctx = new SvcLogicContext();
619 Map<String, String> p = new HashMap<String, String>();
620 p.put("restapiUrl", "https://echo.getpostman.com/delete");
621 p.put("authType", "oauth");
622 p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
623 p.put("oAuthConsumerSecret", "secret");
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 testInvalidDeleteAuthTypeBasic() throws SvcLogicException {
634 SvcLogicContext ctx = new SvcLogicContext();
636 Map<String, String> p = new HashMap<String, String>();
637 p.put("restapiUrl", "https://echo.getpostman.com/delete");
638 p.put("authType", "basic");
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 testInvalidDeleteAuthTypeDigest() throws SvcLogicException {
651 SvcLogicContext ctx = new SvcLogicContext();
653 Map<String, String> p = new HashMap<String, String>();
654 p.put("restapiUrl", "https://echo.getpostman.com/delete");
655 p.put("authType", "digest");
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);
667 public void testMultipartFormData() throws SvcLogicException {
668 final ResourceConfig resourceConfig = new ResourceConfig(
669 MultipartServerMock.class, MultiPartFeature.class);
670 HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
671 URI.create("http://localhost:8080/"),resourceConfig);
673 Map<String, String> p = new HashMap<>();
674 p.put("multipartFormData", "true");
675 p.put("format", "none");
676 p.put("multipartFile", "src/test/resources/test-template.json");
677 p.put("restapiUrl", "http://localhost:8080/file-upload/upload");
679 SvcLogicContext ctx = new SvcLogicContext();
680 RestapiCallNode rcn = new RestapiCallNode();
681 rcn.sendRequest(p, ctx);
682 assertThat(ctx.getAttribute("response-code"), is("200"));
683 assertThat(ctx.getAttribute("httpResponse"), is( "test-template.json"));
684 server.shutdownNow();
688 public void testCookieResponse() throws SvcLogicException {
689 final ResourceConfig resourceConfig = new ResourceConfig(
690 MockCookieAuthServer.class);
691 HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
692 URI.create("http://localhost:8080/"),resourceConfig);
694 Map<String, String> p = new HashMap<>();
695 p.put("format", "none");
696 p.put("httpMethod", "get");
697 p.put("restapiUrl", "http://localhost:8080/get-cookie/cookie");
698 p.put("dumpHeaders", "true");
700 SvcLogicContext ctx = new SvcLogicContext();
701 RestapiCallNode rcn = new RestapiCallNode();
702 rcn.sendRequest(p, ctx);
703 assertThat(ctx.getAttribute("response-code"), is("200"));
704 assertThat(ctx.getAttribute("header.Set-Cookie"), is("cookieResponse=cookieValueInReturn;Version=1"));
705 server.shutdownNow();