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 jtest.org.onap.ccsdk.sli.plugins.restapicall;
 
  24 import java.util.HashMap;
 
  26 import org.junit.Test;
 
  27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  29 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
 
  30 import org.slf4j.Logger;
 
  31 import org.slf4j.LoggerFactory;
 
  33 public class TestRestapiCallNode {
 
  35     private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
 
  39     public void testDelete() throws SvcLogicException {
 
  40         SvcLogicContext ctx = new SvcLogicContext();
 
  42         Map<String, String> p = new HashMap<String, String>();
 
  43         p.put("restapiUrl", "https://echo.getpostman.com/delete");
 
  44         p.put("restapiUser", "user1");
 
  45         p.put("restapiPassword", "pwd1");
 
  46         p.put("httpMethod", "delete");
 
  47         p.put("skipSending", "true");
 
  49         RestapiCallNode rcn = new RestapiCallNode();
 
  50         rcn.sendRequest(p, ctx);
 
  54     public void testJsonTemplate() throws SvcLogicException {
 
  55         SvcLogicContext ctx = new SvcLogicContext();
 
  56         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
 
  57         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
 
  58         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
 
  59         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
 
  60         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
 
  61         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
 
  62         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
 
  63         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
 
  64         ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
 
  65         ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
 
  66         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
 
  67         ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
 
  68         ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
 
  69         ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
 
  70         ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
 
  71         ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
 
  72         ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
 
  73         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
 
  74         ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
 
  75         ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
 
  76         ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
 
  77         ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
 
  79         Map<String, String> p = new HashMap<String, String>();
 
  80         p.put("templateFileName", "src/test/resources/test-template.json");
 
  81         p.put("restapiUrl", "http://echo.getpostman.com");
 
  82         p.put("restapiUser", "user1");
 
  83         p.put("restapiPassword", "abc123");
 
  84         p.put("format", "json");
 
  85         p.put("httpMethod", "post");
 
  86         p.put("responsePrefix", "response");
 
  87         p.put("skipSending", "true");
 
  89         RestapiCallNode rcn = new RestapiCallNode();
 
  90         rcn.sendRequest(p, ctx);
 
  93     @Test(expected = SvcLogicException.class)
 
  94     public void testInvalidRepeatTimes() throws SvcLogicException {
 
  95         SvcLogicContext ctx = new SvcLogicContext();
 
  96         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
 
  97         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
 
  98         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
 
  99         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
 
 100         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
 
 101         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
 
 102         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
 
 103         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
 
 105         Map<String, String> p = new HashMap<String, String>();
 
 106         p.put("templateFileName", "src/test/resources/test-template.json");
 
 107         p.put("restapiUrl", "http://echo.getpostman.com");
 
 108         p.put("restapiUser", "user1");
 
 109         p.put("restapiPassword", "abc123");
 
 110         p.put("format", "json");
 
 111         p.put("httpMethod", "post");
 
 112         p.put("responsePrefix", "response");
 
 113         p.put("skipSending", "true");
 
 115         RestapiCallNode rcn = new RestapiCallNode();
 
 116         rcn.sendRequest(p, ctx);
 
 119     @Test(expected = SvcLogicException.class)
 
 120     public void testInvalidTemplatePath() throws SvcLogicException {
 
 121         SvcLogicContext ctx = new SvcLogicContext();
 
 122         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 123         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
 
 124         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
 
 125         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
 
 126         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
 
 127         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
 
 128         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
 
 129         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
 
 131         Map<String, String> p = new HashMap<String, String>();
 
 132         p.put("templateFileName", "src/test/resourcess/test-template.json");
 
 133         p.put("restapiUrl", "http://echo.getpostman.com");
 
 134         p.put("restapiUser", "user1");
 
 135         p.put("restapiPassword", "abc123");
 
 136         p.put("format", "json");
 
 137         p.put("httpMethod", "post");
 
 138         p.put("responsePrefix", "response");
 
 139         p.put("skipSending", "true");
 
 141         RestapiCallNode rcn = new RestapiCallNode();
 
 142         rcn.sendRequest(p, ctx);
 
 145     @Test(expected = SvcLogicException.class)
 
 146     public void testWithoutSkipSending() throws SvcLogicException {
 
 147         SvcLogicContext ctx = new SvcLogicContext();
 
 148         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 149         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
 
 150         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
 
 151         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
 
 152         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
 
 153         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
 
 154         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
 
 155         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
 
 157         Map<String, String> p = new HashMap<String, String>();
 
 158         p.put("templateFileName", "src/test/resources/test-template.json");
 
 159         p.put("restapiUrl", "http://echo.getpostman.com");
 
 160         p.put("restapiUser", "user1");
 
 161         p.put("restapiPassword", "abc123");
 
 162         p.put("format", "json");
 
 163         p.put("httpMethod", "post");
 
 164         p.put("responsePrefix", "response");
 
 165         p.put("skipSending", "false");
 
 167         RestapiCallNode rcn = new RestapiCallNode();
 
 168         rcn.sendRequest(p, ctx);
 
 172     @Test(expected = SvcLogicException.class)
 
 173     public void testWithInvalidURI() throws SvcLogicException {
 
 174         SvcLogicContext ctx = new SvcLogicContext();
 
 175         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 176         ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
 
 177         ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
 
 178         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
 
 179         ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
 
 180         ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
 
 181         ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
 
 182         ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
 
 184         Map<String, String> p = new HashMap<String, String>();
 
 185         p.put("templateFileName", "src/test/resources/test-template.json");
 
 186         p.put("restapiUrl", "http://echo.  getpostman.com");
 
 187         p.put("restapiUser", "user1");
 
 188         p.put("restapiPassword", "abc123");
 
 189         p.put("format", "json");
 
 190         p.put("httpMethod", "post");
 
 191         p.put("responsePrefix", "response");
 
 192         p.put("skipSending", "false");
 
 194         RestapiCallNode rcn = new RestapiCallNode();
 
 195         rcn.sendRequest(p, ctx);
 
 199     public void testVpnJsonTemplate() throws SvcLogicException {
 
 200         SvcLogicContext ctx = new SvcLogicContext();
 
 201         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
 
 202         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
 
 204         Map<String, String> p = new HashMap<String, String>();
 
 205         p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
 
 206         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
 
 207         p.put("restapiUser", "admin");
 
 208         p.put("restapiPassword", "admin123");
 
 209         p.put("format", "json");
 
 210         p.put("httpMethod", "post");
 
 211         p.put("responsePrefix", "restapi-result");
 
 212         p.put("skipSending", "true");
 
 214         RestapiCallNode rcn = new RestapiCallNode();
 
 215         rcn.sendRequest(p, ctx);
 
 219     public void testSiteJsonTemplate() throws SvcLogicException {
 
 220         SvcLogicContext ctx = new SvcLogicContext();
 
 221         ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
 
 222         ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
 
 224         ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
 
 225         ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
 
 226         ctx.setAttribute("prop.l3vpn.entry1-id", "1");
 
 227         ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
 
 228         ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
 
 229         ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
 
 230         ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
 
 231         ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
 
 232         ctx.setAttribute("prop.l3vpn.sna1-route", "192.168.1.4/24");
 
 234         ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
 
 235         ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
 
 236         ctx.setAttribute("prop.l3vpn.entry2-id", "1");
 
 237         ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
 
 238         ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
 
 239         ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
 
 240         ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.5");
 
 241         ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
 
 242         ctx.setAttribute("prop.l3vpn.sna2-route", "192.168.1.8/24");
 
 244         Map<String, String> p = new HashMap<String, String>();
 
 245         p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
 
 246         p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
 
 247         p.put("restapiUser", "admin");
 
 248         p.put("restapiPassword", "admin123");
 
 249         p.put("format", "json");
 
 250         p.put("httpMethod", "post");
 
 251         p.put("responsePrefix", "restapi-result");
 
 252         p.put("skipSending", "true");
 
 254         RestapiCallNode rcn = new RestapiCallNode();
 
 255         rcn.sendRequest(p, ctx);
 
 259     public void testL2DciTemplate() throws SvcLogicException {
 
 260         SvcLogicContext ctx = new SvcLogicContext();
 
 261         ctx.setAttribute("prop.dci-connects.id", "Id1");
 
 262         ctx.setAttribute("prop.dci-connects.name", "Name1");
 
 263         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
 
 264         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
 
 265         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
 
 266         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
 
 267         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
 
 268         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
 
 269         ctx.setAttribute("prop.dci-connects.vni", "1");
 
 271         Map<String, String> p = new HashMap<String, String>();
 
 272         p.put("templateFileName", "src/test/resources/l2-dci-connects-template.json");
 
 273         p.put("restapiUrl", "http://echo.getpostman.com");
 
 274         p.put("restapiUser", "user1");
 
 275         p.put("restapiPassword", "abc123");
 
 276         p.put("format", "json");
 
 277         p.put("httpMethod", "post");
 
 278         p.put("responsePrefix", "response");
 
 279         p.put("skipSending", "true");
 
 281         RestapiCallNode rcn = new RestapiCallNode();
 
 282         rcn.sendRequest(p, ctx);
 
 286     public void testL3DciTemplate() throws SvcLogicException {
 
 287         SvcLogicContext ctx = new SvcLogicContext();
 
 288         ctx.setAttribute("prop.dci-connects.id", "Id1");
 
 289         ctx.setAttribute("prop.dci-connects.name", "Name1");
 
 290         ctx.setAttribute("prop.dci-connects.local_networks_length", "2");
 
 291         ctx.setAttribute("prop.dci-connects.local_networks[0]", "NetId1");
 
 292         ctx.setAttribute("prop.dci-connects.local_networks[1]", "NetId2");
 
 293         ctx.setAttribute("prop.dci-connects.evpn_irts[0]", "100:1");
 
 294         ctx.setAttribute("prop.dci-connects.evpn_erts[0]", "100:2");
 
 295         ctx.setAttribute("prop.dci-connects.evpn_irts[1]", "200:1");
 
 296         ctx.setAttribute("prop.dci-connects.evpn_erts[1]", "200:2");
 
 297         ctx.setAttribute("prop.dci-connects.vni", "1");
 
 299         Map<String, String> p = new HashMap<String, String>();
 
 300         p.put("templateFileName", "src/test/resources/l3-dci-connects-template.json");
 
 301         p.put("restapiUrl", "http://echo.getpostman.com");
 
 302         p.put("restapiUser", "user1");
 
 303         p.put("restapiPassword", "abc123");
 
 304         p.put("format", "json");
 
 305         p.put("httpMethod", "post");
 
 306         p.put("responsePrefix", "response");
 
 307         p.put("skipSending", "true");
 
 309         RestapiCallNode rcn = new RestapiCallNode();
 
 310         rcn.sendRequest(p, ctx);