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;
28 import java.util.HashMap;
31 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 testJsonTemplate() throws SvcLogicException {
85 SvcLogicContext ctx = new SvcLogicContext();
86 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
87 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
88 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
89 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
90 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
91 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
92 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
93 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
94 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
95 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
96 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
97 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
98 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
99 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
100 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
101 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
102 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
103 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
104 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
105 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
106 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
107 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
109 Map<String, String> p = new HashMap<>();
110 p.put("templateFileName", "src/test/resources/test-template.json");
111 p.put("restapiUrl", "http://echo.getpostman.com");
112 p.put("restapiUser", "user1");
113 p.put("restapiPassword", "abc123");
114 p.put("format", "json");
115 p.put("httpMethod", "post");
116 p.put("responsePrefix", "response");
117 p.put("skipSending", "true");
119 RestapiCallNode rcn = new RestapiCallNode();
120 rcn.sendRequest(p, ctx);
124 public void testInvalidRepeatTimes() throws SvcLogicException {
125 SvcLogicContext ctx = new SvcLogicContext();
126 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
127 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
128 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
129 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
130 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
131 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
132 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
133 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
135 Map<String, String> p = new HashMap<>();
136 p.put("templateFileName", "src/test/resources/test-template.json");
137 p.put("restapiUrl", "http://echo.getpostman.com");
138 p.put("restapiUser", "user1");
139 p.put("restapiPassword", "abc123");
140 p.put("format", "json");
141 p.put("httpMethod", "post");
142 p.put("responsePrefix", "response");
143 p.put("skipSending", "true");
145 RestapiCallNode rcn = new RestapiCallNode();
146 rcn.sendRequest(p, ctx);
149 @Test(expected = SvcLogicException.class)
150 public void testInvalidTemplatePath() throws SvcLogicException {
151 SvcLogicContext ctx = new SvcLogicContext();
152 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
153 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
154 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
155 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
156 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
157 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
158 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
159 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
161 Map<String, String> p = new HashMap<>();
162 p.put("templateFileName", "src/test/resourcess/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");
171 RestapiCallNode rcn = new RestapiCallNode();
172 rcn.sendRequest(p, ctx);
175 @Test(expected = SvcLogicException.class)
176 public void testWithoutSkipSending() throws SvcLogicException {
177 SvcLogicContext ctx = new SvcLogicContext();
178 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
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");
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", "false");
197 RestapiCallNode rcn = new RestapiCallNode();
198 rcn.sendRequest(p, ctx);
202 @Test(expected = SvcLogicException.class)
203 public void testWithInvalidURI() throws SvcLogicException {
204 SvcLogicContext ctx = new SvcLogicContext();
205 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
206 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
207 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
208 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
209 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
210 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
211 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
212 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
214 Map<String, String> p = new HashMap<>();
215 p.put("templateFileName", "src/test/resources/test-template.json");
216 p.put("restapiUrl", "http://echo. getpostman.com");
217 p.put("restapiUser", "user1");
218 p.put("restapiPassword", "abc123");
219 p.put("format", "json");
220 p.put("httpMethod", "post");
221 p.put("responsePrefix", "response");
222 p.put("skipSending", "false");
224 RestapiCallNode rcn = new RestapiCallNode();
225 rcn.sendRequest(p, ctx);
229 public void testVpnJsonTemplate() throws SvcLogicException {
230 SvcLogicContext ctx = new SvcLogicContext();
231 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
232 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
234 Map<String, String> p = new HashMap<>();
235 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
236 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
237 p.put("restapiUser", "admin");
238 p.put("restapiPassword", "admin123");
239 p.put("format", "json");
240 p.put("httpMethod", "post");
241 p.put("responsePrefix", "restapi-result");
242 p.put("skipSending", "true");
244 RestapiCallNode rcn = new RestapiCallNode();
245 rcn.sendRequest(p, ctx);
249 public void testSiteJsonTemplate() throws SvcLogicException {
250 SvcLogicContext ctx = new SvcLogicContext();
251 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
252 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
254 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
255 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
256 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
257 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
258 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
259 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
260 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
261 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
262 ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
263 ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
264 ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
265 ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
267 ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
268 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
269 ctx.setAttribute("prop.l3vpn.entry2-id", "1");
270 ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
271 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
272 ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
273 ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
274 ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
275 ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
276 ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
277 ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
278 ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
280 Map<String, String> p = new HashMap<>();
281 p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
282 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
283 p.put("restapiUser", "admin");
284 p.put("restapiPassword", "admin123");
285 p.put("format", "json");
286 p.put("httpMethod", "post");
287 p.put("responsePrefix", "restapi-result");
288 p.put("skipSending", "true");
290 RestapiCallNode rcn = new RestapiCallNode();
291 rcn.sendRequest(p, ctx);
295 public void testVrfJsonTemplate() throws SvcLogicException {
296 SvcLogicContext ctx = new SvcLogicContext();
297 ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
298 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
299 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
300 ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
301 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
302 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
304 Map<String, String> p = new HashMap<>();
305 p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
306 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
307 p.put("restapiUser", "admin");
308 p.put("restapiPassword", "admin123");
309 p.put("format", "json");
310 p.put("httpMethod", "post");
311 p.put("responsePrefix", "restapi-result");
312 p.put("skipSending", "true");
314 RestapiCallNode rcn = new RestapiCallNode();
315 rcn.sendRequest(p, ctx);
319 public void testDeleteVpnJsonTemplate() throws SvcLogicException {
320 SvcLogicContext ctx = new SvcLogicContext();
321 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
322 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
324 Map<String, String> p = new HashMap<>();
325 //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
326 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
327 + "/vpnservice=10000000-0000-0000-0000-000000000001");
328 p.put("restapiUser", "admin");
329 p.put("restapiPassword", "admin123");
330 p.put("format", "json");
331 p.put("httpMethod", "delete");
332 p.put("responsePrefix", "restapi-result");
333 p.put("skipSending", "true");
335 RestapiCallNode rcn = new RestapiCallNode();
336 rcn.sendRequest(p, ctx);
340 public void testL2DciTemplate() throws SvcLogicException {
341 SvcLogicContext ctx = new SvcLogicContext();
342 ctx.setAttribute("prop.dci-connects.id", "Id1");
343 ctx.setAttribute("prop.dci-connects.name", "Name1");
344 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
345 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
346 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
347 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
348 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
349 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
350 ctx.setAttribute("prop.dci-connects.vni", "1");
352 Map<String, String> p = new HashMap<>();
353 p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
354 p.put("restapiUrl", "http://echo.getpostman.com");
355 p.put("restapiUser", "user1");
356 p.put("restapiPassword", "abc123");
357 p.put("format", "json");
358 p.put("httpMethod", "post");
359 p.put("responsePrefix", "response");
360 p.put("skipSending", "true");
362 RestapiCallNode rcn = new RestapiCallNode();
363 rcn.sendRequest(p, ctx);
367 public void testL3DciTemplate() throws SvcLogicException {
368 SvcLogicContext ctx = new SvcLogicContext();
369 ctx.setAttribute("prop.dci-connects.id", "Id1");
370 ctx.setAttribute("prop.dci-connects.name", "Name1");
371 ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
372 ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
373 ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
374 ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
375 ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
376 ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
377 ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
378 ctx.setAttribute("prop.dci-connects.vni", "1");
380 Map<String, String> p = new HashMap<>();
381 p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
382 p.put("restapiUrl", "http://echo.getpostman.com");
383 p.put("restapiUser", "user1");
384 p.put("restapiPassword", "abc123");
385 p.put("format", "json");
386 p.put("httpMethod", "post");
387 p.put("responsePrefix", "response");
388 p.put("skipSending", "true");
390 RestapiCallNode rcn = new RestapiCallNode();
391 rcn.sendRequest(p, ctx);
396 public void testControllerTokenTemplate() throws SvcLogicException {
397 SvcLogicContext ctx = new SvcLogicContext();
398 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
399 ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
401 Map<String, String> p = new HashMap<>();
402 p.put("templateFileName", "src/test/resources/actokentemplate.json");
403 p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
404 p.put("format", "json");
405 p.put("httpMethod", "post");
406 p.put("responsePrefix", "restapi-result");
407 p.put("skipSending", "true");
409 RestapiCallNode rcn = new RestapiCallNode();
410 rcn.sendRequest(p, ctx);
415 public void testDeleteNoneAsContentType() throws SvcLogicException {
416 SvcLogicContext ctx = new SvcLogicContext();
418 Map<String, String> p = new HashMap<>();
419 p.put("restapiUrl", "https://echo.getpostman.com/delete");
420 p.put("restapiUser", "user1");
421 p.put("restapiPassword", "pwd1");
422 p.put("httpMethod", "delete");
423 p.put("format", "none");
424 p.put("skipSending", "true");
426 RestapiCallNode rcn = new RestapiCallNode();
427 rcn.sendRequest(p, ctx);
431 public void testPostNoneAsContentType() throws SvcLogicException {
432 SvcLogicContext ctx = new SvcLogicContext();
433 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
434 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
436 Map<String, String> p = new HashMap<>();
437 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
438 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
439 p.put("restapiUser", "admin");
440 p.put("restapiPassword", "admin123");
441 p.put("format", "none");
442 p.put("httpMethod", "post");
443 p.put("responsePrefix", "restapi-result");
444 p.put("skipSending", "true");
446 RestapiCallNode rcn = new RestapiCallNode();
447 rcn.sendRequest(p, ctx);
452 "url": "http://localhost:7001" 4 http://uebsb93kcdc.it.att.com:3904",
456 "url": "http://localhost:7002",
457 "user": "controller_user",
458 "password": "P@ssword",
462 "url": "http://localhost:7003",
463 "user": "controller_admin"
468 public void testPartners() throws Exception{
469 String partnerTwoKey = "partnerTwo";
470 String partnerTwoUsername = "controller_user";
471 String partnerTwoPassword = "P@ssword";
473 System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
474 RestapiCallNode rcn = new RestapiCallNode();
475 assertNull(rcn.partnerStore.get("partnerOne"));
476 PartnerDetails details = rcn.partnerStore.get(partnerTwoKey);
477 assertEquals(partnerTwoUsername,details.username);
478 assertEquals(partnerTwoPassword,details.password);
479 assertNull(rcn.partnerStore.get("partnerThree"));
481 //In this scenario the caller expects username, password and url to be picked up from the partners json
482 Map<String, String> paramMap = new HashMap<String,String>();
483 paramMap.put("partner", partnerTwoKey);
484 rcn.handlePartner(paramMap );
485 assertEquals(partnerTwoUsername,paramMap.get(rcn.restapiUserKey));
486 assertEquals(partnerTwoPassword,paramMap.get(rcn.restapiPasswordKey));
487 assertEquals("http://localhost:7002",paramMap.get(rcn.restapiUrlString));
489 //In this scenario the caller expects username, password and url to be picked up from the partners json
490 //the provided suffix will be appended to the default url from the partners json
491 paramMap = new HashMap<String,String>();
492 paramMap.put("partner", partnerTwoKey);
493 paramMap.put("restapiUrlSuffix", "/networking/v1/instance/3");
494 rcn.handlePartner(paramMap);
495 Parameters p = new Parameters();
496 RestapiCallNode.getParameters(paramMap, p);
497 assertEquals(partnerTwoUsername,p.restapiUser);
498 assertEquals(partnerTwoPassword,p.restapiPassword);
499 assertEquals("http://localhost:7002/networking/v1/instance/3",p.restapiUrl);
503 public void retryPolicyBean() throws Exception {
505 String first = "http://localhost:7001";
506 String second = "http://localhost:7001";
508 RetryPolicy p = new RetryPolicy(new String[] {first,second}, retries);
509 assertEquals(retries,p.getMaximumRetries());
510 assertNotNull(p.getRetryMessage());
511 String next = p.getNextHostName();
512 assertEquals(second,next);
513 assertEquals(1,p.getRetryCount());
514 next = p.getNextHostName();
515 assertEquals(first,next);
516 assertEquals(2,p.getRetryCount());
520 public void testEmbeddedJsonTemplate() throws Exception {
521 SvcLogicContext ctx = new SvcLogicContext();
522 String complexObj = "{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}";
523 ctx.setAttribute("reqId", "1235");
524 ctx.setAttribute("subReqId", "054243");
525 ctx.setAttribute("actionName", "CREATE");
526 ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0");
527 ctx.setAttribute("complexObj", complexObj);
528 RestapiCallNode rcn = new RestapiCallNode();
529 String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testEmbeddedTemplate.json"), Format.JSON);
530 //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON
531 JSONObject requestObj = new JSONObject(request);