Update VoLTE underlay JSON template
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / test / java / jtest / 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 jtest.org.onap.ccsdk.sli.plugins.restapicall;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.junit.Test;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class TestRestapiCallNode {
35
36     private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
37
38
39     @Test
40     public void testDelete() throws SvcLogicException {
41         SvcLogicContext ctx = new SvcLogicContext();
42
43         Map<String, String> p = new HashMap<String, String>();
44         p.put("restapiUrl", "https://echo.getpostman.com/delete");
45         p.put("restapiUser", "user1");
46         p.put("restapiPassword", "pwd1");
47         p.put("httpMethod", "delete");
48         p.put("skipSending", "true");
49
50         RestapiCallNode rcn = new RestapiCallNode();
51         rcn.sendRequest(p, ctx);
52     }
53
54     @Test
55     public void testJsonTemplate() throws SvcLogicException {
56         SvcLogicContext ctx = new SvcLogicContext();
57         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
58         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
59         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
60         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
61         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
62         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
63         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
64         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
65         ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
66         ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
67         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
68         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
69         ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
70         ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
71         ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
72         ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
73         ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
74         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
75         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
76         ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
77         ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
78         ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
79
80         Map<String, String> p = new HashMap<String, String>();
81         p.put("templateFileName", "src/test/resources/test-template.json");
82         p.put("restapiUrl", "http://echo.getpostman.com");
83         p.put("restapiUser", "user1");
84         p.put("restapiPassword", "abc123");
85         p.put("format", "json");
86         p.put("httpMethod", "post");
87         p.put("responsePrefix", "response");
88         p.put("skipSending", "true");
89
90         RestapiCallNode rcn = new RestapiCallNode();
91         rcn.sendRequest(p, ctx);
92     }
93
94     @Test(expected = SvcLogicException.class)
95     public void testInvalidRepeatTimes() throws SvcLogicException {
96         SvcLogicContext ctx = new SvcLogicContext();
97         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
98         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
99         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
100         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
101         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
102         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
103         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
104         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
105
106         Map<String, String> p = new HashMap<String, String>();
107         p.put("templateFileName", "src/test/resources/test-template.json");
108         p.put("restapiUrl", "http://echo.getpostman.com");
109         p.put("restapiUser", "user1");
110         p.put("restapiPassword", "abc123");
111         p.put("format", "json");
112         p.put("httpMethod", "post");
113         p.put("responsePrefix", "response");
114         p.put("skipSending", "true");
115
116         RestapiCallNode rcn = new RestapiCallNode();
117         rcn.sendRequest(p, ctx);
118     }
119
120     @Test(expected = SvcLogicException.class)
121     public void testInvalidTemplatePath() throws SvcLogicException {
122         SvcLogicContext ctx = new SvcLogicContext();
123         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
124         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
125         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
126         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
127         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
128         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
129         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
130         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
131
132         Map<String, String> p = new HashMap<String, String>();
133         p.put("templateFileName", "src/test/resourcess/test-template.json");
134         p.put("restapiUrl", "http://echo.getpostman.com");
135         p.put("restapiUser", "user1");
136         p.put("restapiPassword", "abc123");
137         p.put("format", "json");
138         p.put("httpMethod", "post");
139         p.put("responsePrefix", "response");
140         p.put("skipSending", "true");
141
142         RestapiCallNode rcn = new RestapiCallNode();
143         rcn.sendRequest(p, ctx);
144     }
145
146     @Test(expected = SvcLogicException.class)
147     public void testWithoutSkipSending() throws SvcLogicException {
148         SvcLogicContext ctx = new SvcLogicContext();
149         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
150         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
151         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
152         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
153         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
154         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
155         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
156         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
157
158         Map<String, String> p = new HashMap<String, String>();
159         p.put("templateFileName", "src/test/resources/test-template.json");
160         p.put("restapiUrl", "http://echo.getpostman.com");
161         p.put("restapiUser", "user1");
162         p.put("restapiPassword", "abc123");
163         p.put("format", "json");
164         p.put("httpMethod", "post");
165         p.put("responsePrefix", "response");
166         p.put("skipSending", "false");
167
168         RestapiCallNode rcn = new RestapiCallNode();
169         rcn.sendRequest(p, ctx);
170     }
171
172
173     @Test(expected = SvcLogicException.class)
174     public void testWithInvalidURI() throws SvcLogicException {
175         SvcLogicContext ctx = new SvcLogicContext();
176         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
177         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
178         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
179         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
180         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
181         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
182         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
183         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
184
185         Map<String, String> p = new HashMap<String, String>();
186         p.put("templateFileName", "src/test/resources/test-template.json");
187         p.put("restapiUrl", "http://echo.  getpostman.com");
188         p.put("restapiUser", "user1");
189         p.put("restapiPassword", "abc123");
190         p.put("format", "json");
191         p.put("httpMethod", "post");
192         p.put("responsePrefix", "response");
193         p.put("skipSending", "false");
194
195         RestapiCallNode rcn = new RestapiCallNode();
196         rcn.sendRequest(p, ctx);
197     }
198
199     @Test
200     public void testVpnJsonTemplate() throws SvcLogicException {
201         SvcLogicContext ctx = new SvcLogicContext();
202         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
203         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
204
205         Map<String, String> p = new HashMap<String, String>();
206         p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
207         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
208         p.put("restapiUser", "admin");
209         p.put("restapiPassword", "admin123");
210         p.put("format", "json");
211         p.put("httpMethod", "post");
212         p.put("responsePrefix", "restapi-result");
213         p.put("skipSending", "true");
214
215         RestapiCallNode rcn = new RestapiCallNode();
216         rcn.sendRequest(p, ctx);
217     }
218
219     @Test
220     public void testSiteJsonTemplate() throws SvcLogicException {
221         SvcLogicContext ctx = new SvcLogicContext();
222         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
223         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
224
225         ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
226         ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
227         ctx.setAttribute("prop.l3vpn.entry1-id", "1");
228         ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
229         ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
230         ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
231         ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
232         ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
233         ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
234         ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
235         ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
236
237         ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
238         ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
239         ctx.setAttribute("prop.l3vpn.entry2-id", "1");
240         ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
241         ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
242         ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
243         ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.5");
244         ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
245         ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
246         ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.5");
247         ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
248
249         Map<String, String> p = new HashMap<String, String>();
250         p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
251         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
252         p.put("restapiUser", "admin");
253         p.put("restapiPassword", "admin123");
254         p.put("format", "json");
255         p.put("httpMethod", "post");
256         p.put("responsePrefix", "restapi-result");
257         p.put("skipSending", "true");
258
259         RestapiCallNode rcn = new RestapiCallNode();
260         rcn.sendRequest(p, ctx);
261     }
262
263     @Test
264     public void testVrfJsonTemplate() throws SvcLogicException {
265         SvcLogicContext ctx = new SvcLogicContext();
266         ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
267         ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
268         ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
269         ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
270         ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
271         ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
272
273         Map<String, String> p = new HashMap<String, String>();
274         p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
275         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
276         p.put("restapiUser", "admin");
277         p.put("restapiPassword", "admin123");
278         p.put("format", "json");
279         p.put("httpMethod", "post");
280         p.put("responsePrefix", "restapi-result");
281         p.put("skipSending", "true");
282
283         RestapiCallNode rcn = new RestapiCallNode();
284         rcn.sendRequest(p, ctx);
285     }
286
287     @Test
288     public void testDeleteVpnJsonTemplate() throws SvcLogicException {
289         SvcLogicContext ctx = new SvcLogicContext();
290         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
291         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
292
293         Map<String, String> p = new HashMap<String, String>();
294         //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
295         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
296             + "/vpnservice=10000000-0000-0000-0000-000000000001");
297         p.put("restapiUser", "admin");
298         p.put("restapiPassword", "admin123");
299         p.put("format", "json");
300         p.put("httpMethod", "delete");
301         p.put("responsePrefix", "restapi-result");
302         p.put("skipSending", "true");
303
304         RestapiCallNode rcn = new RestapiCallNode();
305         rcn.sendRequest(p, ctx);
306     }
307
308     @Test
309     public void testL2DciTemplate() throws SvcLogicException {
310         SvcLogicContext ctx = new SvcLogicContext();
311         ctx.setAttribute("prop.dci-connects.id", "Id1");
312         ctx.setAttribute("prop.dci-connects.name", "Name1");
313         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
314         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
315         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
316         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
317         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
318         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
319         ctx.setAttribute("prop.dci-connects.vni", "1");
320
321         Map<String, String> p = new HashMap<String, String>();
322         p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
323         p.put("restapiUrl", "http://echo.getpostman.com");
324         p.put("restapiUser", "user1");
325         p.put("restapiPassword", "abc123");
326         p.put("format", "json");
327         p.put("httpMethod", "post");
328         p.put("responsePrefix", "response");
329         p.put("skipSending", "true");
330
331         RestapiCallNode rcn = new RestapiCallNode();
332         rcn.sendRequest(p, ctx);
333     }
334
335     @Test
336     public void testL3DciTemplate() throws SvcLogicException {
337         SvcLogicContext ctx = new SvcLogicContext();
338         ctx.setAttribute("prop.dci-connects.id", "Id1");
339         ctx.setAttribute("prop.dci-connects.name", "Name1");
340         ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
341         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
342         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
343         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
344         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
345         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
346         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
347         ctx.setAttribute("prop.dci-connects.vni", "1");
348
349         Map<String, String> p = new HashMap<String, String>();
350         p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
351         p.put("restapiUrl", "http://echo.getpostman.com");
352         p.put("restapiUser", "user1");
353         p.put("restapiPassword", "abc123");
354         p.put("format", "json");
355         p.put("httpMethod", "post");
356         p.put("responsePrefix", "response");
357         p.put("skipSending", "true");
358
359         RestapiCallNode rcn = new RestapiCallNode();
360         rcn.sendRequest(p, ctx);
361
362     }
363 }