X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=properties-node%2Fprovider%2Fsrc%2Ftest%2Fjava%2Fjtest%2Forg%2Fonap%2Fccsdk%2Fsli%2Fplugins%2Fprop%2FTestPropertiesNode.java;h=a858c49b35069ffbfb0d8e812b5bc5625bb0d803;hb=57bfbb05e485fb11b620b1bf12e70aa063aaa3c8;hp=894eee997443cde2ef66722df959c95672d08f3d;hpb=75352fad2c5d2165bb67a34ecd61117af3214306;p=ccsdk%2Fsli%2Fplugins.git diff --git a/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java index 894eee99..a858c49b 100644 --- a/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java +++ b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java @@ -1,9 +1,13 @@ package jtest.org.onap.ccsdk.sli.plugins.prop; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; +import java.util.Set; +import org.junit.Rule; import org.junit.Test; +import org.junit.contrib.java.lang.system.EnvironmentVariables; import static org.junit.Assert.assertEquals; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; @@ -14,6 +18,8 @@ import org.slf4j.LoggerFactory; public class TestPropertiesNode { private static final Logger log = LoggerFactory.getLogger(TestPropertiesNode.class); + @Rule + public EnvironmentVariables environmentVariables = new EnvironmentVariables(); @Test public void testJSONFileParsing() throws SvcLogicException { @@ -22,6 +28,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.json"); p.put("contextPrefix", "test-json"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -37,6 +44,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.json"); p.put("contextPrefix", "test-json"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -54,6 +62,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.json"); p.put("contextPrefix", ""); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -72,6 +81,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.json"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -91,6 +101,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.json"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -112,6 +123,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test-invalid.json"); p.put("contextPrefix", "invalid"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -121,11 +133,16 @@ public class TestPropertiesNode { @Test public void testTXTFileParsing() throws SvcLogicException { + + environmentVariables.set("deployer_pass", "sdncp-123"); + assertEquals("sdncp-123", System.getenv("deployer_pass")); + SvcLogicContext ctx = new SvcLogicContext(); Map p = new HashMap(); p.put("fileName", "src/test/resources/test.txt"); p.put("contextPrefix", "test-txt"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -138,6 +155,7 @@ public class TestPropertiesNode { "access-information.l1-customer-handoff"),"_1000BASELX"); assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" + "access-information.vlan-tag-control"),"_1Q"); + assertEquals(ctx.getAttribute("test-txt.obfuscated-var"), "sdncp-123"); } @Test @@ -147,6 +165,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.txt"); p.put("contextPrefix", ""); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -167,6 +186,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.txt"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -188,6 +208,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/test/resources/test.txt"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -211,6 +232,7 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("responsePrefix", "response"); p.put("skipSending", "true"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -224,6 +246,7 @@ public class TestPropertiesNode { ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1"); Map p = new HashMap(); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); @@ -238,10 +261,348 @@ public class TestPropertiesNode { Map p = new HashMap(); p.put("fileName", "src/tests/resources/test.txt"); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1"); + } + + @Test + public void testXMLFileParsing() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("contextPrefix", "test-xml"); + p.put("listName", "project.build"); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("test-xml.project.modelVersion"),"4.0.0"); + } + + @Test + public void testXMLFileInnerParsing() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("contextPrefix", "test-xml"); + p.put("listName", "project.modelVersion"); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("test-xml.project.properties.project.build.sourceEncoding"),"UTF-8"); + assertEquals(ctx.getAttribute("test-xml.project.dependencies.dependency.scope"),"provided"); + assertEquals(ctx.getAttribute("test-xml.project.build.pluginManagement.plugins.plugin.configuration" + + ".lifecycleMappingMetadata.pluginExecutions.pluginExecution." + + "pluginExecutionFilter.versionRange"),"[1.2.0.100,)"); + assertEquals(ctx.getAttribute("test-xml.project.build.plugins.plugin.configuration." + + "instructions.Import-Package"),"*"); + } + + @Test + public void testXMLFileParsingPrefixCheck() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("contextPrefix", ""); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("project.properties.project.build.sourceEncoding"),"UTF-8"); + assertEquals(ctx.getAttribute("project.dependencies.dependency.scope"),"provided"); + assertEquals(ctx.getAttribute("project.build.pluginManagement.plugins.plugin.configuration" + + ".lifecycleMappingMetadata.pluginExecutions.pluginExecution." + + "pluginExecutionFilter.versionRange"),"[1.2.0.100,)"); + assertEquals(ctx.getAttribute("project.build.plugins.plugin.configuration." + + "instructions.Import-Package"),"*"); + } + + @Test + public void testXMLFileParsingNoPrefix() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("project.properties.project.build.sourceEncoding"),"UTF-8"); + assertEquals(ctx.getAttribute("project.dependencies.dependency.scope"),"provided"); + assertEquals(ctx.getAttribute("project.build.pluginManagement.plugins.plugin.configuration" + + ".lifecycleMappingMetadata.pluginExecutions.pluginExecution." + + "pluginExecutionFilter.versionRange"),"[1.2.0.100,)"); + assertEquals(ctx.getAttribute("project.build.plugins.plugin.configuration." + + "instructions.Import-Package"),"*"); + } + + @Test + public void testXMLFileParsingCtxCheck() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1"); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("project.properties.project.build.sourceEncoding"),"UTF-8"); + assertEquals(ctx.getAttribute("project.dependencies.dependency.scope"),"provided"); + assertEquals(ctx.getAttribute("project.build.pluginManagement.plugins.plugin.configuration" + + ".lifecycleMappingMetadata.pluginExecutions.pluginExecution." + + "pluginExecutionFilter.versionRange"),"[1.2.0.100,)"); + assertEquals(ctx.getAttribute("project.build.plugins.plugin.configuration." + + "instructions.Import-Package"),"*"); + assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1"); + } + + @Test(expected = SvcLogicException.class) + public void testToPropertiesInvalidXML() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1"); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test-invalid.xml"); + p.put("contextPrefix", "invalid"); + p.put("fileBasedParsing","true"); PropertiesNode rcn = new PropertiesNode(); rcn.readProperties(p, ctx); assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1"); } + + @Test + public void testXMLFileParsingListName() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("contextPrefix", "test-xml-listName"); + p.put("fileBasedParsing","true"); + p.put("listName", "project.build.pluginManagement"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("test-xml-listName.project.build." + + "pluginManagement.plugins.plugin.version"),null); + assertEquals(ctx.getAttribute("test-xml-listName.project.build." + + "plugins.plugin.groupId"),"org.apache.felix"); + } + + @Test + public void testXMLFileParsingListNameAnother() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("contextPrefix", "test-xml-listName"); + p.put("fileBasedParsing","true"); + p.put("listName", "project.modelVersion"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("test-xml-listName.project.modelVersion"),null); + assertEquals(ctx.getAttribute("test-xml-listName.project.build." + + "plugins.plugin.groupId"),"org.apache.felix"); + } + + @Test + public void testTXTFileParsingNotFileBased() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.txt"); + p.put("contextPrefix", "test-txt"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("test-txt.service-data.service-information.service-type"),"AVPN"); + assertEquals(ctx.getAttribute("test-txt.service-configuration-notification-input.response-code"),"0"); + assertEquals(ctx.getAttribute("test-txt.operational-data.avpn-ip-port-information.port-" + + "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED"); + assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" + + "access-information.l1-customer-handoff"),"_1000BASELX"); + assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" + + "access-information.vlan-tag-control"),"_1Q"); + } + + @Test + public void testTXTFileParsingPrefixCheckNotFileBased() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.txt"); + p.put("contextPrefix", ""); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN"); + assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0"); + assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" + + "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.l1-customer-handoff"),"_1000BASELX"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.vlan-tag-control"),"_1Q"); + } + + @Test + public void testTXTFileParsingNoPrefixNotFileBased() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.txt"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN"); + assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0"); + assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" + + "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.l1-customer-handoff"),"_1000BASELX"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.vlan-tag-control"),"_1Q"); + } + + @Test + public void testTXTFileParsingCtxCheckNotFileBased() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1"); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.txt"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN"); + assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0"); + assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" + + "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.l1-customer-handoff"),"_1000BASELX"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.vlan-tag-control"),"_1Q"); + assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1"); + } + + @Test + public void testJSONFileArrayParsingNotFileBased() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.json"); + p.put("contextPrefix", "NotFileBased"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("NotFileBased.\"limit-value\""),"\"1920000\""); + assertEquals(ctx.getAttribute("NotFileBased.\"hard-limit-expression\""),"\"max-server-speed * number-primary-servers\","); + assertEquals(ctx.getAttribute("NotFileBased.\"test-inner-node\""),"\"Test-Value\""); + } + + @Test + public void testXMLFileInnerParsingNotFileBased() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test.xml"); + p.put("contextPrefix", "NotFileBased"); + p.put("listName", "project.modelVersion"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("NotFileBased.RESTAPI"),"Call Node - Provider"); + assertEquals(ctx.getAttribute("NotFileBased."); + assertEquals(ctx.getAttribute("NotFileBased.openECOMP"),"SDN-C"); + assertEquals(ctx.getAttribute("NotFileBased."); + } + + @Test + public void testNoFileTypeNoPrefixNotFileBased() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test"); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN"); + assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0"); + assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" + + "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.l1-customer-handoff"),"_1000BASELX"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.vlan-tag-control"),"_1Q"); + } + + @Test(expected = SvcLogicException.class) + public void testNoFileTypeParseReqError() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("file Name", "src/test/resources/test"); + p.put("fileBasedParsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN"); + assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0"); + assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" + + "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.l1-customer-handoff"),"_1000BASELX"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.vlan-tag-control"),"_1Q"); + } + + @Test + public void testNoFileTypeParseError() throws SvcLogicException { + SvcLogicContext ctx = new SvcLogicContext(); + + Map p = new HashMap(); + p.put("fileName", "src/test/resources/test"); + p.put("file Based % Parsing","true"); + + PropertiesNode rcn = new PropertiesNode(); + rcn.readProperties(p, ctx); + + assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN"); + assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0"); + assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" + + "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.l1-customer-handoff"),"_1000BASELX"); + assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" + + "access-information.vlan-tag-control"),"_1Q"); + } }