aboutsummaryrefslogtreecommitdiffstats
path: root/sliPluginUtils/provider
diff options
context:
space:
mode:
authorSmokowski, Kevin (ks6305) <kevin.smokowski@att.com>2020-04-01 19:58:23 +0000
committerDan Timoney <dtimoney@att.com>2020-04-03 17:29:08 +0000
commit6fdb7812d8acb2b13daff5b80d541c162fff6ae7 (patch)
tree4383aebc60f2e359dd40e4f422af9544832540f7 /sliPluginUtils/provider
parentfaaf89d113eb5b820f5d5806de0e0a466ba79964 (diff)
SliPluginUtils jsonStringToCtx fix
Support null values in jsonStringToCtx in Slipluginutils Issue-ID: CCSDK-2250 Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> Change-Id: I3316fa9e80c9e684fc27d83356bbfad9b1151992 (cherry picked from commit b970a7b46fac32e626acfa23b1e2de9b22da7ff7)
Diffstat (limited to 'sliPluginUtils/provider')
-rw-r--r--sliPluginUtils/provider/src/main/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils.java9
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java7
-rw-r--r--sliPluginUtils/provider/src/test/resources/2dArray.json2
-rw-r--r--sliPluginUtils/provider/src/test/resources/ArrayMenu.json2
-rw-r--r--sliPluginUtils/provider/src/test/resources/Widget.json2
5 files changed, 15 insertions, 7 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 ce0f5080..60bb4fd3 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
@@ -70,6 +70,7 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
private static final String LOG_MSG="extracting list from context memory";
private static final String LOG_MSG1="removing elements from list";
private static final String LENGTH="_length";
+ public static final String CTX_NULL_VALUE="";
// ========== CONSTRUCTORS ==========
@@ -846,7 +847,11 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
if(!root.endsWith(".")){
root = root + ".";
}
- ctx.setAttribute(root + key, entry.getValue().getAsString());
+ if(entry.getValue().isJsonNull()) {
+ ctx.setAttribute(root + key, CTX_NULL_VALUE);
+ }else {
+ ctx.setAttribute(root + key, entry.getValue().getAsString());
+ }
}
}
}
@@ -861,6 +866,8 @@ public class SliPluginUtils implements SvcLogicJavaPlugin {
handleJsonArray(key, element.getAsJsonArray(), ctx, prefix);
} else if (element.isJsonObject()) {
writeJsonObject(element.getAsJsonObject(), ctx, prefix + ".");
+ } else if (element.isJsonNull()) {
+ ctx.setAttribute(prefix, CTX_NULL_VALUE);
} else if (element.isJsonPrimitive()) {
ctx.setAttribute(prefix, element.getAsString());
}
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 ad039d7f..bc2c9226 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
@@ -335,7 +335,7 @@ public class SliPluginUtils_StaticFunctionsTest {
assertEquals("plain", ctx.getAttribute("testPath.[0].name"));
assertEquals("pizza", ctx.getAttribute("testPath.[0].type"));
assertEquals("true", ctx.getAttribute("testPath.[0].vegetarian"));
- assertEquals("2000", ctx.getAttribute("testPath.[1].calories"));
+ assertEquals(SliPluginUtils.CTX_NULL_VALUE, ctx.getAttribute("testPath.[1].calories"));
assertEquals("2", ctx.getAttribute("testPath.[1].id"));
assertEquals("Tuesday Special", ctx.getAttribute("testPath.[1].name"));
assertEquals("1", ctx.getAttribute("testPath.[1].topping[0].id"));
@@ -423,7 +423,8 @@ public class SliPluginUtils_StaticFunctionsTest {
assertEquals("apple", ctx.getAttribute("testPath.[0][0]"));
assertEquals("orange", ctx.getAttribute("testPath.[0][1]"));
assertEquals("banana", ctx.getAttribute("testPath.[0][2]"));
- assertEquals("3", ctx.getAttribute("testPath.[0]_length"));
+ assertEquals(SliPluginUtils.CTX_NULL_VALUE, ctx.getAttribute("testPath.[0][3]"));
+ assertEquals("4", ctx.getAttribute("testPath.[0]_length"));
assertEquals("squash", ctx.getAttribute("testPath.[1][0]"));
assertEquals("broccoli", ctx.getAttribute("testPath.[1][1]"));
assertEquals("cauliflower", ctx.getAttribute("testPath.[1][2]"));
@@ -488,7 +489,7 @@ public class SliPluginUtils_StaticFunctionsTest {
assertEquals("text1", ctx.getAttribute("testPath.widget.text.name"));
assertEquals("21", ctx.getAttribute("testPath.widget.text.size"));
assertEquals("bold", ctx.getAttribute("testPath.widget.text.style"));
- assertEquals("200", ctx.getAttribute("testPath.widget.text.vOffset"));
+ assertEquals(SliPluginUtils.CTX_NULL_VALUE, ctx.getAttribute("testPath.widget.text.vOffset"));
assertEquals("300", ctx.getAttribute("testPath.widget.window.height"));
assertEquals("main_window", ctx.getAttribute("testPath.widget.window.name"));
assertEquals("ONAP Widget", ctx.getAttribute("testPath.widget.window.title"));
diff --git a/sliPluginUtils/provider/src/test/resources/2dArray.json b/sliPluginUtils/provider/src/test/resources/2dArray.json
index b473864d..2a94b46f 100644
--- a/sliPluginUtils/provider/src/test/resources/2dArray.json
+++ b/sliPluginUtils/provider/src/test/resources/2dArray.json
@@ -1,4 +1,4 @@
[
- ["apple", "orange", "banana"],
+ ["apple", "orange", "banana", null],
["squash", "broccoli", "cauliflower"]
] \ No newline at end of file
diff --git a/sliPluginUtils/provider/src/test/resources/ArrayMenu.json b/sliPluginUtils/provider/src/test/resources/ArrayMenu.json
index b12f1631..26a24f29 100644
--- a/sliPluginUtils/provider/src/test/resources/ArrayMenu.json
+++ b/sliPluginUtils/provider/src/test/resources/ArrayMenu.json
@@ -8,7 +8,7 @@
"id": "2",
"type": "pizza",
"name": "Tuesday Special",
- "calories": 2000,
+ "calories": null,
"vegetarian": false,
"topping":
[{
diff --git a/sliPluginUtils/provider/src/test/resources/Widget.json b/sliPluginUtils/provider/src/test/resources/Widget.json
index 1e25282c..6b90907c 100644
--- a/sliPluginUtils/provider/src/test/resources/Widget.json
+++ b/sliPluginUtils/provider/src/test/resources/Widget.json
@@ -20,7 +20,7 @@
"style": "bold",
"name": "text1",
"hOffset": 350,
- "vOffset": 200,
+ "vOffset": null,
"alignment": "center"
}
}