From 31e5da15c8247d2b98fc3a52fcf3c096e45933ce Mon Sep 17 00:00:00 2001 From: Sandeep J Date: Tue, 25 Sep 2018 17:29:03 +0530 Subject: added test cases to CheckParametersTest.java to increase code coverage Issue-ID: CCSDK-595 Change-Id: I182eac676dd65c4ef68dd8a479d288615471c712 Signed-off-by: Sandeep J --- .../core/slipluginutils/CheckParametersTest.java | 259 ++++++++++++--------- 1 file changed, 146 insertions(+), 113 deletions(-) diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java index 266603d1..a7cc1bde 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java @@ -35,119 +35,152 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.gson.JsonObject; + public class CheckParametersTest { - @Test - public void nullRequiredParameters() throws Exception { - Map parametersMap = new HashMap(); - String[] requiredParams = null; - Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); - SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); - } - - @Test(expected = SvcLogicException.class) - public void emptyParametersMap() throws Exception { - Map parametersMap = new HashMap(); - String[] requiredParams = new String[] { "param1", "param2", "param3" }; - Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); - SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); - } - - @Test(expected = SvcLogicException.class) - public void paramNotFound() throws Exception { - Map parametersMap = new HashMap(); - parametersMap.put("tst", "me"); - String[] requiredParams = new String[] { "param1", "parm2", "param3" }; - Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); - SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); - } - - @Test - public void testSunnyRequiredParameters() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("param1", "hello"); - ctx.setAttribute("param2", "world"); - ctx.setAttribute("param3", "!"); - - Map parameters = new HashMap(); - parameters.put("param1", "dog"); - parameters.put("param2", "cat"); - parameters.put("param3", "fish"); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test - public void testSunnyRequiredParametersWithPrefix() throws Exception { - String prefixValue = "my.unique.path."; - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute(prefixValue + "param1", "hello"); - ctx.setAttribute(prefixValue + "param2", "world"); - ctx.setAttribute(prefixValue + "param3", "!"); - - Map parameters = new HashMap(); - parameters.put("prefix", prefixValue); - parameters.put("param1", "dog"); - parameters.put("param2", "cat"); - parameters.put("param3", "fish"); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test(expected = SvcLogicException.class) - public void testRainyMissingRequiredParameters() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("param1", "hello"); - ctx.setAttribute("param3", "!"); - - Map parameters = new HashMap(); - parameters.put("param1", null); - parameters.put("param2", null); - parameters.put("param3", null); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test(expected = SvcLogicException.class) - public void testEmptyRequiredParameters() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("param1", "hello"); - ctx.setAttribute("param3", "!"); - - Map parameters = new HashMap(); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test(expected = SvcLogicException.class) - public void testJsonStringToCtx() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - Map parameters = new HashMap(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "true"); - parameters.put("source", "//{/name1/:value1/}//"); - SliPluginUtils.jsonStringToCtx(parameters, ctx); - } - - @Test - public void testGetAttributeValue() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - Map parameters = new HashMap(); - parameters.put("outputPath", "testPath"); - parameters.put("source", "testSource"); - SliPluginUtils.getAttributeValue(parameters, ctx); - assertNull(ctx.getAttribute(parameters.get("outputPath"))); - } - - @Test - public void testCtxListContains() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - Map parameters = new HashMap(); - parameters.put("list", "10_length"); - parameters.put("keyName", "testName"); - parameters.put("keyValue", "testValue"); - ctx.setAttribute("10_length", "10"); - assertEquals("false", SliPluginUtils.ctxListContains(parameters, ctx)); - - } + @Test + public void nullRequiredParameters() throws Exception { + Map parametersMap = new HashMap(); + String[] requiredParams = null; + Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); + SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); + } + + @Test(expected = SvcLogicException.class) + public void emptyParametersMap() throws Exception { + Map parametersMap = new HashMap(); + String[] requiredParams = new String[] { "param1", "param2", "param3" }; + Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); + SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); + } + + @Test(expected = SvcLogicException.class) + public void paramNotFound() throws Exception { + Map parametersMap = new HashMap(); + parametersMap.put("tst", "me"); + String[] requiredParams = new String[] { "param1", "parm2", "param3" }; + Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); + SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); + } + + @Test + public void testSunnyRequiredParameters() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("param1", "hello"); + ctx.setAttribute("param2", "world"); + ctx.setAttribute("param3", "!"); + + Map parameters = new HashMap(); + parameters.put("param1", "dog"); + parameters.put("param2", "cat"); + parameters.put("param3", "fish"); + + SliPluginUtils.requiredParameters(parameters, ctx); + } + + @Test + public void testSunnyRequiredParametersWithPrefix() throws Exception { + String prefixValue = "my.unique.path."; + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute(prefixValue + "param1", "hello"); + ctx.setAttribute(prefixValue + "param2", "world"); + ctx.setAttribute(prefixValue + "param3", "!"); + + Map parameters = new HashMap(); + parameters.put("prefix", prefixValue); + parameters.put("param1", "dog"); + parameters.put("param2", "cat"); + parameters.put("param3", "fish"); + + SliPluginUtils.requiredParameters(parameters, ctx); + } + + @Test(expected = SvcLogicException.class) + public void testRainyMissingRequiredParameters() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("param1", "hello"); + ctx.setAttribute("param3", "!"); + + Map parameters = new HashMap(); + parameters.put("param1", null); + parameters.put("param2", null); + parameters.put("param3", null); + + SliPluginUtils.requiredParameters(parameters, ctx); + } + + @Test(expected = SvcLogicException.class) + public void testEmptyRequiredParameters() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("param1", "hello"); + ctx.setAttribute("param3", "!"); + + Map parameters = new HashMap(); + + SliPluginUtils.requiredParameters(parameters, ctx); + } + + @Test(expected = SvcLogicException.class) + public void testJsonStringToCtx() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + Map parameters = new HashMap(); + parameters.put("outputPath", "testPath"); + parameters.put("isEscaped", "true"); + parameters.put("source", "//{/name1/:value1/}//"); + SliPluginUtils.jsonStringToCtx(parameters, ctx); + } + + @Test + public void testGetAttributeValue() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + Map parameters = new HashMap(); + parameters.put("outputPath", "testPath"); + parameters.put("source", "testSource"); + SliPluginUtils.getAttributeValue(parameters, ctx); + assertNull(ctx.getAttribute(parameters.get("outputPath"))); + } + + @Test + public void testCtxListContains() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + Map parameters = new HashMap(); + parameters.put("list", "10_length"); + parameters.put("keyName", "testName"); + parameters.put("keyValue", "testValue"); + ctx.setAttribute("10_length", "10"); + assertEquals("false", SliPluginUtils.ctxListContains(parameters, ctx)); + + } + + @Test(expected= SvcLogicException.class) + public void testPrintContextForNullParameters() throws SvcLogicException + { + SvcLogicContext ctx = new SvcLogicContext(); + Map parameters = new HashMap(); + SliPluginUtils.printContext(parameters, ctx); + } + + @Test + public void testPrintContext() throws SvcLogicException + { + SvcLogicContext ctx = new SvcLogicContext(); + Map parameters = new HashMap(); + parameters.put("filename","testFileName"); + SliPluginUtils.printContext(parameters, ctx); + } + + @Test + public void testWriteJsonObject() throws SvcLogicException + { + JsonObject obj=new JsonObject(); + obj.addProperty("name","testName"); + obj.addProperty("age",27); + obj.addProperty("salary",600000); + SvcLogicContext ctx = new SvcLogicContext(); + SliPluginUtils.writeJsonObject(obj, ctx,"root"); + assertEquals("testName", ctx.getAttribute("root.name")); + assertEquals("27", ctx.getAttribute("root.age")); + assertEquals("600000", ctx.getAttribute("root.salary")); + } } -- cgit 1.2.3-korg