From 4a79f9d1e5066f9fafde81bf13004a61a4011fe7 Mon Sep 17 00:00:00 2001 From: "Smokowski, Kevin (ks6305)" Date: Thu, 17 Oct 2019 19:03:35 +0000 Subject: SliStringUtils additional functions in SliStringUtils added Issue-ID: CCSDK-1847 Signed-off-by: Smokowski, Kevin (ks6305) Change-Id: I2e38258abe57d4fcd49cf226877cd38e9dd947d6 --- .../SliPluginUtils_StaticFunctionsTest.java | 21 ++++++- .../core/slipluginutils/SliStringUtilsTest.java | 68 +++++++++++++++++++++- 2 files changed, 85 insertions(+), 4 deletions(-) (limited to 'sliPluginUtils/provider/src/test/java') diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java index 774aa1c8..08adc973 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java @@ -24,10 +24,8 @@ package org.onap.ccsdk.sli.core.slipluginutils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; - import java.util.HashMap; import java.util.Map; - import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; @@ -247,4 +245,23 @@ public class SliPluginUtils_StaticFunctionsTest { SliPluginUtils.setTime(parameters, ctx); assertNotNull(ctx.getAttribute(outputPath)); } + + @Test + public void containsKey() throws Exception { + ctx = new SvcLogicContext(); + parameters.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); + String result = SliPluginUtils.containsKey(parameters, ctx); + assertEquals(SliStringUtils.FALSE_CONSTANT, result); + + ctx.setAttribute("a", null); + parameters.put(SliStringUtils.INPUT_PARAM_KEY, "a"); + result = SliPluginUtils.containsKey(parameters, ctx); + assertEquals(SliStringUtils.FALSE_CONSTANT, result); + + ctx.setAttribute("a", "hellworld"); + parameters.put(SliStringUtils.INPUT_PARAM_KEY, "a"); + result = SliPluginUtils.containsKey(parameters, ctx); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + } + } diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java index b88e8d2c..d8d78a0b 100644 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java +++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java @@ -26,10 +26,8 @@ package org.onap.ccsdk.sli.core.slipluginutils; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; - import java.util.HashMap; import java.util.Map; - import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; @@ -317,4 +315,70 @@ public class SliStringUtilsTest { assertEquals("{\\\"image_name\\\":\\\"Ubuntu 14.04\\\",\\\"service-instance-id\\\":\\\"1\\\",\\\"vnf-model-customization-uuid\\\":\\\"2f\\\",\\\"vnf-id\\\":\\\"3b\\\"}", ctx.getAttribute(outputPath)); } + @Test + public void isEmpty() throws Exception { + ctx = new SvcLogicContext(); + param = new HashMap<>(); + String result = SliStringUtils.isEmpty(param, ctx); + param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", null); + param.put(SliStringUtils.INPUT_PARAM_KEY, "a"); + result = SliStringUtils.isEmpty(param, ctx); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", ""); + result = SliStringUtils.isEmpty(param, ctx); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", " "); + result = SliStringUtils.isEmpty(param, ctx); + assertEquals(SliStringUtils.FALSE_CONSTANT, result); + } + + @Test + public void isBlank() throws Exception { + ctx = new SvcLogicContext(); + param = new HashMap<>(); + String result = SliStringUtils.isBlank(param, ctx); + param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", null); + param.put(SliStringUtils.INPUT_PARAM_KEY, "a"); + result = SliStringUtils.isBlank(param, ctx); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", ""); + result = SliStringUtils.isBlank(param, ctx); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", " "); + result = SliStringUtils.isBlank(param, ctx); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + } + + @Test + public void isNull() throws Exception { + ctx = new SvcLogicContext(); + param = new HashMap<>(); + String result = SliStringUtils.isNull(param, ctx); + param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", null); + param.put(SliStringUtils.INPUT_PARAM_KEY, "a"); + result = SliStringUtils.isNull(param, ctx); + assertEquals(SliStringUtils.TRUE_CONSTANT, result); + + ctx.setAttribute("a", ""); + result = SliStringUtils.isNull(param, ctx); + assertEquals(SliStringUtils.FALSE_CONSTANT, result); + + ctx.setAttribute("a", " "); + result = SliStringUtils.isNull(param, ctx); + assertEquals(SliStringUtils.FALSE_CONSTANT, result); + } + } -- cgit 1.2.3-korg