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;
27 import org.junit.Test;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
30 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class TestRestapiCallNode {
36 private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
40 public void testDelete() throws SvcLogicException {
41 SvcLogicContext ctx = new SvcLogicContext();
43 Map<String, String> p = new HashMap<String, String>();
44 p.put("restapiUrl", "https://echo.getpostman.com/delete");
45 p.put("restapiUser", "user1");
46 p.put("restapiPassword", "pwd1");
47 p.put("httpMethod", "delete");
48 p.put("skipSending", "true");
50 RestapiCallNode rcn = new RestapiCallNode();
51 rcn.sendRequest(p, ctx);
55 public void testJsonTemplate() throws SvcLogicException {
56 SvcLogicContext ctx = new SvcLogicContext();
57 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
58 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
59 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
60 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
61 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
62 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
63 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
64 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
65 ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
66 ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
67 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
68 ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
69 ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
70 ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
71 ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
72 ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
73 ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
74 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
75 ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
76 ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
77 ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
78 ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
80 Map<String, String> p = new HashMap<String, String>();
81 p.put("templateFileName", "src/test/resources/test-template.json");
82 p.put("restapiUrl", "http://echo.getpostman.com");
83 p.put("restapiUser", "user1");
84 p.put("restapiPassword", "abc123");
85 p.put("format", "json");
86 p.put("httpMethod", "post");
87 p.put("responsePrefix", "response");
88 p.put("skipSending", "true");
90 RestapiCallNode rcn = new RestapiCallNode();
91 rcn.sendRequest(p, ctx);
94 @Test(expected = SvcLogicException.class)
95 public void testInvalidRepeatTimes() throws SvcLogicException {
96 SvcLogicContext ctx = new SvcLogicContext();
97 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "a");
98 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
99 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
100 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
101 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
102 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
103 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
104 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
106 Map<String, String> p = new HashMap<String, String>();
107 p.put("templateFileName", "src/test/resources/test-template.json");
108 p.put("restapiUrl", "http://echo.getpostman.com");
109 p.put("restapiUser", "user1");
110 p.put("restapiPassword", "abc123");
111 p.put("format", "json");
112 p.put("httpMethod", "post");
113 p.put("responsePrefix", "response");
114 p.put("skipSending", "true");
116 RestapiCallNode rcn = new RestapiCallNode();
117 rcn.sendRequest(p, ctx);
120 @Test(expected = SvcLogicException.class)
121 public void testInvalidTemplatePath() throws SvcLogicException {
122 SvcLogicContext ctx = new SvcLogicContext();
123 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
124 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
125 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
126 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
127 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
128 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
129 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
130 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
132 Map<String, String> p = new HashMap<String, String>();
133 p.put("templateFileName", "src/test/resourcess/test-template.json");
134 p.put("restapiUrl", "http://echo.getpostman.com");
135 p.put("restapiUser", "user1");
136 p.put("restapiPassword", "abc123");
137 p.put("format", "json");
138 p.put("httpMethod", "post");
139 p.put("responsePrefix", "response");
140 p.put("skipSending", "true");
142 RestapiCallNode rcn = new RestapiCallNode();
143 rcn.sendRequest(p, ctx);
146 @Test(expected = SvcLogicException.class)
147 public void testWithoutSkipSending() throws SvcLogicException {
148 SvcLogicContext ctx = new SvcLogicContext();
149 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
150 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
151 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
152 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
153 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
154 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
155 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
156 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
158 Map<String, String> p = new HashMap<String, String>();
159 p.put("templateFileName", "src/test/resources/test-template.json");
160 p.put("restapiUrl", "http://echo.getpostman.com");
161 p.put("restapiUser", "user1");
162 p.put("restapiPassword", "abc123");
163 p.put("format", "json");
164 p.put("httpMethod", "post");
165 p.put("responsePrefix", "response");
166 p.put("skipSending", "false");
168 RestapiCallNode rcn = new RestapiCallNode();
169 rcn.sendRequest(p, ctx);
173 @Test(expected = SvcLogicException.class)
174 public void testWithInvalidURI() throws SvcLogicException {
175 SvcLogicContext ctx = new SvcLogicContext();
176 ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
177 ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
178 ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
179 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
180 ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
181 ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
182 ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
183 ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
185 Map<String, String> p = new HashMap<String, String>();
186 p.put("templateFileName", "src/test/resources/test-template.json");
187 p.put("restapiUrl", "http://echo. getpostman.com");
188 p.put("restapiUser", "user1");
189 p.put("restapiPassword", "abc123");
190 p.put("format", "json");
191 p.put("httpMethod", "post");
192 p.put("responsePrefix", "response");
193 p.put("skipSending", "false");
195 RestapiCallNode rcn = new RestapiCallNode();
196 rcn.sendRequest(p, ctx);
200 public void testVpnJsonTemplate() throws SvcLogicException {
201 SvcLogicContext ctx = new SvcLogicContext();
202 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
203 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
205 Map<String, String> p = new HashMap<String, String>();
206 p.put("templateFileName", "src/test/resources/l3smvpntemplate.json");
207 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/vpn-services");
208 p.put("restapiUser", "admin");
209 p.put("restapiPassword", "admin123");
210 p.put("format", "json");
211 p.put("httpMethod", "post");
212 p.put("responsePrefix", "restapi-result");
213 p.put("skipSending", "true");
215 RestapiCallNode rcn = new RestapiCallNode();
216 rcn.sendRequest(p, ctx);
220 public void testSiteJsonTemplate() throws SvcLogicException {
221 SvcLogicContext ctx = new SvcLogicContext();
222 ctx.setAttribute("prop.l3vpn.name", "10000000-0000-0000-0000-000000000001");
223 ctx.setAttribute("prop.l3vpn.topology", "point_to_point");
225 ctx.setAttribute("prop.l3vpn.site1_name", "10000000-0000-0000-0000-000000000002");
226 ctx.setAttribute("prop.l3vpn.vpn-policy1-id", "10000000-0000-0000-0000-000000000003");
227 ctx.setAttribute("prop.l3vpn.entry1-id", "1");
228 ctx.setAttribute("prop.l3vpn.sna1_name", "10000000-0000-0000-0000-000000000004");
229 ctx.setAttribute("prop.l3vpn.pe1_id", "a8098c1a-f86e-11da-bd1a-00112444be1e");
230 ctx.setAttribute("prop.l3vpn.ac1_id", "a8098c1a-f86e-11da-bd1a-00112444be1b");
231 ctx.setAttribute("prop.l3vpn.ac1-peer-ip", "192.168.1.1");
232 ctx.setAttribute("prop.l3vpn.ac1-ip", "192.168.1.2");
233 ctx.setAttribute("prop.l3vpn.sna1-route", "192.168.1.4/24");
235 ctx.setAttribute("prop.l3vpn.site2_name", "10000000-0000-0000-0000-000000000005");
236 ctx.setAttribute("prop.l3vpn.vpn-policy2-id", "10000000-0000-0000-0000-000000000006");
237 ctx.setAttribute("prop.l3vpn.entry2-id", "1");
238 ctx.setAttribute("prop.l3vpn.sna2_name", "10000000-0000-0000-0000-000000000007");
239 ctx.setAttribute("prop.l3vpn.pe2_id", "a8098c1a-f86e-11da-bd1a-00112444be1a");
240 ctx.setAttribute("prop.l3vpn.ac2_id", "a8098c1a-f86e-11da-bd1a-00112444be1c");
241 ctx.setAttribute("prop.l3vpn.ac2-peer-ip", "192.168.1.5");
242 ctx.setAttribute("prop.l3vpn.ac2-ip", "192.168.1.5");
243 ctx.setAttribute("prop.l3vpn.sna2-route", "192.168.1.8/24");
245 Map<String, String> p = new HashMap<String, String>();
246 p.put("templateFileName", "src/test/resources/l3smsitetemplate.json");
247 p.put("restapiUrl", "http://ipwan:18002/restconf/data/huawei-ac-net-l3vpn-svc:l3vpn-svc-cfg/sites");
248 p.put("restapiUser", "admin");
249 p.put("restapiPassword", "admin123");
250 p.put("format", "json");
251 p.put("httpMethod", "post");
252 p.put("responsePrefix", "restapi-result");
253 p.put("skipSending", "true");
255 RestapiCallNode rcn = new RestapiCallNode();
256 rcn.sendRequest(p, ctx);