diff options
author | Sandeep J <sandeejh@in.ibm.com> | 2018-09-25 17:29:03 +0530 |
---|---|---|
committer | Sandeep J <sandeejh@in.ibm.com> | 2018-09-25 17:29:48 +0530 |
commit | 31e5da15c8247d2b98fc3a52fcf3c096e45933ce (patch) | |
tree | 845b2a13e14894d54215939a9c626783692e6582 /sliPluginUtils/provider/src | |
parent | 0f82181e2621c414bbdaf6531696c5e25fe6ba9d (diff) |
added test cases to CheckParametersTest.java
to increase code coverage
Issue-ID: CCSDK-595
Change-Id: I182eac676dd65c4ef68dd8a479d288615471c712
Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
Diffstat (limited to 'sliPluginUtils/provider/src')
-rw-r--r-- | sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java | 259 |
1 files 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 266603d1d..a7cc1bde5 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<String, String> parametersMap = new HashMap<String, String>(); - String[] requiredParams = null; - Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); - SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); - } - - @Test(expected = SvcLogicException.class) - public void emptyParametersMap() throws Exception { - Map<String, String> parametersMap = new HashMap<String, String>(); - 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<String, String> parametersMap = new HashMap<String, String>(); - 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<String, String> parameters = new HashMap<String, String>(); - 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<String, String> parameters = new HashMap<String, String>(); - 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<String, String> parameters = new HashMap<String, String>(); - 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<String, String> parameters = new HashMap<String, String>(); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test(expected = SvcLogicException.class) - public void testJsonStringToCtx() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - Map<String, String> parameters = new HashMap<String, String>(); - 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<String, String> parameters = new HashMap<String, String>(); - 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<String, String> parameters = new HashMap<String, String>(); - 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<String, String> parametersMap = new HashMap<String, String>(); + String[] requiredParams = null; + Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); + SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); + } + + @Test(expected = SvcLogicException.class) + public void emptyParametersMap() throws Exception { + Map<String, String> parametersMap = new HashMap<String, String>(); + 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<String, String> parametersMap = new HashMap<String, String>(); + 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<String, String> parameters = new HashMap<String, String>(); + 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<String, String> parameters = new HashMap<String, String>(); + 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<String, String> parameters = new HashMap<String, String>(); + 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<String, String> parameters = new HashMap<String, String>(); + + SliPluginUtils.requiredParameters(parameters, ctx); + } + + @Test(expected = SvcLogicException.class) + public void testJsonStringToCtx() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + Map<String, String> parameters = new HashMap<String, String>(); + 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<String, String> parameters = new HashMap<String, String>(); + 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<String, String> parameters = new HashMap<String, String>(); + 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<String, String> parameters = new HashMap<String, String>(); + SliPluginUtils.printContext(parameters, ctx); + } + + @Test + public void testPrintContext() throws SvcLogicException + { + SvcLogicContext ctx = new SvcLogicContext(); + Map<String, String> parameters = new HashMap<String, String>(); + 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")); + } } |