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 org.onap.ccsdk.sli.plugins.restapicall;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
30 import java.util.HashMap;
32 import org.codehaus.jettison.json.JSONObject;
33 import org.junit.Before;
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.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
40 public class TestRestapiCallNode {
42 @SuppressWarnings("unused")
43 private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
47 System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
51 public void testDelete() throws SvcLogicException {
52 SvcLogicContext ctx = new SvcLogicContext();
54 Map<String, String> p = new HashMap<>();
55 p.put("restapiUrl", "https://echo.getpostman.com/delete");
56 p.put("restapiUser", "user1");
57 p.put("restapiPassword", "pwd1");
58 p.put("httpMethod", "delete");
59 p.put("skipSending", "true");
61 RestapiCallNode rcn = new RestapiCallNode();
62 rcn.sendRequest(p, ctx);
66 public void testDeleteWithPayload() throws SvcLogicException {
67 SvcLogicContext ctx = new SvcLogicContext();
69 ctx.setAttribute("prop.name", "site1");
71 Map<String, String> p = new HashMap<>();
72 p.put("templateFileName", "src/test/resources/sdwan-site.json");
73 p.put("restapiUrl", "https://echo.getpostman.com/delete");
74 p.put("restapiUser", "user1");
75 p.put("restapiPassword", "pwd1");
76 p.put("httpMethod", "delete");
77 p.put("skipSending", "true");
79 RestapiCallNode rcn = new RestapiCallNode();
80 rcn.sendRequest(p, ctx);
84 public void testSendFile() throws SvcLogicException {
85 SvcLogicContext ctx = new SvcLogicContext();
87 Map<String, String> p = new HashMap<>();
88 p.put("fileName", "src/test/resources/test_file.txt");
89 p.put("url", "https://testurl.test");
90 p.put("user", "user");
91 p.put("password", "*******");
92 p.put("skipSending", "true"); // Set real url, user, password, when testing actual sending
94 RestapiCallNode rcn = new RestapiCallNode();
99 public void testJsonTemplate() throws SvcLogicException {
100 SvcLogicContext ctx = new SvcLogicContext();
101 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
102 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
103 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
104 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
105 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
106 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
107 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
108 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
109 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
110 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
111 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
112 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
113 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
114 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
115 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
116 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
117 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
118 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
119 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
120 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
121 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
122 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
124 Map<String, String> p = new HashMap<>();
125 p.put("templateFileName", "src/test/resources/test-template.json");
126 p.put("restapiUrl", "http://echo.getpostman.com");
127 p.put("restapiUser", "user1");
128 p.put("restapiPassword", "abc123");
129 p.put("format", "json");
130 p.put("httpMethod", "post");
131 p.put("responsePrefix", "response");
132 p.put("skipSending", "true");
134 RestapiCallNode rcn = new RestapiCallNode();
135 rcn.sendRequest(p, ctx);
139 public void testInvalidRepeatTimes() throws SvcLogicException {
140 SvcLogicContext ctx = new SvcLogicContext();
141 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
142 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
143 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
144 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
145 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
146 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
147 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
148 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
150 Map<String, String> p = new HashMap<>();
151 p.put("templateFileName", "src/test/resources/test-template.json");
152 p.put("restapiUrl", "http://echo.getpostman.com");
153 p.put("restapiUser", "user1");
154 p.put("restapiPassword", "abc123");
155 p.put("format", "json");
156 p.put("httpMethod", "post");
157 p.put("responsePrefix", "response");
158 p.put("skipSending", "true");
160 RestapiCallNode rcn = new RestapiCallNode();
161 rcn.sendRequest(p, ctx);
164 @Test(expected = SvcLogicException.class)
165 public void testInvalidTemplatePath() throws SvcLogicException {
166 SvcLogicContext ctx = new SvcLogicContext();
167 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
168 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
169 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
170 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
171 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
172 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
173 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
174 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
176 Map<String, String> p = new HashMap<>();
177 p.put("templateFileName", "src/test/resourcess/test-template.json");
178 p.put("restapiUrl", "http://echo.getpostman.com");
179 p.put("restapiUser", "user1");
180 p.put("restapiPassword", "abc123");
181 p.put("format", "json");
182 p.put("httpMethod", "post");
183 p.put("responsePrefix", "response");
184 p.put("skipSending", "true");
186 RestapiCallNode rcn = new RestapiCallNode();
187 rcn.sendRequest(p, ctx);
190 @Test(expected = SvcLogicException.class)
191 public void testWithoutSkipSending() throws SvcLogicException {
192 SvcLogicContext ctx = new SvcLogicContext();
193 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
194 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
195 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
196 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
197 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
198 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
199 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
200 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
202 Map<String, String> p = new HashMap<>();
203 p.put("templateFileName", "src/test/resources/test-template.json");
204 p.put("restapiUrl", "http://echo.getpostman.com");
205 p.put("restapiUser", "user1");
206 p.put("restapiPassword", "abc123");
207 p.put("format", "json");
208 p.put("httpMethod", "post");
209 p.put("responsePrefix", "response");
210 p.put("skipSending", "false");
212 RestapiCallNode rcn = new RestapiCallNode();
213 rcn.sendRequest(p, ctx);
217 @Test(expected = SvcLogicException.class)
218 public void testWithInvalidURI() throws SvcLogicException {
219 SvcLogicContext ctx = new SvcLogicContext();
220 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
221 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
222 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
223 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
224 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
225 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
226 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
227 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
229 Map<String, String> p = new HashMap<>();
230 p.put("templateFileName", "src/test/resources/test-template.json");
231 p.put("restapiUrl", "http://echo. getpostman.com");
232 p.put("restapiUser", "user1");
233 p.put("restapiPassword", "abc123");
234 p.put("format", "json");
235 p.put("httpMethod", "post");
236 p.put("responsePrefix", "response");
237 p.put("skipSending", "false");
239 RestapiCallNode rcn = new RestapiCallNode();
240 rcn.sendRequest(p, ctx);
244 public void testVpnJsonTemplate() throws SvcLogicException {
245 SvcLogicContext ctx = new SvcLogicContext();
246 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
247 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
249 Map<String, String> p = new HashMap<>();
250 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
251 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
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 testSiteJsonTemplate() throws SvcLogicException {
265 SvcLogicContext ctx = new SvcLogicContext();
266 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
267 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
269 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
270 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
271 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
272 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
273 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
274 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
275 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
276 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
277 ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
278 ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
279 ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
280 ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
282 ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
283 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
284 ctx.setAttribute("prop.l3vpn.entry2-id", "1");
285 ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
286 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
287 ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
288 ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
289 ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
290 ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
291 ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
292 ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
293 ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
295 Map<String, String> p = new HashMap<>();
296 p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
297 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
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 testVrfJsonTemplate() throws SvcLogicException {
311 SvcLogicContext ctx = new SvcLogicContext();
312 ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
313 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
314 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
315 ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
316 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
317 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
319 Map<String, String> p = new HashMap<>();
320 p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
321 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
322 p.put("restapiUser", "admin");
323 p.put("restapiPassword", "admin123");
324 p.put("format", "json");
325 p.put("httpMethod", "post");
326 p.put("responsePrefix", "restapi-result");
327 p.put("skipSending", "true");
329 RestapiCallNode rcn = new RestapiCallNode();
330 rcn.sendRequest(p, ctx);
334 public void testDeleteVpnJsonTemplate() throws SvcLogicException {
335 SvcLogicContext ctx = new SvcLogicContext();
336 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
337 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
339 Map<String, String> p = new HashMap<>();
340 //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
341 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
342 + "/vpnservice=10000000-0000-0000-0000-000000000001");
343 p.put("restapiUser", "admin");
344 p.put("restapiPassword", "admin123");
345 p.put("format", "json");
346 p.put("httpMethod", "delete");
347 p.put("responsePrefix", "restapi-result");
348 p.put("skipSending", "true");
350 RestapiCallNode rcn = new RestapiCallNode();
351 rcn.sendRequest(p, ctx);
355 public void testL2DciTemplate() throws SvcLogicException {
356 SvcLogicContext ctx = new SvcLogicContext();
357 ctx.setAttribute("prop.dci-connects.id", "Id1");
358 ctx.setAttribute("prop.dci-connects.name", "Name1");
359 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
360 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
361 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
362 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
363 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
364 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
365 ctx.setAttribute("prop.dci-connects.vni", "1");
367 Map<String, String> p = new HashMap<>();
368 p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
369 p.put("restapiUrl", "http://echo.getpostman.com");
370 p.put("restapiUser", "user1");
371 p.put("restapiPassword", "abc123");
372 p.put("format", "json");
373 p.put("httpMethod", "post");
374 p.put("responsePrefix", "response");
375 p.put("skipSending", "true");
377 RestapiCallNode rcn = new RestapiCallNode();
378 rcn.sendRequest(p, ctx);
382 public void testL3DciTemplate() throws SvcLogicException {
383 SvcLogicContext ctx = new SvcLogicContext();
384 ctx.setAttribute("prop.dci-connects.id", "Id1");
385 ctx.setAttribute("prop.dci-connects.name", "Name1");
386 ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
387 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
388 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
389 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
390 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
391 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
392 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
393 ctx.setAttribute("prop.dci-connects.vni", "1");
395 Map<String, String> p = new HashMap<>();
396 p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
397 p.put("restapiUrl", "http://echo.getpostman.com");
398 p.put("restapiUser", "user1");
399 p.put("restapiPassword", "abc123");
400 p.put("format", "json");
401 p.put("httpMethod", "post");
402 p.put("responsePrefix", "response");
403 p.put("skipSending", "true");
405 RestapiCallNode rcn = new RestapiCallNode();
406 rcn.sendRequest(p, ctx);
411 public void testControllerTokenTemplate() throws SvcLogicException {
412 SvcLogicContext ctx = new SvcLogicContext();
413 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
414 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
416 Map<String, String> p = new HashMap<>();
417 p.put("templateFileName", "src/test/resources/actokentemplate.json");
418 p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
419 p.put("format", "json");
420 p.put("httpMethod", "post");
421 p.put("responsePrefix", "restapi-result");
422 p.put("skipSending", "true");
424 RestapiCallNode rcn = new RestapiCallNode();
425 rcn.sendRequest(p, ctx);
430 public void testDeleteNoneAsContentType() throws SvcLogicException {
431 SvcLogicContext ctx = new SvcLogicContext();
433 Map<String, String> p = new HashMap<>();
434 p.put("restapiUrl", "https://echo.getpostman.com/delete");
435 p.put("restapiUser", "user1");
436 p.put("restapiPassword", "pwd1");
437 p.put("httpMethod", "delete");
438 p.put("format", "none");
439 p.put("skipSending", "true");
441 RestapiCallNode rcn = new RestapiCallNode();
442 rcn.sendRequest(p, ctx);
446 public void testPostNoneAsContentType() throws SvcLogicException {
447 SvcLogicContext ctx = new SvcLogicContext();
448 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
449 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
451 Map<String, String> p = new HashMap<>();
452 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
453 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
454 p.put("restapiUser", "admin");
455 p.put("restapiPassword", "admin123");
456 p.put("format", "none");
457 p.put("httpMethod", "post");
458 p.put("responsePrefix", "restapi-result");
459 p.put("skipSending", "true");
461 RestapiCallNode rcn = new RestapiCallNode();
462 rcn.sendRequest(p, ctx);
467 "url": "http://localhost:7001" 4 http://uebsb93kcdc.it.att.com:3904",
471 "url": "http://localhost:7002",
472 "user": "controller_user",
473 "password": "P@ssword",
477 "url": "http://localhost:7003",
478 "user": "controller_admin"
483 public void testPartners() throws Exception{
484 String partnerTwoKey = "partnerTwo";
485 String partnerTwoUsername = "controller_user";
486 String partnerTwoPassword = "P@ssword";
488 System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
489 RestapiCallNode rcn = new RestapiCallNode();
490 assertNull(rcn.partnerStore.get("partnerOne"));
491 PartnerDetails details = rcn.partnerStore.get(partnerTwoKey);
492 assertEquals(partnerTwoUsername,details.username);
493 assertEquals(partnerTwoPassword,details.password);
494 assertNull(rcn.partnerStore.get("partnerThree"));
496 //In this scenario the caller expects username, password and url to be picked up from the partners json
497 Map<String, String> paramMap = new HashMap<>();
498 paramMap.put("partner", partnerTwoKey);
499 rcn.handlePartner(paramMap );
500 assertEquals(partnerTwoUsername,paramMap.get(RestapiCallNode.restapiUserKey));
501 assertEquals(partnerTwoPassword,paramMap.get(RestapiCallNode.restapiPasswordKey));
502 assertEquals("http://localhost:7002",paramMap.get(RestapiCallNode.restapiUrlString));
504 //In this scenario the caller expects username, password and url to be picked up from the partners json
505 //the provided suffix will be appended to the default url from the partners json
506 paramMap = new HashMap<>();
507 paramMap.put("partner", partnerTwoKey);
508 paramMap.put("restapiUrlSuffix", "/networking/v1/instance/3");
509 rcn.handlePartner(paramMap);
510 Parameters p = new Parameters();
511 RestapiCallNode.getParameters(paramMap, p);
512 assertEquals(partnerTwoUsername,p.restapiUser);
513 assertEquals(partnerTwoPassword,p.restapiPassword);
514 assertEquals("http://localhost:7002/networking/v1/instance/3",p.restapiUrl);
518 public void retryPolicyBean() throws Exception {
520 String first = "http://localhost:7001";
521 String second = "http://localhost:7001";
523 RetryPolicy p = new RetryPolicy(new String[] {first,second}, retries);
524 assertEquals(retries,p.getMaximumRetries());
525 assertNotNull(p.getRetryMessage());
526 String next = p.getNextHostName();
527 assertEquals(second,next);
528 assertEquals(1,p.getRetryCount());
529 next = p.getNextHostName();
530 assertEquals(first,next);
531 assertEquals(2,p.getRetryCount());
535 public void testEmbeddedJsonTemplate() throws Exception {
536 SvcLogicContext ctx = new SvcLogicContext();
537 String complexObj = "{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}";
538 ctx.setAttribute("reqId", "1235");
539 ctx.setAttribute("subReqId", "054243");
540 ctx.setAttribute("actionName", "CREATE");
541 ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0");
542 ctx.setAttribute("complexObj", complexObj);
543 RestapiCallNode rcn = new RestapiCallNode();
544 String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testEmbeddedTemplate.json"), Format.JSON);
545 //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON
546 assertNotNull(new JSONObject(request));
550 public void testMultiLineEmbeddedJsonTemplate() throws Exception {
551 SvcLogicContext ctx = new SvcLogicContext();
552 String complexObj = "{\n"
553 + " \"image_name\": \"Ubuntu 14.04\",\n"
554 + " \"service-instance-id\": \"1\",\n"
555 + " \"vnf-model-customization-uuid\": \"2f\",\n"
556 + " \"vnf-id\": \"3b\"\n"
558 ctx.setAttribute("reqId", "1235");
559 ctx.setAttribute("subReqId", "054243");
560 ctx.setAttribute("actionName", "CREATE");
561 ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0");
562 ctx.setAttribute("complexObj", complexObj);
563 RestapiCallNode rcn = new RestapiCallNode();
564 String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testMultiLineEmbeddedTemplate.json"), Format.JSON);
565 //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON
566 assertNotNull(new JSONObject(request));
570 public void testGetMultipleUrls() throws Exception{
571 String[] urls = RestapiCallNode.getMultipleUrls("http://localhost:8008/rest/restconf/data/abc:def/abc:action=Create,deviceType=Banana,https://localhost:8008/rest/restconf/data/abc:def/abc:action=Create,deviceType=Potato");
572 assertEquals("http://localhost:8008/rest/restconf/data/abc:def/abc:action=Create,deviceType=Banana",urls[0]);
573 assertEquals("https://localhost:8008/rest/restconf/data/abc:def/abc:action=Create,deviceType=Potato",urls[1]);
575 urls = RestapiCallNode.getMultipleUrls("https://wiki.onap.org/,http://localhost:7001/,http://wiki.onap.org/");
576 assertEquals("https://wiki.onap.org/",urls[0]);
577 assertEquals("http://localhost:7001/",urls[1]);
578 assertEquals("http://wiki.onap.org/",urls[2]);
580 urls = RestapiCallNode.getMultipleUrls("https://wiki.onap.org/test=4,5,6,http://localhost:7001/test=1,2,3,http://wiki.onap.org/test=7,8,9,10");
581 assertEquals("https://wiki.onap.org/test=4,5,6",urls[0]);
582 assertEquals("http://localhost:7001/test=1,2,3",urls[1]);
583 assertEquals("http://wiki.onap.org/test=7,8,9,10",urls[2]);
585 urls = RestapiCallNode.getMultipleUrls("https://wiki.onap.org/,https://readthedocs.org/projects/onap/");
586 assertEquals("https://wiki.onap.org/",urls[0]);
587 assertEquals("https://readthedocs.org/projects/onap/",urls[1]);
591 public void testContainsMultipleUrls() throws Exception{
592 assertFalse(RestapiCallNode.containsMultipleUrls("https://wiki.onap.org/"));
593 assertFalse(RestapiCallNode.containsMultipleUrls("http://wiki.onap.org/"));
594 assertFalse(RestapiCallNode.containsMultipleUrls("http://localhost:8008/rest/restconf/data/abc:def/abc:action=Create,deviceType=Banana"));
595 assertFalse(RestapiCallNode.containsMultipleUrls("https://localhost:8008/params=1,2,3,4,5,6"));
597 assertTrue(RestapiCallNode.containsMultipleUrls("https://wiki.onap.org/,https://readthedocs.org/projects/onap/"));
598 assertTrue(RestapiCallNode.containsMultipleUrls("http://localhost:7001/,http://localhost:7002"));
599 assertTrue(RestapiCallNode.containsMultipleUrls("http://localhost:8008/rest/restconf/data/abc:def/abc:action=Create,deviceType=Banana,https://localhost:8008/rest/restconf/data/abc:def/abc:action=Create,deviceType=Potato"));
600 assertTrue(RestapiCallNode.containsMultipleUrls("https://wiki.onap.org/,http://localhost:7001/,http://wiki.onap.org/"));
601 assertTrue(RestapiCallNode.containsMultipleUrls("https://wiki.onap.org/test=4,5,6,http://localhost:7001/test=1,2,3,http://wiki.onap.org/test=7,8,9,10"));