bdf67dc45a16ece3e3e9b04bd5f76a9d2e9bb557
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / test / java / org / onap / ccsdk / sli / plugins / restapicall / TestRestapiCallNode.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                      reserved.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.ccsdk.sli.plugins.restapicall;
23
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.core.Is.is;
26 import java.net.URI;
27 import java.util.HashMap;
28 import java.util.Map;
29 import org.codehaus.jettison.json.JSONObject;
30 import org.glassfish.grizzly.http.server.HttpServer;
31 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
32 import org.glassfish.jersey.media.multipart.MultiPartFeature;
33 import org.glassfish.jersey.server.ResourceConfig;
34 import org.junit.Test;
35 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
36 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
37 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 public class TestRestapiCallNode {
42
43     private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
44
45
46     @Test
47     public void testDelete() throws SvcLogicException {
48         SvcLogicContext ctx = new SvcLogicContext();
49
50         Map<String, String> p = new HashMap<>();
51         p.put("restapiUrl", "https://echo.getpostman.com/delete");
52         p.put("restapiUser", "user1");
53         p.put("restapiPassword", "pwd1");
54         p.put("httpMethod", "delete");
55         p.put("skipSending", "true");
56
57         RestapiCallNode rcn = new RestapiCallNode();
58         rcn.sendRequest(p, ctx);
59     }
60
61     @Test
62     public void testDeleteWithPayload() throws SvcLogicException {
63         SvcLogicContext ctx = new SvcLogicContext();
64
65         ctx.setAttribute("prop.name", "site1");
66
67
68         Map<String, String> p = new HashMap<>();
69         p.put("templateFileName", "src/test/resources/sdwan-site.json");
70         p.put("restapiUrl", "https://echo.getpostman.com/delete");
71         p.put("restapiUser", "user1");
72         p.put("restapiPassword", "pwd1");
73         p.put("httpMethod", "delete");
74         p.put("skipSending", "true");
75
76         RestapiCallNode rcn = new RestapiCallNode();
77         rcn.sendRequest(p, ctx);
78     }
79
80     @Test
81     public void testJsonSdwanVpnTopologyTemplate() throws SvcLogicException {
82         SvcLogicContext ctx = new SvcLogicContext();
83
84         ctx.setAttribute("prop.topology", "topoType");
85
86         ctx.setAttribute("prop.roles_length", "1");
87         ctx.setAttribute("prop.roles[0]", "role1");
88
89         ctx.setAttribute("prop.siteAttachement_length", "2");
90
91         ctx.setAttribute("prop.siteAttachement[0].siteId", "site1");
92         ctx.setAttribute("prop.siteAttachement[0].roles_length", "0");
93         ctx.setAttribute("prop.siteAttachement[0].roles[0]", "role1");
94         ctx.setAttribute("prop.siteAttachement[0].roles[1]", "role3");
95
96         ctx.setAttribute("prop.siteAttachement[1].siteId", "site2");
97         ctx.setAttribute("prop.siteAttachement[1].roles_length", "1");
98         ctx.setAttribute("prop.siteAttachement[1].roles[0]", "role2");
99
100         Map<String, String> p = new HashMap<>();
101         p.put("templateFileName", "src/test/resources/sdwan-vpn-topology.json");
102         p.put("restapiUrl", "http://echo.getpostman.com");
103         p.put("restapiUser", "user1");
104         p.put("restapiPassword", "abc123");
105         p.put("format", "json");
106         p.put("httpMethod", "post");
107         p.put("responsePrefix", "response");
108         p.put("skipSending", "true");
109
110         RestapiCallNode rcn = new RestapiCallNode();
111         rcn.sendRequest(p, ctx);
112     }
113
114     @Test
115     public void testJsonSdwanSiteTemplate() throws SvcLogicException {
116         SvcLogicContext ctx = new SvcLogicContext();
117
118         ctx.setAttribute("prop.name", "site1");
119
120
121         Map<String, String> p = new HashMap<>();
122         p.put("templateFileName", "src/test/resources/sdwan-site.json");
123         p.put("restapiUrl", "http://echo.getpostman.com");
124         p.put("restapiUser", "user1");
125         p.put("restapiPassword", "abc123");
126         p.put("format", "json");
127         p.put("httpMethod", "post");
128         p.put("responsePrefix", "response");
129         p.put("skipSending", "true");
130
131         RestapiCallNode rcn = new RestapiCallNode();
132         rcn.sendRequest(p, ctx);
133     }
134
135     @Test
136     public void testJsonTemplate() throws SvcLogicException {
137         SvcLogicContext ctx = new SvcLogicContext();
138         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
139         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
140         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
141         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
142         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
143         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
144         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
145         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
146         ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
147         ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
148         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
149         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
150         ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
151         ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
152         ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
153         ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
154         ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
155         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
156         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
157         ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
158         ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
159         ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
160
161         Map<String, String> p = new HashMap<>();
162         p.put("templateFileName", "src/test/resources/test-template.json");
163         p.put("restapiUrl", "http://echo.getpostman.com");
164         p.put("restapiUser", "user1");
165         p.put("restapiPassword", "abc123");
166         p.put("format", "json");
167         p.put("httpMethod", "post");
168         p.put("responsePrefix", "response");
169         p.put("skipSending", "true");
170
171         RestapiCallNode rcn = new RestapiCallNode();
172         rcn.sendRequest(p, ctx);
173     }
174
175     @Test
176     public void testInvalidRepeatTimes() throws SvcLogicException {
177         SvcLogicContext ctx = new SvcLogicContext();
178         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
179         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
180         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
181         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
182         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
183         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
184         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
185         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
186
187         Map<String, String> p = new HashMap<>();
188         p.put("templateFileName", "src/test/resources/test-template.json");
189         p.put("restapiUrl", "http://echo.getpostman.com");
190         p.put("restapiUser", "user1");
191         p.put("restapiPassword", "abc123");
192         p.put("format", "json");
193         p.put("httpMethod", "post");
194         p.put("responsePrefix", "response");
195         p.put("skipSending", "true");
196
197         RestapiCallNode rcn = new RestapiCallNode();
198         rcn.sendRequest(p, ctx);
199     }
200
201     @Test(expected = SvcLogicException.class)
202     public void testInvalidTemplatePath() throws SvcLogicException {
203         SvcLogicContext ctx = new SvcLogicContext();
204         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
205         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
206         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
207         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
208         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
209         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
210         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
211         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
212
213         Map<String, String> p = new HashMap<>();
214         p.put("templateFileName", "src/test/resourcess/test-template.json");
215         p.put("restapiUrl", "http://echo.getpostman.com");
216         p.put("restapiUser", "user1");
217         p.put("restapiPassword", "abc123");
218         p.put("format", "json");
219         p.put("httpMethod", "post");
220         p.put("responsePrefix", "response");
221         p.put("skipSending", "true");
222
223         RestapiCallNode rcn = new RestapiCallNode();
224         rcn.sendRequest(p, ctx);
225     }
226
227     @Test(expected = SvcLogicException.class)
228     public void testWithoutSkipSending() throws SvcLogicException {
229         SvcLogicContext ctx = new SvcLogicContext();
230         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
231         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
232         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
233         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
234         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
235         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
236         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
237         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
238
239         Map<String, String> p = new HashMap<>();
240         p.put("templateFileName", "src/test/resources/test-template.json");
241         p.put("restapiUrl", "http://echo.getpostman.com");
242         p.put("restapiUser", "user1");
243         p.put("restapiPassword", "abc123");
244         p.put("format", "json");
245         p.put("httpMethod", "post");
246         p.put("responsePrefix", "response");
247         p.put("skipSending", "false");
248
249         RestapiCallNode rcn = new RestapiCallNode();
250         rcn.sendRequest(p, ctx);
251     }
252
253     @Test(expected = SvcLogicException.class)
254     public void testFormData() throws SvcLogicException {
255         SvcLogicContext ctx = new SvcLogicContext();
256         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
257         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
258         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
259         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
260         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
261         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
262         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
263         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
264
265         Map<String, String> p = new HashMap<>();
266         p.put("templateFileName", "src/test/resources/test-template.json");
267         p.put("restapiUrl", "http://echo.getpostman.com");
268         p.put("restapiUser", "user1");
269         p.put("restapiPassword", "abc123");
270         p.put("format", "json");
271         p.put("httpMethod", "post");
272         p.put("responsePrefix", "response");
273         p.put("skipSending", "false");
274         p.put("multipartFormData", "true");
275         p.put("multipartFile", "src/test/resources/test-template.json");
276
277         RestapiCallNode rcn = new RestapiCallNode();
278         rcn.sendRequest(p, ctx);
279     }
280
281     @Test(expected = SvcLogicException.class)
282     public void testWithInvalidURI() throws SvcLogicException {
283         SvcLogicContext ctx = new SvcLogicContext();
284         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
285         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
286         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
287         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
288         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
289         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
290         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
291         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
292
293         Map<String, String> p = new HashMap<>();
294         p.put("templateFileName", "src/test/resources/test-template.json");
295         p.put("restapiUrl", "http://echo.  getpostman.com");
296         p.put("restapiUser", "user1");
297         p.put("restapiPassword", "abc123");
298         p.put("format", "json");
299         p.put("httpMethod", "post");
300         p.put("responsePrefix", "response");
301         p.put("skipSending", "false");
302
303         RestapiCallNode rcn = new RestapiCallNode();
304         rcn.sendRequest(p, ctx);
305     }
306
307     @Test
308     public void testVpnJsonTemplate() throws SvcLogicException {
309         SvcLogicContext ctx = new SvcLogicContext();
310         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
311         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
312
313         Map<String, String> p = new HashMap<>();
314         p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
315         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
316         p.put("restapiUser", "admin");
317         p.put("restapiPassword", "admin123");
318         p.put("format", "json");
319         p.put("httpMethod", "post");
320         p.put("responsePrefix", "restapi-result");
321         p.put("skipSending", "true");
322
323         RestapiCallNode rcn = new RestapiCallNode();
324         rcn.sendRequest(p, ctx);
325     }
326
327     @Test
328     public void testSiteJsonTemplate() throws SvcLogicException {
329         SvcLogicContext ctx = new SvcLogicContext();
330         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
331         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
332
333         ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
334         ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
335         ctx.setAttribute("prop.l3vpn.entry1-id", "1");
336         ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
337         ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
338         ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
339         ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
340         ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
341         ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
342         ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
343         ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
344         ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
345
346         ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
347         ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
348         ctx.setAttribute("prop.l3vpn.entry2-id", "1");
349         ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
350         ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
351         ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
352         ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
353         ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
354         ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
355         ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
356         ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
357         ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
358
359         Map<String, String> p = new HashMap<>();
360         p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
361         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
362         p.put("restapiUser", "admin");
363         p.put("restapiPassword", "admin123");
364         p.put("format", "json");
365         p.put("httpMethod", "post");
366         p.put("responsePrefix", "restapi-result");
367         p.put("skipSending", "true");
368
369         RestapiCallNode rcn = new RestapiCallNode();
370         rcn.sendRequest(p, ctx);
371     }
372
373     @Test
374     public void testVrfJsonTemplate() throws SvcLogicException {
375         SvcLogicContext ctx = new SvcLogicContext();
376         ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
377         ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
378         ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
379         ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
380         ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
381         ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
382
383         Map<String, String> p = new HashMap<>();
384         p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
385         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
386         p.put("restapiUser", "admin");
387         p.put("restapiPassword", "admin123");
388         p.put("format", "json");
389         p.put("httpMethod", "post");
390         p.put("responsePrefix", "restapi-result");
391         p.put("skipSending", "true");
392
393         RestapiCallNode rcn = new RestapiCallNode();
394         rcn.sendRequest(p, ctx);
395     }
396
397     @Test
398     public void testDeleteVpnJsonTemplate() throws SvcLogicException {
399         SvcLogicContext ctx = new SvcLogicContext();
400         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
401         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
402
403         Map<String, String> p = new HashMap<>();
404         //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
405         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
406             + "/vpnservice=10000000-0000-0000-0000-000000000001");
407         p.put("restapiUser", "admin");
408         p.put("restapiPassword", "admin123");
409         p.put("format", "json");
410         p.put("httpMethod", "delete");
411         p.put("responsePrefix", "restapi-result");
412         p.put("skipSending", "true");
413
414         RestapiCallNode rcn = new RestapiCallNode();
415         rcn.sendRequest(p, ctx);
416     }
417
418     @Test
419     public void testL2DciTemplate() throws SvcLogicException {
420         SvcLogicContext ctx = new SvcLogicContext();
421         ctx.setAttribute("prop.dci-connects.id", "Id1");
422         ctx.setAttribute("prop.dci-connects.name", "Name1");
423         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
424         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
425         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
426         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
427         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
428         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
429         ctx.setAttribute("prop.dci-connects.vni", "1");
430
431         Map<String, String> p = new HashMap<>();
432         p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
433         p.put("restapiUrl", "http://echo.getpostman.com");
434         p.put("restapiUser", "user1");
435         p.put("restapiPassword", "abc123");
436         p.put("format", "json");
437         p.put("httpMethod", "post");
438         p.put("responsePrefix", "response");
439         p.put("skipSending", "true");
440
441         RestapiCallNode rcn = new RestapiCallNode();
442         rcn.sendRequest(p, ctx);
443     }
444
445     @Test
446     public void testL3DciTemplate() throws SvcLogicException {
447         SvcLogicContext ctx = new SvcLogicContext();
448         ctx.setAttribute("prop.dci-connects.id", "Id1");
449         ctx.setAttribute("prop.dci-connects.name", "Name1");
450         ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
451         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
452         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
453         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
454         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
455         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
456         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
457         ctx.setAttribute("prop.dci-connects.vni", "1");
458
459         Map<String, String> p = new HashMap<>();
460         p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
461         p.put("restapiUrl", "http://echo.getpostman.com");
462         p.put("restapiUser", "user1");
463         p.put("restapiPassword", "abc123");
464         p.put("format", "json");
465         p.put("httpMethod", "post");
466         p.put("responsePrefix", "response");
467         p.put("skipSending", "true");
468
469         RestapiCallNode rcn = new RestapiCallNode();
470         rcn.sendRequest(p, ctx);
471
472     }
473
474     @Test
475     public void testControllerTokenTemplate() throws SvcLogicException {
476         SvcLogicContext ctx = new SvcLogicContext();
477         ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
478         ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
479
480         Map<String, String> p = new HashMap<>();
481         p.put("templateFileName", "src/test/resources/actokentemplate.json");
482         p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
483         p.put("format", "json");
484         p.put("httpMethod", "post");
485         p.put("responsePrefix", "restapi-result");
486         p.put("skipSending", "true");
487
488         RestapiCallNode rcn = new RestapiCallNode();
489         rcn.sendRequest(p, ctx);
490     }
491
492
493     @Test
494     public void testDeleteNoneAsContentType() throws SvcLogicException {
495         SvcLogicContext ctx = new SvcLogicContext();
496
497         Map<String, String> p = new HashMap<>();
498         p.put("restapiUrl", "https://echo.getpostman.com/delete");
499         p.put("restapiUser", "user1");
500         p.put("restapiPassword", "pwd1");
501         p.put("httpMethod", "delete");
502         p.put("format", "none");
503         p.put("skipSending", "true");
504
505         RestapiCallNode rcn = new RestapiCallNode();
506         rcn.sendRequest(p, ctx);
507     }
508
509     @Test
510     public void testPostNoneAsContentType() throws SvcLogicException {
511         SvcLogicContext ctx = new SvcLogicContext();
512         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
513         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
514
515         Map<String, String> p = new HashMap<>();
516         p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
517         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
518         p.put("restapiUser", "admin");
519         p.put("restapiPassword", "admin123");
520         p.put("format", "none");
521         p.put("httpMethod", "post");
522         p.put("responsePrefix", "restapi-result");
523         p.put("skipSending", "true");
524
525         RestapiCallNode rcn = new RestapiCallNode();
526         rcn.sendRequest(p, ctx);
527     }
528
529     @Test
530     public void testDeleteOAuthType() throws SvcLogicException {
531         SvcLogicContext ctx = new SvcLogicContext();
532
533         Map<String, String> p = new HashMap<>();
534         p.put("restapiUrl", "https://echo.getpostman.com/delete");
535         p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
536         p.put("oAuthConsumerSecret", "secret");
537         p.put("oAuthSignatureMethod", "plainTEXT");
538         p.put("oAuthVersion", "1.0");
539         p.put("httpMethod", "delete");
540         p.put("format", "none");
541         p.put("skipSending", "true");
542
543         RestapiCallNode rcn = new RestapiCallNode();
544         rcn.sendRequest(p, ctx);
545     }
546
547     @Test
548     public void testDeleteAuthTypeBasic() throws SvcLogicException {
549         SvcLogicContext ctx = new SvcLogicContext();
550
551         Map<String, String> p = new HashMap<>();
552         p.put("restapiUrl", "https://echo.getpostman.com/delete");
553         p.put("authType", "basic");
554         p.put("restapiUser", "admin");
555         p.put("restapiPassword", "admin123");
556         p.put("httpMethod", "delete");
557         p.put("format", "none");
558         p.put("skipSending", "true");
559
560         RestapiCallNode rcn = new RestapiCallNode();
561         rcn.sendRequest(p, ctx);
562     }
563
564     @Test
565     public void testDeleteAuthTypeDigest() throws SvcLogicException {
566         SvcLogicContext ctx = new SvcLogicContext();
567
568         Map<String, String> p = new HashMap<>();
569         p.put("restapiUrl", "https://echo.getpostman.com/delete");
570         p.put("authType", "digest");
571         p.put("restapiUser", "admin");
572         p.put("restapiPassword", "admin123");
573         p.put("httpMethod", "delete");
574         p.put("format", "none");
575         p.put("skipSending", "true");
576
577         RestapiCallNode rcn = new RestapiCallNode();
578         rcn.sendRequest(p, ctx);
579     }
580
581     @Test
582     public void testDeleteAuthTypeOAuth() throws SvcLogicException {
583         SvcLogicContext ctx = new SvcLogicContext();
584
585         Map<String, String> p = new HashMap<>();
586         p.put("restapiUrl", "https://echo.getpostman.com/delete");
587         p.put("authType", "oauth");
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");
595
596         RestapiCallNode rcn = new RestapiCallNode();
597         rcn.sendRequest(p, ctx);
598     }
599
600     @Test
601     public void testDeleteAuthTypeNoneOAuth() throws SvcLogicException {
602         SvcLogicContext ctx = new SvcLogicContext();
603
604         Map<String, String> p = new HashMap<>();
605         p.put("restapiUrl", "https://echo.getpostman.com/delete");
606         p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
607         p.put("oAuthConsumerSecret", "secret");
608         p.put("oAuthSignatureMethod", "plainTEXT");
609         p.put("oAuthVersion", "1.0");
610         p.put("httpMethod", "delete");
611         p.put("format", "none");
612         p.put("skipSending", "true");
613
614         RestapiCallNode rcn = new RestapiCallNode();
615         rcn.sendRequest(p, ctx);
616     }
617     @Test
618     public void testDeleteAuthTypeNoneBasic() throws SvcLogicException {
619         SvcLogicContext ctx = new SvcLogicContext();
620
621         Map<String, String> p = new HashMap<>();
622         p.put("restapiUrl", "https://echo.getpostman.com/delete");
623         p.put("restapiUser", "admin");
624         p.put("restapiPassword", "admin123");
625         p.put("httpMethod", "delete");
626         p.put("format", "none");
627         p.put("skipSending", "true");
628
629         RestapiCallNode rcn = new RestapiCallNode();
630         rcn.sendRequest(p, ctx);
631     }
632
633     @Test(expected = SvcLogicException.class)
634     public void testInvalidDeleteAuthTypeOAuth() throws SvcLogicException {
635         SvcLogicContext ctx = new SvcLogicContext();
636
637         Map<String, String> p = new HashMap<>();
638         p.put("restapiUrl", "https://echo.getpostman.com/delete");
639         p.put("authType", "oauth");
640         p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
641         p.put("oAuthConsumerSecret", "secret");
642         p.put("httpMethod", "delete");
643         p.put("format", "none");
644         p.put("skipSending", "true");
645
646         RestapiCallNode rcn = new RestapiCallNode();
647         rcn.sendRequest(p, ctx);
648     }
649
650     @Test(expected = SvcLogicException.class)
651     public void testInvalidDeleteAuthTypeBasic() throws SvcLogicException {
652         SvcLogicContext ctx = new SvcLogicContext();
653
654         Map<String, String> p = new HashMap<>();
655         p.put("restapiUrl", "https://echo.getpostman.com/delete");
656         p.put("authType", "basic");
657         p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
658         p.put("oAuthConsumerSecret", "secret");
659         p.put("httpMethod", "delete");
660         p.put("format", "none");
661         p.put("skipSending", "true");
662
663         RestapiCallNode rcn = new RestapiCallNode();
664         rcn.sendRequest(p, ctx);
665     }
666
667     @Test(expected = SvcLogicException.class)
668     public void testInvalidDeleteAuthTypeDigest() throws SvcLogicException {
669         SvcLogicContext ctx = new SvcLogicContext();
670
671         Map<String, String> p = new HashMap<>();
672         p.put("restapiUrl", "https://echo.getpostman.com/delete");
673         p.put("authType", "digest");
674         p.put("oAuthConsumerKey", "f2a1ed52710d4533bde25be6da03b6e3");
675         p.put("oAuthConsumerSecret", "secret");
676         p.put("httpMethod", "delete");
677         p.put("format", "none");
678         p.put("skipSending", "true");
679
680         RestapiCallNode rcn = new RestapiCallNode();
681         rcn.sendRequest(p, ctx);
682     }
683
684     @Test
685     public void testMultipartFormData() throws SvcLogicException {
686         final ResourceConfig resourceConfig = new ResourceConfig(
687                 MultipartServerMock.class, MultiPartFeature.class);
688         HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
689                 URI.create("http://localhost:8080/"),resourceConfig);
690
691         Map<String, String> p = new HashMap<>();
692         p.put("multipartFormData", "true");
693         p.put("format", "none");
694         p.put("multipartFile", "src/test/resources/test-template.json");
695         p.put("restapiUrl", "http://localhost:8080/file-upload/upload");
696
697         SvcLogicContext ctx = new SvcLogicContext();
698         RestapiCallNode rcn = new RestapiCallNode();
699         rcn.sendRequest(p, ctx);
700         assertThat(ctx.getAttribute("response-code"), is("200"));
701         assertThat(ctx.getAttribute("httpResponse"), is( "test-template.json"));
702         server.shutdownNow();
703     }
704
705     @Test
706     public void testCookieResponse() throws SvcLogicException {
707         final ResourceConfig resourceConfig = new ResourceConfig(
708                 MockCookieAuthServer.class);
709         HttpServer server = GrizzlyHttpServerFactory.createHttpServer(
710                 URI.create("http://localhost:8080/"),resourceConfig);
711
712         Map<String, String> p = new HashMap<>();
713         p.put("format", "none");
714         p.put("httpMethod", "get");
715         p.put("restapiUrl", "http://localhost:8080/get-cookie/cookie");
716         p.put("dumpHeaders", "true");
717
718         SvcLogicContext ctx = new SvcLogicContext();
719         RestapiCallNode rcn = new RestapiCallNode();
720         rcn.sendRequest(p, ctx);
721         assertThat(ctx.getAttribute("response-code"), is("200"));
722         assertThat(ctx.getAttribute("header.Set-Cookie"), is("cookieResponse=cookieValueInReturn;Version=1"));
723         server.shutdownNow();
724     }
725
726     @Test
727     public void testEmbeddedJsonTemplate() throws Exception {
728         SvcLogicContext ctx = new SvcLogicContext();
729         String complexObj = "{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}";
730         ctx.setAttribute("reqId", "1235");
731         ctx.setAttribute("subReqId", "054243");
732         ctx.setAttribute("actionName", "CREATE");
733         ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0");
734         ctx.setAttribute("complexObj", complexObj);
735         RestapiCallNode rcn = new RestapiCallNode();
736         String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testEmbeddedTemplate.json"), Format.JSON);
737         //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON
738         JSONObject requestObj = new JSONObject(request);
739     }
740
741 }