diff options
author | Enbo Wang <wangenbo@huawei.com> | 2020-02-21 14:57:01 +0800 |
---|---|---|
committer | Dan Timoney <dtimoney@att.com> | 2020-02-21 20:21:32 +0000 |
commit | 3a325d8192addf27423494d8ed8b621dedcf7888 (patch) | |
tree | 46cae681522bff113a5bb8716b57c60c7f8ccedc /sliPluginUtils/provider/src/test | |
parent | dd60cf1b40744590285eec61aa1170ea14c1b9fb (diff) |
Support updating JSON object string for sliPluginUtils
Issue-ID: CCSDK-2111
Signed-off-by: Enbo Wang <wangenbo@huawei.com>
Change-Id: Ide6bb06a05fcbb3b88e73cc0fbec6fd46bd29033
Diffstat (limited to 'sliPluginUtils/provider/src/test')
-rw-r--r-- | sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java | 37 | ||||
-rw-r--r-- | sliPluginUtils/provider/src/test/resources/JsonObject.json | 5 |
2 files changed, 42 insertions, 0 deletions
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 @@ -496,6 +496,43 @@ public class SliPluginUtils_StaticFunctionsTest { } @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<String, String> parametersUpdateJson = new HashMap<String, String>(); + 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<String, String> parametersJsonToCtx = new HashMap<String, String>(); + 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"; String content = new String(Files.readAllBytes(Paths.get(path))); diff --git a/sliPluginUtils/provider/src/test/resources/JsonObject.json b/sliPluginUtils/provider/src/test/resources/JsonObject.json new file mode 100644 index 000000000..0578368f8 --- /dev/null +++ b/sliPluginUtils/provider/src/test/resources/JsonObject.json @@ -0,0 +1,5 @@ +{
+ "aaa": "123",
+ "bbb": "xyz",
+ "c.d": "abc"
+}
\ No newline at end of file |