5b03bff47e517df35b15c40cb6e0cc686da07198
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / test / java / jtest / 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 jtest.org.onap.ccsdk.sli.plugins.restapicall;
23
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import org.junit.Test;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class TestRestapiCallNode {
34
35         private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
36
37
38         @Test
39         public void testDelete() throws Exception {
40                 SvcLogicContext ctx = new SvcLogicContext();
41
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");
48
49                 RestapiCallNode rcn = new RestapiCallNode();
50                 rcn.sendRequest(p, ctx);
51         }
52
53         @Test
54         public void testJsonTemplate() throws Exception {
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");
78
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");
88
89                 RestapiCallNode rcn = new RestapiCallNode();
90                 rcn.sendRequest(p, ctx);
91         }
92 }