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