diff options
author | janani b <janani.b@huawei.com> | 2018-10-08 14:17:51 +0530 |
---|---|---|
committer | Janani B <janani.b@huawei.com> | 2018-10-08 09:14:37 +0000 |
commit | 769622040a1fa819d2708c50d4904ac24b867a38 (patch) | |
tree | 7c92010c37da84613565b0549cbe737b1ff0244d | |
parent | 87850a15d93c7a1162d30c129e0dc76cd1b66f94 (diff) |
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 <janani.b@huawei.com>
3 files changed, 104 insertions, 35 deletions
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java index 8497805c2..f23452653 100644 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeWalker.java @@ -22,6 +22,7 @@ package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer; import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import java.util.Collection; import java.util.Map; /** @@ -58,6 +59,32 @@ public class DefaultPropertiesNodeWalker<T extends NodeChild> implements Propert listener.exitPropertiesNode(node); } } + if (propertiesNode instanceof RootNode) { + processAugments(propertiesNode, listener); + } + } + + /** + * Processes the augments present in the root node. + * + * @param node root node + * @param listener properties node listener + * @throws SvcLogicException when augment node walking fails + */ + private void processAugments(PropertiesNode node, + PropertiesNodeListener listener) + throws SvcLogicException { + for (Map.Entry<Object, Collection<PropertiesNode>> + augToChild : node.augmentations().asMap().entrySet()) { + Collection<PropertiesNode> child = augToChild.getValue(); + if (!child.isEmpty()) { + for (PropertiesNode p : child) { + listener.enterPropertiesNode(p); + walkChildNode(listener, p); + listener.exitPropertiesNode(p); + } + } + } } /** 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; @@ -218,6 +219,25 @@ public class DataFormatSerializerTest { } /** + * 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</interface>\n" + "</con1>\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 { " <leaf28>abc</leaf28>\n" + " </cont13>\n" + "</output>"; + + /** + * 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()); + } } |