diff options
author | 2019-12-19 15:19:53 -0500 | |
---|---|---|
committer | 2019-12-20 10:29:54 -0500 | |
commit | a220181cb93b27fdd02fc5a9252f22113b59cad2 (patch) | |
tree | 960753d9fb9405b775c7c7d36f285c77d9acb37d /restapi-call-node/provider/src/test | |
parent | c185a9bf56303dc4ad9feb4ba5b6227a038f4153 (diff) |
MultiDimension JSON Array Parser
Adding Code to support MutiDimensional json parsing logic
Change-Id: I487f25c9c7eaeb466ac6903bea80175fa4c50728
Issue-ID: CCSDK-2008
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Diffstat (limited to 'restapi-call-node/provider/src/test')
3 files changed, 65 insertions, 18 deletions
diff --git a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java index 569719d6..cdffd457 100644 --- a/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java +++ b/restapi-call-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/restapicall/TestJsonParser.java @@ -134,7 +134,23 @@ public class TestJsonParser { assertEquals("3", mm.get("menu_length")); } - @Test(expected = SvcLogicException.class) // current behavior is multidimensional arrays are not supported + @Test + public void test1dJsonStringToCtx() throws Exception { + String path = "src/test/resources/1dArray.json"; + String content = new String(Files.readAllBytes(Paths.get(path))); + Map<String, String> mm = JsonParser.convertToProperties(content); + + System.out.println(mm); + assertEquals("6", mm.get("_length")); + assertEquals("apple", mm.get("[0]")); + assertEquals("orange", mm.get("[1]")); + assertEquals("banana", mm.get("[2]")); + assertEquals("squash", mm.get("[3]")); + assertEquals("broccoli", mm.get("[4]")); + assertEquals("cauliflower", mm.get("[5]")); + } + + @Test public void test2dJsonStringToCtx() throws Exception { String path = "src/test/resources/2dArray.json"; String content = new String(Files.readAllBytes(Paths.get(path))); @@ -145,6 +161,7 @@ public class TestJsonParser { assertEquals("orange", mm.get("[0][1]")); assertEquals("banana", mm.get("[0][2]")); assertEquals("3", mm.get("[0]_length")); + assertEquals("squash", mm.get("[1][0]")); assertEquals("broccoli", mm.get("[1][1]")); assertEquals("cauliflower", mm.get("[1][2]")); @@ -152,28 +169,48 @@ public class TestJsonParser { assertEquals("2", mm.get("_length")); } - @Test(expected = SvcLogicException.class) // current behavior is multidimensional arrays are not supported + @Test public void test3dJsonStringToCtx() throws Exception { String path = "src/test/resources/3dArray.json"; String content = new String(Files.readAllBytes(Paths.get(path))); Map<String, String> mm = JsonParser.convertToProperties(content); - // code will crash before these tests - assertEquals("a", mm.get("[0][0][0]")); - assertEquals("b", mm.get("[0][0][1]")); - assertEquals("c", mm.get("[0][0][2]")); + assertEquals("3", mm.get("_length")); + assertEquals("1", mm.get("[0]_length")); assertEquals("3", mm.get("[0][0]_length")); - assertEquals("d", mm.get("[0][1][0]")); - assertEquals("e", mm.get("[0][1][1]")); - assertEquals("f", mm.get("[0][1][2]")); - assertEquals("3", mm.get("[0][1]_length")); - assertEquals("2", mm.get("[0]_length")); - assertEquals("x", mm.get("[1][0][0]")); - assertEquals("y", mm.get("[1][0][1]")); - assertEquals("z", mm.get("[1][0][2]")); + + assertEquals("2", mm.get("[1]_length")); assertEquals("3", mm.get("[1][0]_length")); - assertEquals("1", mm.get("[1]_length")); - assertEquals("2", mm.get("_length")); + assertEquals("3", mm.get("[1][1]_length")); + + assertEquals("3", mm.get("[2]_length")); + assertEquals("3", mm.get("[2][0]_length")); + assertEquals("3", mm.get("[2][1]_length")); + assertEquals("3", mm.get("[2][2]_length")); + + assertEquals("x", mm.get("[0][0][0]")); + assertEquals("y", mm.get("[0][0][1]")); + assertEquals("z", mm.get("[0][0][2]")); + + assertEquals("abc", mm.get("[1][0][0]")); + assertEquals("def", mm.get("[1][0][1]")); + assertEquals("xyz", mm.get("[1][0][2]")); + + assertEquals("123", mm.get("[1][1][0]")); + assertEquals("456", mm.get("[1][1][1]")); + assertEquals("789", mm.get("[1][1][2]")); + + assertEquals("a", mm.get("[2][0][0]")); + assertEquals("b", mm.get("[2][0][1]")); + assertEquals("c", mm.get("[2][0][2]")); + + assertEquals("d", mm.get("[2][1][0]")); + assertEquals("e", mm.get("[2][1][1]")); + assertEquals("f", mm.get("[2][1][2]")); + + assertEquals("1", mm.get("[2][2][0]")); + assertEquals("2", mm.get("[2][2][1]")); + assertEquals("3", mm.get("[2][2][2]")); } @Test @@ -216,6 +253,7 @@ public class TestJsonParser { mm = JsonParser.convertToProperties(mm.get("input.parameters[0].value")); assertEquals("0.2.0.0/16", mm.get("[0].id")); assertEquals("ge04::/64", mm.get("[1].id")); + assertEquals("2", mm.get("_length")); } } diff --git a/restapi-call-node/provider/src/test/resources/1dArray.json b/restapi-call-node/provider/src/test/resources/1dArray.json new file mode 100644 index 00000000..208fb70a --- /dev/null +++ b/restapi-call-node/provider/src/test/resources/1dArray.json @@ -0,0 +1,8 @@ +[
+ "apple",
+ "orange",
+ "banana",
+ "squash",
+ "broccoli",
+ "cauliflower"
+]
\ No newline at end of file diff --git a/restapi-call-node/provider/src/test/resources/3dArray.json b/restapi-call-node/provider/src/test/resources/3dArray.json index 14995559..3f3f4fab 100644 --- a/restapi-call-node/provider/src/test/resources/3dArray.json +++ b/restapi-call-node/provider/src/test/resources/3dArray.json @@ -1,4 +1,5 @@ [
- [["a","b","c"], ["d","e","f"]],
- [["x","y","z"]]
+ [["x","y","z"]],
+ [["abc","def","xyz"], [123, 456, 789]],
+ [["a","b","c"], ["d","e","f"], ["1","2","3"]]
]
\ No newline at end of file |