aboutsummaryrefslogtreecommitdiffstats
path: root/restapi-call-node/provider/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'restapi-call-node/provider/src/test/java')
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java65
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java92
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java215
-rw-r--r--restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java75
4 files changed, 447 insertions, 0 deletions
diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java
new file mode 100644
index 00000000..16fa6859
--- /dev/null
+++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestJsonParser.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 ONAP Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package jtest.org.openecomp.sdnc.restapicall;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openecomp.sdnc.restapicall.JsonParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestJsonParser {
+
+ private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class);
+
+ @Test
+ public void test() throws Exception {
+ BufferedReader in = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json")));
+ String ss = "";
+ String line = null;
+ while ((line = in.readLine()) != null)
+ ss += line + '\n';
+
+ Map<String, String> mm = JsonParser.convertToProperties(ss);
+
+ logProperties(mm);
+
+ in.close();
+ }
+
+ private void logProperties(Map<String, String> mm) {
+ List<String> ll = new ArrayList<>();
+ for (Object o : mm.keySet())
+ ll.add((String) o);
+ Collections.sort(ll);
+
+ log.info("Properties:");
+ for (String name : ll)
+ log.info("--- " + name + ": " + mm.get(name));
+ }
+}
diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java
new file mode 100644
index 00000000..e0e58ad5
--- /dev/null
+++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestRestapiCallNode.java
@@ -0,0 +1,92 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 ONAP Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package jtest.org.openecomp.sdnc.restapicall;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.openecomp.sdnc.restapicall.RestapiCallNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestRestapiCallNode {
+
+ private static final Logger log = LoggerFactory.getLogger(TestRestapiCallNode.class);
+
+
+ @Test
+ public void testDelete() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("restapiUrl", "https://echo.getpostman.com/delete");
+ p.put("restapiUser", "user1");
+ p.put("restapiPassword", "pwd1");
+ p.put("httpMethod", "delete");
+ p.put("skipSending", "true");
+
+ RestapiCallNode rcn = new RestapiCallNode();
+ rcn.sendRequest(p, ctx);
+ }
+
+ @Test
+ public void testJsonTemplate() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.sdn-circuit-req-row_length", "3");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[0].source-uid", "APIDOC-123");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[0].action", "delete");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-timestamp", "2016-09-09 16:30:35.0");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[0].request-status", "New");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[0].processing-status", "New");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[0].service-clfi", "testClfi1");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[0].clci", "clci");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[1].source-uid", "APIDOC-123");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[1].action", "delete");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-timestamp", "2016-09-09 16:30:35.0");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[1].request-status", "New");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[1].processing-status", "New");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[1].service-clfi", "testClfi1");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[1].clci", "clci");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[2].source-uid", "APIDOC-123");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[2].action", "delete");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-timestamp", "2016-09-09 16:30:35.0");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[2].request-status", "New");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[2].processing-status", "New");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[2].service-clfi", "testClfi1");
+ ctx.setAttribute("tmp.sdn-circuit-req-row[2].clci", "clci");
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("templateFileName", "src/test/resources/test-template.json");
+ p.put("restapiUrl", "http://echo.getpostman.com");
+ p.put("restapiUser", "user1");
+ p.put("restapiPassword", "abc123");
+ p.put("format", "json");
+ p.put("httpMethod", "post");
+ p.put("responsePrefix", "response");
+ p.put("skipSending", "true");
+
+ RestapiCallNode rcn = new RestapiCallNode();
+ rcn.sendRequest(p, ctx);
+ }
+}
diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java
new file mode 100644
index 00000000..dbcf98a9
--- /dev/null
+++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlJsonUtil.java
@@ -0,0 +1,215 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 ONAP Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package jtest.org.openecomp.sdnc.restapicall;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdnc.restapicall.XmlJsonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+public class TestXmlJsonUtil {
+
+ private static final Logger log = LoggerFactory.getLogger(TestXmlJsonUtil.class);
+
+ @Test
+ public void test() {
+ Map<String, String> mm = new HashMap<>();
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].vnf-type", "N-SBG");
+ mm.put("service-data.service-information.service-instance-id", "someinstance001");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].dns-server-ip-address", "10.11.12.13");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].escf-domain-name", "hclab.atttest.com");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3_length", "2");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[0].snmp-target-v3-id", "1");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[0].snmp-target-ip-address", "127.0.0.1");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[0].snmp-security-level", "NO_AUTH_NO_PRIV");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[1].snmp-target-v3-id", "2");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[1].snmp-target-ip-address", "192.168.1.8");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].snmp-target-v3[1].snmp-security-level", "NO_AUTH_NO_PRIV");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].dns-ip-address-1", "2001:1890:1001:2224::1");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].dns-ip-address-2", "2001:1890:1001:2424::1");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].diameter-rf-realm-name", "uvp.els-an.att.net");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].diameter-rf-peer-ip-address", "192.168.1.66");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].bgf-controller-ip-address", "192.168.1.186");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].bgf-control-link-name", "mg3/69@192.168.1.226");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].rf-interface-nexthop-ip-address", "10.111.108.150");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].rf-mated-pair-ip-address", "10.111.108.146");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf_length", "4");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[0].network-name", "UvpbUgnAccess1");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[0].sip-pa-termination-ip-address", "10.111.108.146");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].network-name", "MIS");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].proactive-transcoding-profile", "trinity-transcodingProfile");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].next-hop-ip-address", "10.111.108.158");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[1].subnet-mask-length", "10.111.108.154");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].network-name", "AVPN1");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].proactive-transcoding-profile", "trinity-transcodingProfile");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].next-hop-ip-address", "10.111.108.166");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[2].subnet-mask-length", "10.111.108.162");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].network-name", "AVPN1");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].proactive-transcoding-profile", "trinity-transcodingProfile");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].next-hop-ip-address", "10.129.108.166");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].access-net-pcscf[3].subnet-mask-length", "10.129.108.162");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf_length", "1");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf[0].network-name", "Core");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf[0].next-hop-ip-address", "10.111.108.142");
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].core-net-pcscf[0].sip-pa-termination-ip-address", "10.111.108.138");
+
+ mm.put("service-data.vnf-config-parameters-list.vnf-config-parameters[0].mated-pair-fully-qualified-domain-name", "mt1nj01sbg01pyl-mt1nj01sbg02pyl.ar1ga.uvp.els-an.att.net");
+
+ mm.put("service-data.appc-request-header.svc-request-id", "SOMESERVICEREQUEST123451000");
+ mm.put("service-data.vnf-config-information.vnf-host-ip-address", "192.168.13.151");
+ mm.put("service-data.vnf-config-information.vendor", "Netconf");
+
+ mm.put("service-data.vnf-config-information.escape-test", "blah blah \"xxx&nnn<>\\'\"there>blah<&''\"\"123\\\\\\'''blah blah &");
+
+ String ss = XmlJsonUtil.getXml(mm, "service-data.vnf-config-parameters-list");
+ log.info(ss);
+
+ ss = XmlJsonUtil.getXml(mm, "service-data.vnf-config-information");
+ log.info(ss);
+
+ ss = XmlJsonUtil.getJson(mm, "service-data.vnf-config-parameters-list.vnf-config-parameters");
+ log.info(ss);
+
+ ss = XmlJsonUtil.getJson(mm, "service-data.vnf-config-information");
+ log.info(ss);
+ }
+
+ @Test
+ public void testRemoveEmptyStructXml() {
+ String xmlin = "" +
+ "<T1>\n" +
+ " <T2>\n" +
+ " <T3>\n" +
+ " <T4></T4>\n" +
+ " <T5> </T5>\n" +
+ " <T6>\n" +
+ " </T6>\n" +
+ " </T3>\n" +
+ " <T7>blah</T7>\n" +
+ " </T2>\n" +
+ " <T8>\n" +
+ " <T9>\n" +
+ " <T10></T10>\n" +
+ " <T11> </T11>\n" +
+ " <T12>\n" +
+ " </T12>\n" +
+ " </T9>\n" +
+ " <T13>\n" +
+ " <T14></T14>\n" +
+ " <T15> </T15>\n" +
+ " <T16>\n" +
+ " <T17></T17>\n" +
+ " </T16>\n" +
+ " </T13>\n" +
+ " <T17>\n" +
+ " </T17>\n" +
+ " </T8>\n" +
+ " <T18>blah blah</T18>\n" +
+ "</T1>\n";
+
+ String xmloutexpected = "" +
+ "<T1>\n" +
+ " <T2>\n" +
+ " <T7>blah</T7>\n" +
+ " </T2>\n" +
+ " <T18>blah blah</T18>\n" +
+ "</T1>\n";
+
+ String xmlout = XmlJsonUtil.removeEmptyStructXml(xmlin);
+ log.info(xmlout);
+
+ Assert.assertEquals(xmloutexpected, xmlout);
+ }
+
+ @Test
+ public void testRemoveEmptyStructJson() {
+ String xmlin = "{\r\n" +
+ " \"T1\":{\r\n" +
+ " \"T2\":{\r\n" +
+ " \"T3\":[\r\n" +
+ " \r\n" +
+ " ],\r\n" +
+ " \"T4\":{\r\n" +
+ " \"T12\":[\r\n" +
+ " \r\n" +
+ " ],\r\n" +
+ " \"T13\":[ ],\r\n" +
+ " \"T14\":{\r\n" +
+ " \"T15\":{\r\n" +
+ " \r\n" +
+ " },\r\n" +
+ " \"T16\":{\r\n" +
+ " \r\n" +
+ " }\r\n" +
+ " }\r\n" +
+ " },\r\n" +
+ " \"T5\":{\r\n" +
+ " \"T6\":[\r\n" +
+ " \r\n" +
+ " ],\r\n" +
+ " \"T7\":[\r\n" +
+ " \"T8\":{\r\n" +
+ " \r\n" +
+ " },\r\n" +
+ " \"T9\":{ },\r\n" +
+ " \"T10\":\"blah\",\r\n" +
+ " \"T11\":[\r\n" +
+ " \r\n" +
+ " ]\r\n" +
+ " ]\r\n" +
+ " }\r\n" +
+ " }\r\n" +
+ " }\r\n" +
+ "}\r\n" +
+ "";
+
+ String xmloutexpected = "{\r\n" +
+ " \"T1\":{\r\n" +
+ " \"T2\":{\r\n" +
+ " \"T5\":{\r\n" +
+ " \"T7\":[\r\n" +
+ " \"T10\":\"blah\",\r\n" +
+ " ]\r\n" +
+ " }\r\n" +
+ " }\r\n" +
+ " }\r\n" +
+ "}\r\n" +
+ "";
+
+ String xmlout = XmlJsonUtil.removeEmptyStructJson(xmlin);
+ log.info(xmlout);
+
+ Assert.assertEquals(xmloutexpected, xmlout);
+ }
+}
diff --git a/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java
new file mode 100644
index 00000000..980eded4
--- /dev/null
+++ b/restapi-call-node/provider/src/test/java/jtest/org/openecomp/sdnc/restapicall/TestXmlParser.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * Copyright (C) 2017 ONAP Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package jtest.org.openecomp.sdnc.restapicall;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Test;
+import org.openecomp.sdnc.restapicall.XmlParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestXmlParser {
+
+ private static final Logger log = LoggerFactory.getLogger(TestXmlParser.class);
+
+ @Test
+ public void test() throws Exception {
+ BufferedReader in = new BufferedReader(new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml")));
+ String ss = "";
+ String line = null;
+ while ((line = in.readLine()) != null)
+ ss += line + '\n';
+
+ Set<String> listNameList = new HashSet<String>();
+ listNameList.add("project.dependencies.dependency");
+ listNameList.add("project.build.plugins.plugin");
+ listNameList.add("project.build.plugins.plugin.executions.execution");
+ listNameList.add("project.build.pluginManagement.plugins.plugin");
+ listNameList.add(
+ "project.build.pluginManagement.plugins.plugin.configuration.lifecycleMappingMetadata.pluginExecutions.pluginExecution");
+
+ Map<String, String> mm = XmlParser.convertToProperties(ss, listNameList);
+
+ logProperties(mm);
+
+ in.close();
+ }
+
+ private void logProperties(Map<String, String> mm) {
+ List<String> ll = new ArrayList<>();
+ for (Object o : mm.keySet())
+ ll.add((String) o);
+ Collections.sort(ll);
+
+ log.info("Properties:");
+ for (String name : ll)
+ log.info("--- " + name + ": " + mm.get(name));
+ }
+}