From 769622040a1fa819d2708c50d4904ac24b867a38 Mon Sep 17 00:00:00 2001 From: janani b Date: Mon, 8 Oct 2018 14:17:51 +0530 Subject: Resolving root level augment nodes Issue fix for root level augment nodes being added to the data format Issue-ID: CCSDK-324 Change-Id: I1c69f97739c6cb56c74b5f22bc4283f2f927719b Signed-off-by: janani b --- .../dfserializer/DataFormatSerializerTest.java | 20 +++++ .../dfserializer/DataFormatUtilsTest.java | 92 ++++++++++++++-------- 2 files changed, 77 insertions(+), 35 deletions(-) (limited to 'restconf-client/provider/src/test/java') diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java index 6c11206c9..40f4c4b1b 100644 --- a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java +++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatSerializerTest.java @@ -50,6 +50,7 @@ import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormat import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_ID; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_RPC; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG; +import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_JSON_YANG_AUG_POST; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_ID; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_RPC; import static org.onap.ccsdk.sli.plugins.yangserializers.dfserializer.DataFormatUtilsTest.ENCODE_TO_XML_YANG; @@ -217,6 +218,25 @@ public class DataFormatSerializerTest { assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG)); } + /** + * Verifies encoding of parameters to JSON data format with augment as + * root child. + * + * @throws SvcLogicException when test case fails + */ + @Test + public void encodeToJsonWithAugAsRootChild() throws SvcLogicException { + String pre = "test-yang:cont1.cont2."; + SvcLogicContext ctx = createAttListYang(pre); + p.put("dirPath", "src/test/resources"); + p.put("format", "json"); + p.put("httpMethod", "post"); + p.put("restapiUrl", "http://echo.getpostman" + + ".com/restconf/operations/test-yang:cont1/cont2/cont4"); + restconf.sendRequest(p, ctx); + assertThat(dfCaptor.getResult(), is(ENCODE_TO_JSON_YANG_AUG_POST)); + } + /** * Verifies decoding of parameters from JSON data format with containers, * grouping and augment. diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java index c7efdeb37..7e6445fcd 100644 --- a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java +++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/dfserializer/DataFormatUtilsTest.java @@ -100,6 +100,46 @@ public final class DataFormatUtilsTest { "yangid:physical\n" + "\n"; + static final String ENCODE_TO_JSON_YANG_COMMON = "\n " + + "\"test-augment:cont13\": {\n" + + " \"ll9\": [\n" + + " \"abc\",\n" + + " \"abc\"\n" + + " ],\n" + + " \"list9\": [\n" + + " {\n" + + " \"leaf27\": \"abc\"\n" + + " },\n" + + " {\n" + + " \"leaf27\": \"abc\"\n" + + " }\n" + + " ],\n" + + " \"leaf28\": \"abc\",\n" + + " \"cont12\": {\n" + + " \"leaf26\": \"abc\"\n" + + " }\n" + + " },\n" + + " \"test-augment:list7\": [\n" + + " {\n" + + " \"leaf14\": \"test\"\n" + + " },\n" + + " {\n" + + " \"leaf14\": \"create\"\n" + + " }\n" + + " ],\n" + + " \"test-augment:leaf15\": \"abc\",\n" + + " \"test-augment:ll6\": [\n" + + " \"unbounded\",\n" + + " \"8\"\n" + + " ],\n" + + " \"test-augment:cont5\": {\n" + + " \"leaf13\": \"true\"\n" + + " }"; + + static final String ENCODE_TO_JSON_YANG_AUG_POST = "{\n" + + " \"test-yang:leaf10\": \"abc\"," + + ENCODE_TO_JSON_YANG_COMMON + "\n}"; + static final String ENCODE_TO_JSON_YANG = "{\n" + " \"test-yang:cont2\": {\n" + " \"list1\": [\n" + @@ -177,41 +217,8 @@ public final class DataFormatUtilsTest { " \"abc\"\n" + " ],\n" + " \"cont4\": {\n" + - " \"leaf10\": \"abc\",\n" + - " \"test-augment:cont13\": {\n" + - " \"ll9\": [\n" + - " \"abc\",\n" + - " \"abc\"\n" + - " ],\n" + - " \"list9\": [\n" + - " {\n" + - " \"leaf27\": \"abc\"\n" + - " },\n" + - " {\n" + - " \"leaf27\": \"abc\"\n" + - " }\n" + - " ],\n" + - " \"leaf28\": \"abc\",\n" + - " \"cont12\": {\n" + - " \"leaf26\": \"abc\"\n" + - " }\n" + - " },\n" + - " \"test-augment:list7\": [\n" + - " {\n" + - " \"leaf14\": \"test\"\n" + - " },\n" + - " {\n" + - " \"leaf14\": \"create\"\n" + - " }\n" + - " ],\n" + - " \"test-augment:leaf15\": \"abc\",\n" + - " \"test-augment:ll6\": [\n" + - " \"unbounded\",\n" + - " \"8\"\n" + - " ],\n" + - " \"test-augment:cont5\": {\n" + - " \"leaf13\": \"true\"\n" + - " }\n" + + " \"leaf10\": \"abc\"," + + addSpace(ENCODE_TO_JSON_YANG_COMMON, 8) + "\n" + " },\n" + " \"ll4\": [\n" + " \"abc\",\n" + @@ -501,4 +508,19 @@ public final class DataFormatUtilsTest { " abc\n" + " \n" + ""; + + /** + * Adds the specified number of space required for a req in each line. + * + * @param req request message + * @param i number of space + * @return space appended string + */ + private static String addSpace(String req, int i) { + StringBuilder space = new StringBuilder(""); + for (int sp = 0; sp < i; sp++) { + space = space.append(" "); + } + return req.replaceAll("\n", "\n" + space.toString()); + } } -- cgit 1.2.3-korg