From 3a325d8192addf27423494d8ed8b621dedcf7888 Mon Sep 17 00:00:00 2001 From: Enbo Wang Date: Fri, 21 Feb 2020 14:57:01 +0800 Subject: Support updating JSON object string for sliPluginUtils Issue-ID: CCSDK-2111 Signed-off-by: Enbo Wang Change-Id: Ide6bb06a05fcbb3b88e73cc0fbec6fd46bd29033 --- .../SliPluginUtils_StaticFunctionsTest.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'sliPluginUtils/provider/src/test/java/org') 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 5c222c83f..ad039d7f4 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 @@ -495,6 +495,43 @@ public class SliPluginUtils_StaticFunctionsTest { assertEquals("200", ctx.getAttribute("testPath.widget.window.width")); } + @Test + public void testUpdateJsonObjectString() throws Exception { + String path = "src/test/resources/JsonObject.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("input", content); + + Map parametersUpdateJson = new HashMap(); + parametersUpdateJson.put("source", "input"); + parametersUpdateJson.put("outputPath", "newJsonString"); + + // add key "ccc" and its value + parametersUpdateJson.put("add.ccc", "abcxyz"); + + // update keys and their values of "aaa" and "c.d" + parametersUpdateJson.put("add.aaa", "4567"); + parametersUpdateJson.put("add.c.d", "defg"); + + // delete key "bbb" + parametersUpdateJson.put("delete.bbb", ""); + + SliPluginUtils.updateJsonObjectString(parametersUpdateJson, ctx); + + Map parametersJsonToCtx = new HashMap(); + parametersJsonToCtx.put("source", "newJsonString"); + parametersJsonToCtx.put("outputPath", "testPath"); + parametersJsonToCtx.put("isEscaped", "false"); + + SliPluginUtils.jsonStringToCtx(parametersJsonToCtx, ctx); + + assertEquals("abcxyz", ctx.getAttribute("testPath.ccc")); + assertEquals("4567", ctx.getAttribute("testPath.aaa")); + assertEquals("defg", ctx.getAttribute("testPath.c.d")); + assertEquals(null, ctx.getAttribute("testPath.bbb")); + } + @Test public void testEmbeddedEscapedJsonJsonStringToCtx() throws Exception { String path = "src/test/resources/EmbeddedEscapedJson.json"; -- cgit 1.2.3-korg