From 96a9aafdff7813324bc8a8ba1e743683e251dde6 Mon Sep 17 00:00:00 2001 From: Jessica Wagantall Date: Tue, 1 Dec 2020 11:33:35 -0800 Subject: Migrate files from sli-plugins Migrate sli-plugins repo into new directory "plugins". Signed-off-by: Jessica Wagantall --- .../sli/plugins/restapicall/TestJsonParser.java | 85 ++++++ .../plugins/restapicall/TestSshApiCallNode.java | 330 +++++++++++++++++++++ .../sli/plugins/restapicall/TestXmlJsonUtil.java | 264 +++++++++++++++++ .../sli/plugins/restapicall/TestXmlParser.java | 123 ++++++++ 4 files changed, 802 insertions(+) create mode 100644 plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java create mode 100644 plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestSshApiCallNode.java create mode 100644 plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java create mode 100644 plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java (limited to 'plugins/sshapi-call-node/provider/src/test/java') diff --git a/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java new file mode 100644 index 000000000..78f20e327 --- /dev/null +++ b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. 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.onap.ccsdk.sli.plugins.restapicall; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import org.codehaus.jettison.json.JSONException; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.plugins.sshapicall.model.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 SvcLogicException, IOException { + BufferedReader in = new BufferedReader( + new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json")) + ); + StringBuilder b = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) + b.append(line).append('\n'); + Map mm = null; + try { + mm = JsonParser.convertToProperties(b.toString()); + } catch (JSONException e){ + throw new SvcLogicException(e.getMessage()); + } + + logProperties(mm); + + in.close(); + } + + @Test(expected = NullPointerException.class) + public void testNullString() throws SvcLogicException { + Map mm = null; + try { + mm = JsonParser.convertToProperties(null); + } catch (JSONException e){ + throw new SvcLogicException(e.getMessage()); + } + } + + private void logProperties(Map mm) { + List 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/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestSshApiCallNode.java b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestSshApiCallNode.java new file mode 100644 index 000000000..c0bcdb82a --- /dev/null +++ b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestSshApiCallNode.java @@ -0,0 +1,330 @@ +package jtest.org.onap.ccsdk.sli.plugins.restapicall; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.plugins.sshapicall.SshApiCallNode; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.assertEquals; + +public class TestSshApiCallNode { + + private static final Logger log = LoggerFactory.getLogger(TestSshApiCallNode.class); + + private SshApiCallNode adapter; + private String TestId; + private boolean testMode = true; + private Map params; + private SvcLogicContext svcContext; + + + @Before + public void setup() throws IllegalArgumentException { + testMode = true; + svcContext = new SvcLogicContext(); + adapter = new SshApiCallNode(); + + params = new HashMap<>(); + params.put("AgentUrl", "https://192.168.1.1"); + params.put("User", "test"); + params.put("Password", "test"); + } + + @After + public void tearDown() { + testMode = false; + adapter = null; + params = null; + svcContext = null; + } + + @Test(expected = SvcLogicException.class) + public void testExecCommand_noUrlFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adapter.execCommand(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandPty_noUrlFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adapter.execCommandWithPty(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_noUrlFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("HostName", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommand_noPortFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adapter.execCommand(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandPty_noPortFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adapter.execCommandWithPty(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_noPortFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Test", "fail"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommand_noCmdFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + adapter.execCommand(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandPty_noCmdFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + adapter.execCommandWithPty(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_noCmdFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_noSSHBasicFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("AuthType", "basic"); + params.put("Cmd", "test"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_noSSHKeyFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("AuthType", "key"); + params.put("Cmd", "test"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_noSSHNoneFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("AuthType", "none"); + params.put("Cmd", "test"); + params.put("ResponseType", "xml"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_noSSHFailed() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("ResponseType", "json"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = IllegalArgumentException.class) + public void testExecCommandResponse_noSSHInvalidParam() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("ResponseType", "txt"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = IllegalArgumentException.class) + public void testExecCommandResponse_noSSHInvalidAuthParam() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("AuthType", "spring"); + params.put("ResponseType", "json"); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test + public void testExecCommandResponse_validJSON() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("AuthType", "basic"); + params.put("ResponseType", "json"); + params.put("TestOut", "{\"equipment-data\":\"boo\"}"); + params.put("TestFail", "false"); + adapter = new SshApiCallNode(true); + adapter.execWithStatusCheck(params, svcContext); + assertEquals("boo", svcContext.getAttribute("equipment-data")); + } + + @Test + public void testExecCommandResponse_validXML() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("AuthType", "basic"); + params.put("ResponseType", "xml"); + params.put("TestOut", "4.0.0"); + params.put("TestFail", "false"); + adapter = new SshApiCallNode(true); + adapter.execWithStatusCheck(params, svcContext); + assertEquals("4.0.0", svcContext.getAttribute("modelVersion")); + } + + @Test + public void testExecCommandResponse_validJSONPrefix() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("AuthType", "basic"); + params.put("ResponseType", "json"); + params.put("TestOut", "{\"equipment-data\":\"boo\"}"); + params.put("ResponsePrefix", "test"); + params.put("TestFail", "false"); + adapter = new SshApiCallNode(true); + adapter.execWithStatusCheck(params, svcContext); + assertEquals("boo", svcContext.getAttribute("test.equipment-data")); + } + + @Test + public void testExecCommandResponse_validXMLPrefix() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("AuthType", "basic"); + params.put("ResponseType", "xml"); + params.put("TestOut", "4.0.0"); + params.put("ResponsePrefix", "test"); + params.put("TestFail", "false"); + adapter = new SshApiCallNode(true); + adapter.execWithStatusCheck(params, svcContext); + assertEquals("4.0.0", svcContext.getAttribute("test.modelVersion")); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_validXMLFail() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + + params.put("Url", "test"); + params.put("Port", "10"); + params.put("User", "test"); + params.put("Password", "test"); + params.put("Cmd", "test"); + params.put("AuthType", "basic"); + params.put("ResponseType", "xml"); + params.put("TestOut", "4.0.0"); + params.put("TestFail", "true"); + params.put("ResponsePrefix", "test"); + adapter = new SshApiCallNode(true); + adapter.execWithStatusCheck(params, svcContext); + } + + @Test(expected = SvcLogicException.class) + public void testExecCommandResponse_validXMLPrefixKey() throws SvcLogicException, + IllegalStateException, IllegalArgumentException { + params = new HashMap<>(); + params.put("Url", "test"); + params.put("Port", "10"); + params.put("SshKey", "test"); + params.put("Cmd", "test"); + params.put("ResponseType", "xml"); + params.put("TestOut", "4.0.0"); + params.put("ResponsePrefix", "test"); + adapter.execWithStatusCheck(params, svcContext); + assertEquals("4.0.0", svcContext.getAttribute("test.modelVersion")); + } +} diff --git a/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java new file mode 100644 index 000000000..33e0f24dd --- /dev/null +++ b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlJsonUtil.java @@ -0,0 +1,264 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. 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.onap.ccsdk.sli.plugins.restapicall; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.sli.plugins.sshapicall.model.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 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); + + ss = XmlJsonUtil.getJson(mm, "service-data.vnf-config-information.vnf-host-ip-address"); + log.info(ss); + + ss = XmlJsonUtil.getJson(mm, "\"service-data.vnf-config-information.vnf-host-ip-address"); + log.info(ss); + } + + @Test + public void testRemoveEmptyStructXml() { + String xmlin = "" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " blah\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " blah blah\n" + + "\n"; + + String xmloutexpected = "" + + "\n" + + " \n" + + " blah\n" + + " \n" + + " blah blah\n" + + "\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/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java new file mode 100644 index 000000000..ba0ae41de --- /dev/null +++ b/plugins/sshapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestXmlParser.java @@ -0,0 +1,123 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2018 Samsung Electronics. 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.onap.ccsdk.sli.plugins.restapicall; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +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.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.plugins.sshapicall.model.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")) + ); + StringBuilder b = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) + b.append(line).append('\n'); + + Set listNameList = new HashSet(); + 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 mm = XmlParser.convertToProperties(b.toString(), listNameList); + logProperties(mm); + in.close(); + } + + @Test + public void testValidLength() throws Exception { + BufferedReader in = new BufferedReader( + new InputStreamReader(ClassLoader.getSystemResourceAsStream("test3.xml")) + ); + StringBuilder b = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) + b.append(line).append('\n'); + + Set listNameList = new HashSet(); + listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport"); + listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport"); + + Map mm = XmlParser.convertToProperties(b.toString(), listNameList); + + assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport[5]"), is("SET_RESET_LP")); + assertThat(mm.get("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport[0]"), is("SET_BVOIP_IN")); + + logProperties(mm); + in.close(); + } + + @Test(expected = SvcLogicException.class) + public void testInvalidLength() throws Exception { + BufferedReader in = new BufferedReader( + new InputStreamReader(ClassLoader.getSystemResourceAsStream("invalidlength.xml")) + ); + StringBuilder b = new StringBuilder(); + String line; + while ((line = in.readLine()) != null) + b.append(line).append('\n'); + + Set listNameList = new HashSet(); + listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfImport"); + listNameList.add("ApplyGroupResponse.ApplyGroupResponseData.VrfDetails.VrfExport"); + + Map mm = XmlParser.convertToProperties(b.toString(), listNameList); + logProperties(mm); + in.close(); + } + + private void logProperties(Map mm) { + List 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)); + } +} -- cgit 1.2.3-korg