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.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import java.util.HashMap;
29 import org.codehaus.jettison.json.JSONObject;
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
33 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 public class TestRestapiCallNode {
39 @SuppressWarnings("unused")
40 private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
44 System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
48 public void testDelete() throws SvcLogicException {
49 SvcLogicContext ctx = new SvcLogicContext();
51 Map<String, String> p = new HashMap<>();
52 p.put("restapiUrl", "https://echo.getpostman.com/delete");
53 p.put("restapiUser", "user1");
54 p.put("restapiPassword", "pwd1");
55 p.put("httpMethod", "delete");
56 p.put("skipSending", "true");
58 RestapiCallNode rcn = new RestapiCallNode();
59 rcn.sendRequest(p, ctx);
63 public void testDeleteWithPayload() throws SvcLogicException {
64 SvcLogicContext ctx = new SvcLogicContext();
66 ctx.setAttribute("prop.name", "site1");
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");
76 RestapiCallNode rcn = new RestapiCallNode();
77 rcn.sendRequest(p, ctx);
81 public void testSendFile() throws SvcLogicException {
82 SvcLogicContext ctx = new SvcLogicContext();
84 Map<String, String> p = new HashMap<>();
85 p.put("fileName", "src/test/resources/test_file.txt");
86 p.put("url", "https://testurl.test");
87 p.put("user", "user");
88 p.put("password", "*******");
89 p.put("skipSending", "true"); // Set real url, user, password, when testing actual sending
91 RestapiCallNode rcn = new RestapiCallNode();
96 public void testJsonTemplate() throws SvcLogicException {
97 SvcLogicContext ctx = new SvcLogicContext();
98 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
99 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
100 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
101 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
102 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
103 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
104 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
105 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
106 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
107 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
108 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
109 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
110 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
111 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
112 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
113 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
114 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
115 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
116 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
117 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
118 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
119 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
121 Map<String, String> p = new HashMap<>();
122 p.put("templateFileName", "src/test/resources/test-template.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");
131 RestapiCallNode rcn = new RestapiCallNode();
132 rcn.sendRequest(p, ctx);
136 public void testInvalidRepeatTimes() throws SvcLogicException {
137 SvcLogicContext ctx = new SvcLogicContext();
138 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
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");
147 Map<String, String> p = new HashMap<>();
148 p.put("templateFileName", "src/test/resources/test-template.json");
149 p.put("restapiUrl", "http://echo.getpostman.com");
150 p.put("restapiUser", "user1");
151 p.put("restapiPassword", "abc123");
152 p.put("format", "json");
153 p.put("httpMethod", "post");
154 p.put("responsePrefix", "response");
155 p.put("skipSending", "true");
157 RestapiCallNode rcn = new RestapiCallNode();
158 rcn.sendRequest(p, ctx);
161 @Test(expected = SvcLogicException.class)
162 public void testInvalidTemplatePath() throws SvcLogicException {
163 SvcLogicContext ctx = new SvcLogicContext();
164 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
165 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
166 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
167 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
168 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
169 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
170 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
171 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
173 Map<String, String> p = new HashMap<>();
174 p.put("templateFileName", "src/test/resourcess/test-template.json");
175 p.put("restapiUrl", "http://echo.getpostman.com");
176 p.put("restapiUser", "user1");
177 p.put("restapiPassword", "abc123");
178 p.put("format", "json");
179 p.put("httpMethod", "post");
180 p.put("responsePrefix", "response");
181 p.put("skipSending", "true");
183 RestapiCallNode rcn = new RestapiCallNode();
184 rcn.sendRequest(p, ctx);
187 @Test(expected = SvcLogicException.class)
188 public void testWithoutSkipSending() throws SvcLogicException {
189 SvcLogicContext ctx = new SvcLogicContext();
190 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
191 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
192 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
193 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
194 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
195 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
196 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
197 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
199 Map<String, String> p = new HashMap<>();
200 p.put("templateFileName", "src/test/resources/test-template.json");
201 p.put("restapiUrl", "http://echo.getpostman.com");
202 p.put("restapiUser", "user1");
203 p.put("restapiPassword", "abc123");
204 p.put("format", "json");
205 p.put("httpMethod", "post");
206 p.put("responsePrefix", "response");
207 p.put("skipSending", "false");
209 RestapiCallNode rcn = new RestapiCallNode();
210 rcn.sendRequest(p, ctx);
214 @Test(expected = SvcLogicException.class)
215 public void testWithInvalidURI() throws SvcLogicException {
216 SvcLogicContext ctx = new SvcLogicContext();
217 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
218 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
219 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
220 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
221 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
222 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
223 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
224 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
226 Map<String, String> p = new HashMap<>();
227 p.put("templateFileName", "src/test/resources/test-template.json");
228 p.put("restapiUrl", "http://echo. getpostman.com");
229 p.put("restapiUser", "user1");
230 p.put("restapiPassword", "abc123");
231 p.put("format", "json");
232 p.put("httpMethod", "post");
233 p.put("responsePrefix", "response");
234 p.put("skipSending", "false");
236 RestapiCallNode rcn = new RestapiCallNode();
237 rcn.sendRequest(p, ctx);
241 public void testVpnJsonTemplate() throws SvcLogicException {
242 SvcLogicContext ctx = new SvcLogicContext();
243 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
244 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
246 Map<String, String> p = new HashMap<>();
247 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
248 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
249 p.put("restapiUser", "admin");
250 p.put("restapiPassword", "admin123");
251 p.put("format", "json");
252 p.put("httpMethod", "post");
253 p.put("responsePrefix", "restapi-result");
254 p.put("skipSending", "true");
256 RestapiCallNode rcn = new RestapiCallNode();
257 rcn.sendRequest(p, ctx);
261 public void testSiteJsonTemplate() throws SvcLogicException {
262 SvcLogicContext ctx = new SvcLogicContext();
263 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
264 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
266 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
267 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
268 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
269 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
270 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
271 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
272 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
273 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
274 ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
275 ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
276 ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
277 ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
279 ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
280 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
281 ctx.setAttribute("prop.l3vpn.entry2-id", "1");
282 ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
283 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
284 ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
285 ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
286 ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
287 ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
288 ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
289 ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
290 ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
292 Map<String, String> p = new HashMap<>();
293 p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
294 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
295 p.put("restapiUser", "admin");
296 p.put("restapiPassword", "admin123");
297 p.put("format", "json");
298 p.put("httpMethod", "post");
299 p.put("responsePrefix", "restapi-result");
300 p.put("skipSending", "true");
302 RestapiCallNode rcn = new RestapiCallNode();
303 rcn.sendRequest(p, ctx);
307 public void testVrfJsonTemplate() throws SvcLogicException {
308 SvcLogicContext ctx = new SvcLogicContext();
309 ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
310 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
311 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
312 ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
313 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
314 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
316 Map<String, String> p = new HashMap<>();
317 p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
318 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
319 p.put("restapiUser", "admin");
320 p.put("restapiPassword", "admin123");
321 p.put("format", "json");
322 p.put("httpMethod", "post");
323 p.put("responsePrefix", "restapi-result");
324 p.put("skipSending", "true");
326 RestapiCallNode rcn = new RestapiCallNode();
327 rcn.sendRequest(p, ctx);
331 public void testDeleteVpnJsonTemplate() throws SvcLogicException {
332 SvcLogicContext ctx = new SvcLogicContext();
333 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
334 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
336 Map<String, String> p = new HashMap<>();
337 //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
338 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
339 + "/vpnservice=10000000-0000-0000-0000-000000000001");
340 p.put("restapiUser", "admin");
341 p.put("restapiPassword", "admin123");
342 p.put("format", "json");
343 p.put("httpMethod", "delete");
344 p.put("responsePrefix", "restapi-result");
345 p.put("skipSending", "true");
347 RestapiCallNode rcn = new RestapiCallNode();
348 rcn.sendRequest(p, ctx);
352 public void testL2DciTemplate() throws SvcLogicException {
353 SvcLogicContext ctx = new SvcLogicContext();
354 ctx.setAttribute("prop.dci-connects.id", "Id1");
355 ctx.setAttribute("prop.dci-connects.name", "Name1");
356 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
357 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
358 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
359 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
360 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
361 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
362 ctx.setAttribute("prop.dci-connects.vni", "1");
364 Map<String, String> p = new HashMap<>();
365 p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
366 p.put("restapiUrl", "http://echo.getpostman.com");
367 p.put("restapiUser", "user1");
368 p.put("restapiPassword", "abc123");
369 p.put("format", "json");
370 p.put("httpMethod", "post");
371 p.put("responsePrefix", "response");
372 p.put("skipSending", "true");
374 RestapiCallNode rcn = new RestapiCallNode();
375 rcn.sendRequest(p, ctx);
379 public void testL3DciTemplate() throws SvcLogicException {
380 SvcLogicContext ctx = new SvcLogicContext();
381 ctx.setAttribute("prop.dci-connects.id", "Id1");
382 ctx.setAttribute("prop.dci-connects.name", "Name1");
383 ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
384 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
385 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
386 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
387 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
388 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
389 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
390 ctx.setAttribute("prop.dci-connects.vni", "1");
392 Map<String, String> p = new HashMap<>();
393 p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
394 p.put("restapiUrl", "http://echo.getpostman.com");
395 p.put("restapiUser", "user1");
396 p.put("restapiPassword", "abc123");
397 p.put("format", "json");
398 p.put("httpMethod", "post");
399 p.put("responsePrefix", "response");
400 p.put("skipSending", "true");
402 RestapiCallNode rcn = new RestapiCallNode();
403 rcn.sendRequest(p, ctx);
408 public void testControllerTokenTemplate() throws SvcLogicException {
409 SvcLogicContext ctx = new SvcLogicContext();
410 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
411 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
413 Map<String, String> p = new HashMap<>();
414 p.put("templateFileName", "src/test/resources/actokentemplate.json");
415 p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
416 p.put("format", "json");
417 p.put("httpMethod", "post");
418 p.put("responsePrefix", "restapi-result");
419 p.put("skipSending", "true");
421 RestapiCallNode rcn = new RestapiCallNode();
422 rcn.sendRequest(p, ctx);
427 public void testDeleteNoneAsContentType() throws SvcLogicException {
428 SvcLogicContext ctx = new SvcLogicContext();
430 Map<String, String> p = new HashMap<>();
431 p.put("restapiUrl", "https://echo.getpostman.com/delete");
432 p.put("restapiUser", "user1");
433 p.put("restapiPassword", "pwd1");
434 p.put("httpMethod", "delete");
435 p.put("format", "none");
436 p.put("skipSending", "true");
438 RestapiCallNode rcn = new RestapiCallNode();
439 rcn.sendRequest(p, ctx);
443 public void testPostNoneAsContentType() throws SvcLogicException {
444 SvcLogicContext ctx = new SvcLogicContext();
445 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
446 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
448 Map<String, String> p = new HashMap<>();
449 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
450 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
451 p.put("restapiUser", "admin");
452 p.put("restapiPassword", "admin123");
453 p.put("format", "none");
454 p.put("httpMethod", "post");
455 p.put("responsePrefix", "restapi-result");
456 p.put("skipSending", "true");
458 RestapiCallNode rcn = new RestapiCallNode();
459 rcn.sendRequest(p, ctx);
464 "url": "http://localhost:7001" 4 http://uebsb93kcdc.it.att.com:3904",
468 "url": "http://localhost:7002",
469 "user": "controller_user",
470 "password": "P@ssword",
474 "url": "http://localhost:7003",
475 "user": "controller_admin"
480 public void testPartners() throws Exception{
481 String partnerTwoKey = "partnerTwo";
482 String partnerTwoUsername = "controller_user";
483 String partnerTwoPassword = "P@ssword";
485 System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
486 RestapiCallNode rcn = new RestapiCallNode();
487 assertNull(rcn.partnerStore.get("partnerOne"));
488 PartnerDetails details = rcn.partnerStore.get(partnerTwoKey);
489 assertEquals(partnerTwoUsername,details.username);
490 assertEquals(partnerTwoPassword,details.password);
491 assertNull(rcn.partnerStore.get("partnerThree"));
493 //In this scenario the caller expects username, password and url to be picked up from the partners json
494 Map<String, String> paramMap = new HashMap<>();
495 paramMap.put("partner", partnerTwoKey);
496 rcn.handlePartner(paramMap );
497 assertEquals(partnerTwoUsername,paramMap.get(RestapiCallNode.restapiUserKey));
498 assertEquals(partnerTwoPassword,paramMap.get(RestapiCallNode.restapiPasswordKey));
499 assertEquals("http://localhost:7002",paramMap.get(RestapiCallNode.restapiUrlString));
501 //In this scenario the caller expects username, password and url to be picked up from the partners json
502 //the provided suffix will be appended to the default url from the partners json
503 paramMap = new HashMap<>();
504 paramMap.put("partner", partnerTwoKey);
505 paramMap.put("restapiUrlSuffix", "/networking/v1/instance/3");
506 rcn.handlePartner(paramMap);
507 Parameters p = new Parameters();
508 RestapiCallNode.getParameters(paramMap, p);
509 assertEquals(partnerTwoUsername,p.restapiUser);
510 assertEquals(partnerTwoPassword,p.restapiPassword);
511 assertEquals("http://localhost:7002/networking/v1/instance/3",p.restapiUrl);
515 public void retryPolicyBean() throws Exception {
517 String first = "http://localhost:7001";
518 String second = "http://localhost:7001";
520 RetryPolicy p = new RetryPolicy(new String[] {first,second}, retries);
521 assertEquals(retries,p.getMaximumRetries());
522 assertNotNull(p.getRetryMessage());
523 String next = p.getNextHostName();
524 assertEquals(second,next);
525 assertEquals(1,p.getRetryCount());
526 next = p.getNextHostName();
527 assertEquals(first,next);
528 assertEquals(2,p.getRetryCount());
532 public void testEmbeddedJsonTemplate() throws Exception {
533 SvcLogicContext ctx = new SvcLogicContext();
534 String complexObj = "{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}";
535 ctx.setAttribute("reqId", "1235");
536 ctx.setAttribute("subReqId", "054243");
537 ctx.setAttribute("actionName", "CREATE");
538 ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0");
539 ctx.setAttribute("complexObj", complexObj);
540 RestapiCallNode rcn = new RestapiCallNode();
541 String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testEmbeddedTemplate.json"), Format.JSON);
542 //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON
543 assertNotNull(new JSONObject(request));
547 public void testMultiLineEmbeddedJsonTemplate() throws Exception {
548 SvcLogicContext ctx = new SvcLogicContext();
549 String complexObj = "{\n"
550 + " \"image_name\": \"Ubuntu 14.04\",\n"
551 + " \"service-instance-id\": \"1\",\n"
552 + " \"vnf-model-customization-uuid\": \"2f\",\n"
553 + " \"vnf-id\": \"3b\"\n"
555 ctx.setAttribute("reqId", "1235");
556 ctx.setAttribute("subReqId", "054243");
557 ctx.setAttribute("actionName", "CREATE");
558 ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0");
559 ctx.setAttribute("complexObj", complexObj);
560 RestapiCallNode rcn = new RestapiCallNode();
561 String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testMultiLineEmbeddedTemplate.json"), Format.JSON);
562 //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON
563 assertNotNull(new JSONObject(request));