2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package jtest.org.onap.ccsdk.sli.plugins.restapicall;
24 import java.util.HashMap;
27 import org.junit.Test;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class TestRestapiCallNode {
36 private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
40 public void testDelete() throws SvcLogicException {
41 SvcLogicContext ctx = new SvcLogicContext();
43 Map<String, String> p = new HashMap<String, String>();
44 p.put("restapiUrl", "https://echo.getpostman.com/delete");
45 p.put("restapiUser", "user1");
46 p.put("restapiPassword", "pwd1");
47 p.put("httpMethod", "delete");
48 p.put("skipSending", "true");
50 RestapiCallNode rcn = new RestapiCallNode();
51 rcn.sendRequest(p, ctx);
55 public void testJsonTemplate() throws SvcLogicException {
56 SvcLogicContext ctx = new SvcLogicContext();
57 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
58 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
59 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
60 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
61 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
62 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
63 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
64 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
65 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
66 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
67 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
68 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
69 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
70 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
71 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
72 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
73 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
74 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
75 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
76 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
77 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
78 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
80 Map<String, String> p = new HashMap<String, String>();
81 p.put("templateFileName", "src/test/resources/test-template.json");
82 p.put("restapiUrl", "http://echo.getpostman.com");
83 p.put("restapiUser", "user1");
84 p.put("restapiPassword", "abc123");
85 p.put("format", "json");
86 p.put("httpMethod", "post");
87 p.put("responsePrefix", "response");
88 p.put("skipSending", "true");
90 RestapiCallNode rcn = new RestapiCallNode();
91 rcn.sendRequest(p, ctx);
94 @Test(expected = SvcLogicException.class)
95 public void testInvalidRepeatTimes() throws SvcLogicException {
96 SvcLogicContext ctx = new SvcLogicContext();
97 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
98 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
99 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
100 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
101 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
102 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
103 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
104 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
106 Map<String, String> p = new HashMap<String, String>();
107 p.put("templateFileName", "src/test/resources/test-template.json");
108 p.put("restapiUrl", "http://echo.getpostman.com");
109 p.put("restapiUser", "user1");
110 p.put("restapiPassword", "abc123");
111 p.put("format", "json");
112 p.put("httpMethod", "post");
113 p.put("responsePrefix", "response");
114 p.put("skipSending", "true");
116 RestapiCallNode rcn = new RestapiCallNode();
117 rcn.sendRequest(p, ctx);
120 @Test(expected = SvcLogicException.class)
121 public void testInvalidTemplatePath() throws SvcLogicException {
122 SvcLogicContext ctx = new SvcLogicContext();
123 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
124 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
125 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
126 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
127 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
128 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
129 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
130 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
132 Map<String, String> p = new HashMap<String, String>();
133 p.put("templateFileName", "src/test/resourcess/test-template.json");
134 p.put("restapiUrl", "http://echo.getpostman.com");
135 p.put("restapiUser", "user1");
136 p.put("restapiPassword", "abc123");
137 p.put("format", "json");
138 p.put("httpMethod", "post");
139 p.put("responsePrefix", "response");
140 p.put("skipSending", "true");
142 RestapiCallNode rcn = new RestapiCallNode();
143 rcn.sendRequest(p, ctx);
146 @Test(expected = SvcLogicException.class)
147 public void testWithoutSkipSending() throws SvcLogicException {
148 SvcLogicContext ctx = new SvcLogicContext();
149 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
150 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
151 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
152 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
153 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
154 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
155 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
156 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
158 Map<String, String> p = new HashMap<String, String>();
159 p.put("templateFileName", "src/test/resources/test-template.json");
160 p.put("restapiUrl", "http://echo.getpostman.com");
161 p.put("restapiUser", "user1");
162 p.put("restapiPassword", "abc123");
163 p.put("format", "json");
164 p.put("httpMethod", "post");
165 p.put("responsePrefix", "response");
166 p.put("skipSending", "false");
168 RestapiCallNode rcn = new RestapiCallNode();
169 rcn.sendRequest(p, ctx);
173 @Test(expected = SvcLogicException.class)
174 public void testWithInvalidURI() throws SvcLogicException {
175 SvcLogicContext ctx = new SvcLogicContext();
176 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
177 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
178 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
179 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
180 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
181 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
182 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
183 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
185 Map<String, String> p = new HashMap<String, String>();
186 p.put("templateFileName", "src/test/resources/test-template.json");
187 p.put("restapiUrl", "http://echo. getpostman.com");
188 p.put("restapiUser", "user1");
189 p.put("restapiPassword", "abc123");
190 p.put("format", "json");
191 p.put("httpMethod", "post");
192 p.put("responsePrefix", "response");
193 p.put("skipSending", "false");
195 RestapiCallNode rcn = new RestapiCallNode();
196 rcn.sendRequest(p, ctx);
200 public void testVpnJsonTemplate() throws SvcLogicException {
201 SvcLogicContext ctx = new SvcLogicContext();
202 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
203 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
205 Map<String, String> p = new HashMap<String, String>();
206 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
207 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
208 p.put("restapiUser", "admin");
209 p.put("restapiPassword", "admin123");
210 p.put("format", "json");
211 p.put("httpMethod", "post");
212 p.put("responsePrefix", "restapi-result");
213 p.put("skipSending", "true");
215 RestapiCallNode rcn = new RestapiCallNode();
216 rcn.sendRequest(p, ctx);
220 public void testSiteJsonTemplate() throws SvcLogicException {
221 SvcLogicContext ctx = new SvcLogicContext();
222 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
223 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
225 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
226 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
227 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
228 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
229 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
230 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
231 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
232 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
233 ctx.setAttribute("prop.l3vpn.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");
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");
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");
259 RestapiCallNode rcn = new RestapiCallNode();
260 rcn.sendRequest(p, ctx);
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");
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");
283 RestapiCallNode rcn = new RestapiCallNode();
284 rcn.sendRequest(p, ctx);
288 public void testL2DciTemplate() throws SvcLogicException {
289 SvcLogicContext ctx = new SvcLogicContext();
290 ctx.setAttribute("prop.dci-connects.id", "Id1");
291 ctx.setAttribute("prop.dci-connects.name", "Name1");
292 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
293 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
294 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
295 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
296 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
297 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
298 ctx.setAttribute("prop.dci-connects.vni", "1");
300 Map<String, String> p = new HashMap<String, String>();
301 p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
302 p.put("restapiUrl", "http://echo.getpostman.com");
303 p.put("restapiUser", "user1");
304 p.put("restapiPassword", "abc123");
305 p.put("format", "json");
306 p.put("httpMethod", "post");
307 p.put("responsePrefix", "response");
308 p.put("skipSending", "true");
310 RestapiCallNode rcn = new RestapiCallNode();
311 rcn.sendRequest(p, ctx);
315 public void testL3DciTemplate() throws SvcLogicException {
316 SvcLogicContext ctx = new SvcLogicContext();
317 ctx.setAttribute("prop.dci-connects.id", "Id1");
318 ctx.setAttribute("prop.dci-connects.name", "Name1");
319 ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
320 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
321 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
322 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
323 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
324 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
325 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
326 ctx.setAttribute("prop.dci-connects.vni", "1");
328 Map<String, String> p = new HashMap<String, String>();
329 p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
330 p.put("restapiUrl", "http://echo.getpostman.com");
331 p.put("restapiUser", "user1");
332 p.put("restapiPassword", "abc123");
333 p.put("format", "json");
334 p.put("httpMethod", "post");
335 p.put("responsePrefix", "response");
336 p.put("skipSending", "true");
338 RestapiCallNode rcn = new RestapiCallNode();
339 rcn.sendRequest(p, ctx);