diff options
author | Sandeep J <sandeejh@in.ibm.com> | 2018-09-24 02:31:45 +0530 |
---|---|---|
committer | Sandeep J <sandeejh@in.ibm.com> | 2018-09-24 02:31:55 +0530 |
commit | d13f91c223d2cd6b8c6d02766f386bd22991396a (patch) | |
tree | b7d1e07ab9143b0a379ec43b53ea0102bc021d5f /sliPluginUtils/provider/src/test/java | |
parent | 9e8138f54edbf4cc8a0309f9e149953e08d3280e (diff) |
added test cases to CheckParametersTest
to increase code coverage
Issue-ID: CCSDK-595
Change-Id: Ief8154612aff27cda10f57623b1cca6baac9a7a7
Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
Diffstat (limited to 'sliPluginUtils/provider/src/test/java')
-rw-r--r-- | sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java | 201 |
1 files changed, 119 insertions, 82 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 166a60e90..266603d1d 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 @@ -3,7 +3,9 @@ * ONAP : CCSDK * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. + * reserved. + * ================================================================================ + * Modifications Copyright (C) 2018 IBM. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +23,9 @@ package org.onap.ccsdk.sli.core.slipluginutils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.util.HashMap; import java.util.Map; @@ -32,85 +37,117 @@ import org.slf4j.LoggerFactory; 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 + 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)); + + } } |