implement generic retry and partners in restapicallnode
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / test / java / 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 org.onap.ccsdk.sli.plugins.restapicall;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import org.codehaus.jettison.json.JSONObject;
32 import org.glassfish.grizzly.http.server.HttpServer;
33 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
34 import org.glassfish.jersey.media.multipart.MultiPartFeature;
35 import org.glassfish.jersey.server.ResourceConfig;
36
37 import org.junit.Test;
38 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
39 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
40 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43
44 public class TestRestapiCallNode {
45
46     @SuppressWarnings("unused")
47     private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
48
49     @Test
50     public void testDelete() throws SvcLogicException {
51         SvcLogicContext ctx = new SvcLogicContext();
52
53         Map<String, String> p = new HashMap<>();
54         p.put("restapiUrl", "https://echo.getpostman.com/delete");
55         p.put("restapiUser", "user1");
56         p.put("restapiPassword", "pwd1");
57         p.put("httpMethod", "delete");
58         p.put("skipSending", "true");
59
60         RestapiCallNode rcn = new RestapiCallNode();
61         rcn.sendRequest(p, ctx);
62     }
63
64     @Test
65     public void testDeleteWithPayload() throws SvcLogicException {
66         SvcLogicContext ctx = new SvcLogicContext();
67
68         ctx.setAttribute("prop.name", "site1");
69
70         Map<String, String> p = new HashMap<>();
71         p.put("templateFileName", "src/test/resources/sdwan-site.json");
72         p.put("restapiUrl", "https://echo.getpostman.com/delete");
73         p.put("restapiUser", "user1");
74         p.put("restapiPassword", "pwd1");
75         p.put("httpMethod", "delete");
76         p.put("skipSending", "true");
77
78         RestapiCallNode rcn = new RestapiCallNode();
79         rcn.sendRequest(p, ctx);
80     }
81
82     @Test
83     public void testJsonTemplate() throws SvcLogicException {
84         SvcLogicContext ctx = new SvcLogicContext();
85         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
86         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
87         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
88         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
89         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
90         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
91         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
92         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
93         ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
94         ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
95         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
96         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
97         ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
98         ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
99         ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
100         ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
101         ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
102         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
103         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
104         ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
105         ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
106         ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
107
108         Map<String, String> p = new HashMap<>();
109         p.put("templateFileName", "src/test/resources/test-template.json");
110         p.put("restapiUrl", "http://echo.getpostman.com");
111         p.put("restapiUser", "user1");
112         p.put("restapiPassword", "abc123");
113         p.put("format", "json");
114         p.put("httpMethod", "post");
115         p.put("responsePrefix", "response");
116         p.put("skipSending", "true");
117
118         RestapiCallNode rcn = new RestapiCallNode();
119         rcn.sendRequest(p, ctx);
120     }
121
122     @Test
123     public void testInvalidRepeatTimes() throws SvcLogicException {
124         SvcLogicContext ctx = new SvcLogicContext();
125         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
126         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
127         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
128         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
129         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
130         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
131         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
132         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
133
134         Map<String, String> p = new HashMap<>();
135         p.put("templateFileName", "src/test/resources/test-template.json");
136         p.put("restapiUrl", "http://echo.getpostman.com");
137         p.put("restapiUser", "user1");
138         p.put("restapiPassword", "abc123");
139         p.put("format", "json");
140         p.put("httpMethod", "post");
141         p.put("responsePrefix", "response");
142         p.put("skipSending", "true");
143
144         RestapiCallNode rcn = new RestapiCallNode();
145         rcn.sendRequest(p, ctx);
146     }
147
148     @Test(expected = SvcLogicException.class)
149     public void testInvalidTemplatePath() throws SvcLogicException {
150         SvcLogicContext ctx = new SvcLogicContext();
151         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
152         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
153         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
154         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
155         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
156         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
157         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
158         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
159
160         Map<String, String> p = new HashMap<>();
161         p.put("templateFileName", "src/test/resourcess/test-template.json");
162         p.put("restapiUrl", "http://echo.getpostman.com");
163         p.put("restapiUser", "user1");
164         p.put("restapiPassword", "abc123");
165         p.put("format", "json");
166         p.put("httpMethod", "post");
167         p.put("responsePrefix", "response");
168         p.put("skipSending", "true");
169
170         RestapiCallNode rcn = new RestapiCallNode();
171         rcn.sendRequest(p, ctx);
172     }
173
174     @Test(expected = SvcLogicException.class)
175     public void testWithoutSkipSending() throws SvcLogicException {
176         SvcLogicContext ctx = new SvcLogicContext();
177         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
178         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
179         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
180         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
181         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
182         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
183         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
184         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
185
186         Map<String, String> p = new HashMap<>();
187         p.put("templateFileName", "src/test/resources/test-template.json");
188         p.put("restapiUrl", "http://echo.getpostman.com");
189         p.put("restapiUser", "user1");
190         p.put("restapiPassword", "abc123");
191         p.put("format", "json");
192         p.put("httpMethod", "post");
193         p.put("responsePrefix", "response");
194         p.put("skipSending", "false");
195
196         RestapiCallNode rcn = new RestapiCallNode();
197         rcn.sendRequest(p, ctx);
198     }
199
200
201     @Test(expected = SvcLogicException.class)
202     public void testWithInvalidURI() throws SvcLogicException {
203         SvcLogicContext ctx = new SvcLogicContext();
204         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
205         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
206         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
207         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
208         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
209         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
210         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
211         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
212
213         Map<String, String> p = new HashMap<>();
214         p.put("templateFileName", "src/test/resources/test-template.json");
215         p.put("restapiUrl", "http://echo.  getpostman.com");
216         p.put("restapiUser", "user1");
217         p.put("restapiPassword", "abc123");
218         p.put("format", "json");
219         p.put("httpMethod", "post");
220         p.put("responsePrefix", "response");
221         p.put("skipSending", "false");
222
223         RestapiCallNode rcn = new RestapiCallNode();
224         rcn.sendRequest(p, ctx);
225     }
226
227     @Test
228     public void testVpnJsonTemplate() throws SvcLogicException {
229         SvcLogicContext ctx = new SvcLogicContext();
230         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
231         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
232
233         Map<String, String> p = new HashMap<>();
234         p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
235         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
236         p.put("restapiUser", "admin");
237         p.put("restapiPassword", "admin123");
238         p.put("format", "json");
239         p.put("httpMethod", "post");
240         p.put("responsePrefix", "restapi-result");
241         p.put("skipSending", "true");
242
243         RestapiCallNode rcn = new RestapiCallNode();
244         rcn.sendRequest(p, ctx);
245     }
246
247     @Test
248     public void testSiteJsonTemplate() throws SvcLogicException {
249         SvcLogicContext ctx = new SvcLogicContext();
250         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
251         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
252
253         ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
254         ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
255         ctx.setAttribute("prop.l3vpn.entry1-id", "1");
256         ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
257         ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
258         ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
259         ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
260         ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
261         ctx.setAttribute("prop.l3vpn.sna1_svlan", "100");
262         ctx.setAttribute("prop.l3vpn.ac1_protocol", "static");
263         ctx.setAttribute("prop.l3vpn.sna1-route.ip-prefix", "192.168.1.1/24");
264         ctx.setAttribute("prop.l3vpn.sna1-route.next-hop", "192.168.1.4");
265
266         ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
267         ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
268         ctx.setAttribute("prop.l3vpn.entry2-id", "1");
269         ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
270         ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
271         ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
272         ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.6");
273         ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
274         ctx.setAttribute("prop.l3vpn.sna2_svlan", "200");
275         ctx.setAttribute("prop.l3vpn.ac2_protocol", "bgp");
276         ctx.setAttribute("prop.l3vpn.peer2-ip", "192.168.1.7");
277         ctx.setAttribute("prop.l3vpn.ac2_protocol_bgp_as", "200");
278
279         Map<String, String> p = new HashMap<>();
280         p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
281         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
282         p.put("restapiUser", "admin");
283         p.put("restapiPassword", "admin123");
284         p.put("format", "json");
285         p.put("httpMethod", "post");
286         p.put("responsePrefix", "restapi-result");
287         p.put("skipSending", "true");
288
289         RestapiCallNode rcn = new RestapiCallNode();
290         rcn.sendRequest(p, ctx);
291     }
292
293     @Test
294     public void testVrfJsonTemplate() throws SvcLogicException {
295         SvcLogicContext ctx = new SvcLogicContext();
296         ctx.setAttribute("prop.l3vpn.vrf1-id", "10000000-0000-0000-0000-000000000007");
297         ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
298         ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
299         ctx.setAttribute("prop.l3vpn.vrf2-id", "10000000-0000-0000-0000-000000000009");
300         ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
301         ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
302
303         Map<String, String> p = new HashMap<>();
304         p.put("templateFileName", "src/test/resources/l3smvrftemplate.json");
305         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vrf-attributes");
306         p.put("restapiUser", "admin");
307         p.put("restapiPassword", "admin123");
308         p.put("format", "json");
309         p.put("httpMethod", "post");
310         p.put("responsePrefix", "restapi-result");
311         p.put("skipSending", "true");
312
313         RestapiCallNode rcn = new RestapiCallNode();
314         rcn.sendRequest(p, ctx);
315     }
316
317     @Test
318     public void testDeleteVpnJsonTemplate() throws SvcLogicException {
319         SvcLogicContext ctx = new SvcLogicContext();
320         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
321         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
322
323         Map<String, String> p = new HashMap<>();
324         //p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
325         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services"
326             + "/vpnservice=10000000-0000-0000-0000-000000000001");
327         p.put("restapiUser", "admin");
328         p.put("restapiPassword", "admin123");
329         p.put("format", "json");
330         p.put("httpMethod", "delete");
331         p.put("responsePrefix", "restapi-result");
332         p.put("skipSending", "true");
333
334         RestapiCallNode rcn = new RestapiCallNode();
335         rcn.sendRequest(p, ctx);
336     }
337
338     @Test
339     public void testL2DciTemplate() throws SvcLogicException {
340         SvcLogicContext ctx = new SvcLogicContext();
341         ctx.setAttribute("prop.dci-connects.id", "Id1");
342         ctx.setAttribute("prop.dci-connects.name", "Name1");
343         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
344         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
345         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
346         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
347         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
348         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
349         ctx.setAttribute("prop.dci-connects.vni", "1");
350
351         Map<String, String> p = new HashMap<>();
352         p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
353         p.put("restapiUrl", "http://echo.getpostman.com");
354         p.put("restapiUser", "user1");
355         p.put("restapiPassword", "abc123");
356         p.put("format", "json");
357         p.put("httpMethod", "post");
358         p.put("responsePrefix", "response");
359         p.put("skipSending", "true");
360
361         RestapiCallNode rcn = new RestapiCallNode();
362         rcn.sendRequest(p, ctx);
363     }
364
365     @Test
366     public void testL3DciTemplate() throws SvcLogicException {
367         SvcLogicContext ctx = new SvcLogicContext();
368         ctx.setAttribute("prop.dci-connects.id", "Id1");
369         ctx.setAttribute("prop.dci-connects.name", "Name1");
370         ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
371         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
372         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
373         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
374         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
375         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
376         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
377         ctx.setAttribute("prop.dci-connects.vni", "1");
378
379         Map<String, String> p = new HashMap<>();
380         p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
381         p.put("restapiUrl", "http://echo.getpostman.com");
382         p.put("restapiUser", "user1");
383         p.put("restapiPassword", "abc123");
384         p.put("format", "json");
385         p.put("httpMethod", "post");
386         p.put("responsePrefix", "response");
387         p.put("skipSending", "true");
388
389         RestapiCallNode rcn = new RestapiCallNode();
390         rcn.sendRequest(p, ctx);
391
392     }
393
394     @Test
395     public void testControllerTokenTemplate() throws SvcLogicException {
396         SvcLogicContext ctx = new SvcLogicContext();
397         ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.user", "admin");
398         ctx.setAttribute("prop.sdncRestApi.thirdpartySdnc.password", "admin123");
399
400         Map<String, String> p = new HashMap<>();
401         p.put("templateFileName", "src/test/resources/actokentemplate.json");
402         p.put("restapiUrl", "https://ipwan:18002/controller/v2/tokens");
403         p.put("format", "json");
404         p.put("httpMethod", "post");
405         p.put("responsePrefix", "restapi-result");
406         p.put("skipSending", "true");
407
408         RestapiCallNode rcn = new RestapiCallNode();
409         rcn.sendRequest(p, ctx);
410     }
411
412
413     @Test
414     public void testDeleteNoneAsContentType() throws SvcLogicException {
415         SvcLogicContext ctx = new SvcLogicContext();
416
417         Map<String, String> p = new HashMap<>();
418         p.put("restapiUrl", "https://echo.getpostman.com/delete");
419         p.put("restapiUser", "user1");
420         p.put("restapiPassword", "pwd1");
421         p.put("httpMethod", "delete");
422         p.put("format", "none");
423         p.put("skipSending", "true");
424
425         RestapiCallNode rcn = new RestapiCallNode();
426         rcn.sendRequest(p, ctx);
427     }
428
429     @Test
430     public void testPostNoneAsContentType() throws SvcLogicException {
431         SvcLogicContext ctx = new SvcLogicContext();
432         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
433         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
434
435         Map<String, String> p = new HashMap<>();
436         p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
437         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
438         p.put("restapiUser", "admin");
439         p.put("restapiPassword", "admin123");
440         p.put("format", "none");
441         p.put("httpMethod", "post");
442         p.put("responsePrefix", "restapi-result");
443         p.put("skipSending", "true");
444
445         RestapiCallNode rcn = new RestapiCallNode();
446         rcn.sendRequest(p, ctx);
447     }
448     /*
449      * {
450   "partnerOne": {
451     "url": "http://localhost:7001"                                                                                                                                                             4 http://uebsb93kcdc.it.att.com:3904",
452     "test": "/metrics"
453   },
454   "partnerTwo": {
455     "url": "http://localhost:7002",
456     "user": "controller_user",
457     "password": "P@ssword",
458     "test": "/metrics"
459   },
460   "partnerThree": {
461     "url": "http://localhost:7003",
462     "user": "controller_admin"
463   }
464 }
465      */
466     @Test
467     public void testPartners() throws Exception{
468         String partnerTwoKey = "partnerTwo";
469         String partnerTwoUsername = "controller_user";
470         String partnerTwoPassword = "P@ssword";
471
472         System.setProperty("SDNC_CONFIG_DIR", "src/test/resources");
473         RestapiCallNode rcn = new RestapiCallNode();
474         assertNull(rcn.partnerStore.get("partnerOne"));
475         PartnerDetails details = rcn.partnerStore.get(partnerTwoKey);
476         assertEquals(partnerTwoUsername,details.username);
477         assertEquals(partnerTwoPassword,details.password);
478         assertNull(rcn.partnerStore.get("partnerThree"));
479         
480         //In this scenario the caller expects username, password and url to be picked up from the partners json
481         Map<String, String> paramMap = new HashMap<String,String>();
482         paramMap.put("partner", partnerTwoKey);
483         rcn.handlePartner(paramMap );
484         assertEquals(partnerTwoUsername,paramMap.get(rcn.restapiUserKey));
485         assertEquals(partnerTwoPassword,paramMap.get(rcn.restapiPasswordKey));
486         assertEquals("http://localhost:7002",paramMap.get(rcn.restapiUrlString));
487
488         //In this scenario the caller expects username, password and url to be picked up from the partners json
489         //the provided suffix will be appended to the default url from the partners json
490         paramMap = new HashMap<String,String>();
491         paramMap.put("partner", partnerTwoKey);
492         paramMap.put("restapiUrlSuffix", "/networking/v1/instance/3");
493         rcn.handlePartner(paramMap);
494         Parameters p = new Parameters();
495         RestapiCallNode.getParameters(paramMap, p);
496         assertEquals(partnerTwoUsername,p.restapiUser);
497         assertEquals(partnerTwoPassword,p.restapiPassword);
498         assertEquals("http://localhost:7002/networking/v1/instance/3",p.restapiUrl);
499     }
500     
501     @Test
502     public void retryPolicyBean() throws Exception {
503         Integer retries = 3;
504         String first = "http://localhost:7001";
505         String second = "http://localhost:7001";
506
507         RetryPolicy p = new RetryPolicy(new String[] {first,second}, retries);
508         assertEquals(retries,p.getMaximumRetries());
509         assertNotNull(p.getRetryMessage());
510         String next = p.getNextHostName();
511         assertEquals(second,next);
512         assertEquals(1,p.getRetryCount());
513         next = p.getNextHostName();
514         assertEquals(first,next);
515         assertEquals(2,p.getRetryCount());
516     }
517
518     @Test
519     public void testEmbeddedJsonTemplate() throws Exception {
520         SvcLogicContext ctx = new SvcLogicContext();
521         String complexObj = "{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}";
522         ctx.setAttribute("reqId", "1235");
523         ctx.setAttribute("subReqId", "054243");
524         ctx.setAttribute("actionName", "CREATE");
525         ctx.setAttribute("myPrefix", "2016-09-09 16:30:35.0");
526         ctx.setAttribute("complexObj", complexObj);
527         RestapiCallNode rcn = new RestapiCallNode();
528         String request = rcn.buildXmlJsonRequest(ctx, rcn.readFile("src/test/resources/testEmbeddedTemplate.json"), Format.JSON);
529         //This will throw a JSONException and fail the test case if rest api call node doesn't form valid JSON
530         JSONObject requestObj = new JSONObject(request);
531     }
532
533 }