summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java11
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java82
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java21
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java68
4 files changed, 153 insertions, 29 deletions
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
index fd3364ca4..b8e88f652 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java
@@ -39,8 +39,8 @@ import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.UUID;
-import org.apache.commons.text.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.text.StringEscapeUtils;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
@@ -1110,4 +1110,13 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
return changeFlag;
}
+ public static String containsKey(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String key = parameters.get("key");
+ Boolean keyFound = ctx.getAttributeKeySet().contains(key);
+ if (keyFound) {
+ return "true";
+ }
+ return "false";
+ }
+
}
diff --git a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
index 888ef8834..269c3766c 100644
--- a/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
+++ b/sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtils.java
@@ -39,10 +39,12 @@ import org.slf4j.LoggerFactory;
*/
public class SliStringUtils implements SvcLogicJavaPlugin {
private static final Logger LOG = LoggerFactory.getLogger(SliStringUtils.class);
-
+ public static final String INPUT_PARAM_KEY = "key";
public static final String INPUT_PARAM_SOURCE = "source";
public static final String INPUT_PARAM_TARGET = "target";
-
+ public static final String TRUE_CONSTANT = "true";
+ public static final String FALSE_CONSTANT = "false";
+
public SliStringUtils() {}
/**
@@ -125,11 +127,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String equalsIgnoreCase(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).equalsIgnoreCase(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).equalsIgnoreCase(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -189,11 +191,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String contains(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).contains(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).contains(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -213,11 +215,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String endsWith(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).endsWith(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).endsWith(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -237,11 +239,11 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static String startsWith(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"target"}, LOG);
- if(parameters.get(INPUT_PARAM_SOURCE).startsWith(parameters.get("target"))){
- return "true";
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET}, LOG);
+ if (parameters.get(INPUT_PARAM_SOURCE).startsWith(parameters.get(INPUT_PARAM_TARGET))) {
+ return TRUE_CONSTANT;
}
- return "false";
+ return FALSE_CONSTANT;
}
/**
@@ -302,8 +304,10 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static void replace(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath","target","replacement"}, LOG);
- ctx.setAttribute(parameters.get("outputPath"), (parameters.get(INPUT_PARAM_SOURCE).replace(parameters.get("target"), parameters.get("replacement"))));
+ SliPluginUtils.checkParameters(parameters,
+ new String[] {INPUT_PARAM_SOURCE, "outputPath", INPUT_PARAM_TARGET, "replacement"}, LOG);
+ ctx.setAttribute(parameters.get("outputPath"), (parameters.get(INPUT_PARAM_SOURCE)
+ .replace(parameters.get(INPUT_PARAM_TARGET), parameters.get("replacement"))));
}
/**
@@ -324,8 +328,10 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static void replaceAll(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
- SliPluginUtils.checkParameters(parameters, new String[]{INPUT_PARAM_SOURCE,"outputPath","target","replacement"}, LOG);
- ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE).replaceAll(parameters.get("target"), parameters.get("replacement")));
+ SliPluginUtils.checkParameters(parameters,
+ new String[] {INPUT_PARAM_SOURCE, "outputPath", INPUT_PARAM_TARGET, "replacement"}, LOG);
+ ctx.setAttribute(parameters.get("outputPath"), parameters.get(INPUT_PARAM_SOURCE)
+ .replaceAll(parameters.get(INPUT_PARAM_TARGET), parameters.get("replacement")));
}
/**
@@ -385,8 +391,9 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
* @since 11.0.2
*/
public static void concat( Map<String, String> parameters, SvcLogicContext ctx ) throws SvcLogicException {
- SliPluginUtils.checkParameters( parameters, new String[]{INPUT_PARAM_SOURCE,"target","outputPath"}, LOG );
- String result = parameters.get(INPUT_PARAM_SOURCE).concat(parameters.get("target"));
+ SliPluginUtils.checkParameters(parameters, new String[] {INPUT_PARAM_SOURCE, INPUT_PARAM_TARGET, "outputPath"},
+ LOG);
+ String result = parameters.get(INPUT_PARAM_SOURCE).concat(parameters.get(INPUT_PARAM_TARGET));
ctx.setAttribute(parameters.get("outputPath"), result);
}
@@ -475,4 +482,31 @@ public class SliStringUtils implements SvcLogicJavaPlugin {
throw new SvcLogicException("problem with escapeJsonString", ex);
}
}
+
+ public static String isBlank(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String ctxLocation = parameters.get(INPUT_PARAM_KEY);
+ String str = ctx.getAttribute(ctxLocation);
+ if (str == null || str.isEmpty() || " ".equals(str)) {
+ return TRUE_CONSTANT;
+ }
+ return FALSE_CONSTANT;
+ }
+
+ public static String isEmpty(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String ctxLocation = parameters.get(INPUT_PARAM_KEY);
+ String str = ctx.getAttribute(ctxLocation);
+ if (str == null || str.isEmpty()) {
+ return TRUE_CONSTANT;
+ }
+ return FALSE_CONSTANT;
+ }
+
+ public static String isNull(Map<String, String> parameters, SvcLogicContext ctx) throws SvcLogicException {
+ String ctxLocation = parameters.get(INPUT_PARAM_KEY);
+ String str = ctx.getAttribute(ctxLocation);
+ if (str == null) {
+ return TRUE_CONSTANT;
+ }
+ return FALSE_CONSTANT;
+ }
}
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 774aa1c84..08adc9731 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 b88e8d2c9..d8d78a0b1 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);
+ }
+
}