aboutsummaryrefslogtreecommitdiffstats
path: root/restconf-client
diff options
context:
space:
mode:
authorVidyashree Rama <vidyashree.rama@huawei.com>2018-08-17 17:15:20 +0530
committerVidyashree Rama <vidyashree.rama@huawei.com>2018-08-17 17:17:37 +0530
commit224d394cda8a832f8d8c9db03795343ac82f7058 (patch)
treea2169c9a25aeacfe0519e8778fcaf0ee2d34bc56 /restconf-client
parent06f4a6531b11b1e841f4c63b968d2b8a7a65eaf6 (diff)
Unit test and decode implementation
properties node serializer decode implementation and unit test cases Issue-ID: CCSDK-378 Change-Id: I586fd534f441eb361e8d75af18cc778f7ad4cc67 Signed-off-by: Vidyashree Rama <vidyashree.rama@huawei.com>
Diffstat (limited to 'restconf-client')
-rwxr-xr-xrestconf-client/provider/pom.xml18
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java95
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java7
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java1
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java7
-rw-r--r--restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/RootNode.java4
-rw-r--r--restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java1090
-rw-r--r--restconf-client/provider/src/test/resources/yang/test-augment.yang85
-rw-r--r--restconf-client/provider/src/test/resources/yang/test-yang.yang231
9 files changed, 1532 insertions, 6 deletions
diff --git a/restconf-client/provider/pom.xml b/restconf-client/provider/pom.xml
index 8995f1dd..2b5be877 100755
--- a/restconf-client/provider/pom.xml
+++ b/restconf-client/provider/pom.xml
@@ -94,5 +94,23 @@
<artifactId>restapi-call-node-provider</artifactId>
<version>0.3.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.hamcrest</groupId>
+ <artifactId>hamcrest-library</artifactId>
+ <version>1.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-test-util</artifactId>
+ <version>2.0.3</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.netconf</groupId>
+ <artifactId>restconf-nb-rfc8040</artifactId>
+ <version>1.7.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java
new file mode 100644
index 00000000..a8a9b493
--- /dev/null
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/DefaultPropertiesNodeListener.java
@@ -0,0 +1,95 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.MULTI_INSTANCE_LEAF_NODE;
+import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.SINGLE_INSTANCE_LEAF_NODE;
+
+/**
+ * Represents implementation of PropertiesNodeListener.
+ */
+public class DefaultPropertiesNodeListener implements PropertiesNodeListener {
+
+ private Map<String, String> params = new HashMap<>();
+
+ @Override
+ public void start(PropertiesNode node) {
+ // do nothing
+ }
+
+ @Override
+ public void end(PropertiesNode node) {
+ exitPropertiesNode(node);
+ }
+
+ @Override
+ public void enterPropertiesNode(PropertiesNode node) {
+ /*
+ * Only if it is leaf node or leaf-list node,
+ * then create a property entry and add to map
+ */
+ if (node.nodeType() == SINGLE_INSTANCE_LEAF_NODE
+ || node.nodeType() == MULTI_INSTANCE_LEAF_NODE) {
+ params.put(node.uri(), ((LeafNode) node).value());
+ }
+ }
+
+ @Override
+ public void exitPropertiesNode(PropertiesNode node) {
+ if (!node.augmentations().isEmpty()) {
+ for (Map.Entry<Object, Collection<PropertiesNode>> augmentationTochild
+ : node.augmentations().asMap().entrySet()) {
+ Collection<PropertiesNode> childsFromAugmentations = augmentationTochild
+ .getValue();
+ if (!childsFromAugmentations.isEmpty()) {
+ PropertiesNodeWalker walker = new DefaultPropertiesNodeWalker<>();
+ for (PropertiesNode pNode : childsFromAugmentations) {
+ enterPropertiesNode(pNode);
+ walker.walk(this, pNode);
+ exitPropertiesNode(pNode);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Returns properties.
+ *
+ * @return properties
+ */
+ public Map<String, String> params() {
+ return params;
+ }
+
+ /**
+ * Sets properties.
+ *
+ * @param params properties
+ */
+ public void params(Map<String, String> params) {
+ this.params = params;
+ }
+}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java
index 063c3d05..0711a7cf 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/InnerNode.java
@@ -104,7 +104,7 @@ public abstract class InnerNode<T extends NodeChild> extends PropertiesNode {
@Override
public PropertiesNode addChild(String name, Namespace namespace,
NodeType type, String value,
- Namespace valuens,
+ Namespace valueNs,
Object appInfo) throws SvcLogicException {
LeafNode node = ((LeafNode) children.get(name));
if (node != null) {
@@ -120,6 +120,7 @@ public abstract class InnerNode<T extends NodeChild> extends PropertiesNode {
String uri = getUri(this, name, namespace);
node = new LeafNode(name, namespace, uri, this,
appInfo, type, value);
+ node.valueNs(valueNs);
if (augSchema != null && !isNamespaceAsParent(this, node)) {
addToAugmentations(augSchema, this, node);
@@ -196,12 +197,12 @@ public abstract class InnerNode<T extends NodeChild> extends PropertiesNode {
children.put(localName, ((T) node));
}
- node = node.addChild(index, localName, namespace, type, value, null, appInfo);
+ node = node.addChild(index, localName, namespace, type, value, valueNs, appInfo);
} else if (node instanceof LeafListHolderNode) {
LeafNode child = ((LeafNode) ((HolderNode) node).child(index));
node = (child != null ? child : node.addChild(index, localName,
namespace, type,
- value, null,
+ value, valueNs,
appInfo));
} else {
throw new SvcLogicException("Duplicate node exist with same node");
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java
index 94892dca..985bc1da 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/LeafListHolderNode.java
@@ -82,6 +82,7 @@ public class LeafListHolderNode extends HolderNode<LeafListHolderChild> implemen
String uri = this.uri() + "[" + index + "]";
node = (node != null) ? node : new LeafNode(name, namespace, uri,
this, appInfo, type, value);
+ node.valueNs(valueNs);
children().put(index, node);
return node;
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java
index 405e2412..146e581f 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java
@@ -86,7 +86,10 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche
@Override
public Map<String, String> decode(PropertiesNode propertiesNode) {
- return null;
+ PropertiesNodeWalker walker = new DefaultPropertiesNodeWalker<>();
+ DefaultPropertiesNodeListener listener = new DefaultPropertiesNodeListener();
+ walker.walk(listener, propertiesNode);
+ return listener.params();
}
private RootNode createRootNode(String lastNodeName, String rootUri) {
@@ -128,6 +131,8 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer<Sche
node = node.endNode();
curSchema = ((SchemaNode) node.appInfo());
break;
+ default:
+ throw new SvcLogicException("Invalid node type");
}
}
}
diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/RootNode.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/RootNode.java
index 0159683a..7d9035e0 100644
--- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/RootNode.java
+++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/RootNode.java
@@ -189,12 +189,12 @@ public class RootNode<T extends NodeChild> extends PropertiesNode {
} else {
children.put(localName, ((T) node));
}
- node = node.addChild(index, localName, namespace, type, value, null, appInfo);
+ node = node.addChild(index, localName, namespace, type, value, valueNs, appInfo);
} else if (node instanceof LeafListHolderNode) {
LeafNode child = ((LeafNode) ((HolderNode) node).child(index));
node = (child != null ? child : node.addChild(index, localName,
namespace, type,
- value, null,
+ value, valueNs,
appInfo));
} else {
throw new SvcLogicException("Duplicate node exist with same node");
diff --git a/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java
new file mode 100644
index 00000000..fddfe2d4
--- /dev/null
+++ b/restconf-client/provider/src/test/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/PropertiesSerializerTest.java
@@ -0,0 +1,1090 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - CCSDK
+ * ================================================================================
+ * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
+import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
+
+public final class PropertiesSerializerTest {
+ private SchemaContext context;
+
+ @Before
+ public void initialization() throws FileNotFoundException {
+ context = compileYangFile();
+ }
+
+ @Test
+ public void testBasicConstructs() throws SvcLogicException {
+ String uri = "test-yang:cont1/cont2";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont1.cont2.cont3.leaf10", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].leaf1", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].leaf2", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].leaf3", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].ll1[0]", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].ll1[1]", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].ll2[0]", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].ll2[1]", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].cont4.leaf11", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].list4[0].leaf8", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].list4[1].leaf8", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].list5[0].leaf9", "abc");
+ params.put("test-yang:cont1.cont2.list1[0].list5[1].leaf9", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].leaf1", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].leaf2", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].leaf3", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].ll1[0]", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].ll1[1]", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].ll2[0]", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].ll2[1]", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].cont4.leaf11", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].list4[0].leaf8", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].list4[1].leaf8", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].list5[0].leaf9", "abc");
+ params.put("test-yang:cont1.cont2.list1[1].list5[1].leaf9", "abc");
+ params.put("test-yang:cont1.cont2.list2[0].leaf4", "abc");
+ params.put("test-yang:cont1.cont2.list2[1].leaf4", "abc");
+ params.put("test-yang:cont1.cont2.leaf5", "abc");
+ params.put("test-yang:cont1.cont2.leaf6", "abc");
+ params.put("test-yang:cont1.cont2.ll3[0]", "abc");
+ params.put("test-yang:cont1.cont2.ll3[1]", "abc");
+ params.put("test-yang:cont1.cont2.ll4[0]", "abc");
+ params.put("test-yang:cont1.cont2.ll4[1]", "abc");
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont3"), is(true));
+ SingleInstanceNode cont3 = ((SingleInstanceNode) childNodes.get("cont3"));
+ assertThat(cont3.uri(), is("test-yang:cont1.cont2.cont3"));
+ assertThat(cont3.children().containsKey("leaf10"), is(true));
+
+ assertThat(childNodes.containsKey("list1"), is(true));
+ HolderNode list1Holder = ((ListHolderNode) childNodes.get("list1"));
+ assertThat(list1Holder.uri(), is("test-yang:cont1.cont2.list1"));
+ MultiInstanceNode list10 = ((MultiInstanceNode) list1Holder.child("0"));
+ assertThat(list10.uri(), is("test-yang:cont1.cont2.list1[0]"));
+ Map<String, DataNodeChild> list10Child = list10.children();
+ assertThat(list10Child.containsKey("leaf1"), is(true));
+ LeafNode l = ((LeafNode) list10Child.get("leaf1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf1"));
+ assertThat(list10Child.containsKey("leaf2"), is(true));
+ l = ((LeafNode) list10Child.get("leaf2"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf2"));
+ assertThat(list10Child.containsKey("leaf2"), is(true));
+ l = ((LeafNode) list10Child.get("leaf3"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].leaf3"));
+
+ LeafListHolderNode ll1Holder = ((LeafListHolderNode) list10Child.get("ll1"));
+ assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll1"));
+ assertThat(ll1Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll1Holder.child("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[0]"));
+ assertThat(ll1Holder.children().containsKey("1"), is(true));
+ l = ((LeafNode) ll1Holder.child("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll1[1]"));
+
+ LeafListHolderNode ll2Holder = ((LeafListHolderNode) list10Child.get("ll2"));
+ assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[0].ll2"));
+ assertThat(ll2Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll2Holder.child("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[0]"));
+ assertThat(ll2Holder.children().containsKey("1"), is(true));
+ l = ((LeafNode) ll2Holder.child("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].ll2[1]"));
+
+ SingleInstanceNode cont4 = ((SingleInstanceNode) list10Child.get("cont4"));
+ assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[0].cont4"));
+ assertThat(cont4.children().containsKey("leaf11"), is(true));
+ l = ((LeafNode) cont4.children().get("leaf11"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].cont4.leaf11"));
+
+ HolderNode list4Holder = ((HolderNode) list10Child.get("list4"));
+ assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[0].list4"));
+ Map<String, PropertiesNode> c = list4Holder.children();
+ MultiInstanceNode list40 = ((MultiInstanceNode) c.get("0"));
+ assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[0].list4[0]"));
+ assertThat(list40.children().containsKey("leaf8"), is(true));
+ l = ((LeafNode) list40.children().get("leaf8"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[0].leaf8"));
+ MultiInstanceNode list41 = ((MultiInstanceNode) c.get("1"));
+ assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[0].list4[1]"));
+ assertThat(list41.children().containsKey("leaf8"), is(true));
+ l = ((LeafNode) list41.children().get("leaf8"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list4[1].leaf8"));
+
+ HolderNode list5Holder = ((HolderNode) list10Child.get("list5"));
+ assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[0].list5"));
+ c = list5Holder.children();
+ MultiInstanceNode list50 = ((MultiInstanceNode) c.get("0"));
+ assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[0].list5[0]"));
+ assertThat(list50.children().containsKey("leaf9"), is(true));
+ l = ((LeafNode) list50.children().get("leaf9"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[0].leaf9"));
+ MultiInstanceNode list51 = ((MultiInstanceNode) c.get("1"));
+ assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[0].list5[1]"));
+ assertThat(list51.children().containsKey("leaf9"), is(true));
+ l = ((LeafNode) list51.children().get("leaf9"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[0].list5[1].leaf9"));
+
+ MultiInstanceNode list11 = ((MultiInstanceNode) list1Holder.child("1"));
+ assertThat(list11.uri(), is("test-yang:cont1.cont2.list1[1]"));
+ Map<String, DataNodeChild> list11Child = list11.children();
+ assertThat(list11Child.containsKey("leaf1"), is(true));
+ l = ((LeafNode) list11Child.get("leaf1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf1"));
+ assertThat(list11Child.containsKey("leaf2"), is(true));
+ l = ((LeafNode) list11Child.get("leaf2"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf2"));
+ assertThat(list11Child.containsKey("leaf3"), is(true));
+ l = ((LeafNode) list11Child.get("leaf3"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].leaf3"));
+
+ ll1Holder = ((LeafListHolderNode) list11Child.get("ll1"));
+ assertThat(ll1Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll1"));
+ assertThat(ll1Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll1Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[0]"));
+ assertThat(ll1Holder.children().containsKey("1"), is(true));
+ l = ((LeafNode) ll1Holder.children().get("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll1[1]"));
+
+ ll2Holder = ((LeafListHolderNode) list11Child.get("ll2"));
+ assertThat(ll2Holder.uri(), is("test-yang:cont1.cont2.list1[1].ll2"));
+ assertThat(ll2Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll2Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[0]"));
+ assertThat(ll2Holder.children().containsKey("1"), is(true));
+ l = ((LeafNode) ll2Holder.children().get("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].ll2[1]"));
+
+ cont4 = ((SingleInstanceNode) list11Child.get("cont4"));
+ assertThat(cont4.uri(), is("test-yang:cont1.cont2.list1[1].cont4"));
+ assertThat(cont4.children().containsKey("leaf11"), is(true));
+ l = ((LeafNode) cont4.children().get("leaf11"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].cont4.leaf11"));
+
+ list4Holder = ((HolderNode) list11Child.get("list4"));
+ assertThat(list4Holder.uri(), is("test-yang:cont1.cont2.list1[1].list4"));
+ c = list4Holder.children();
+ list40 = ((MultiInstanceNode) c.get("0"));
+ assertThat(list40.uri(), is("test-yang:cont1.cont2.list1[1].list4[0]"));
+ assertThat(list40.children().containsKey("leaf8"), is(true));
+ l = ((LeafNode) list40.children().get("leaf8"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[0].leaf8"));
+ list41 = ((MultiInstanceNode) c.get("1"));
+ assertThat(list41.uri(), is("test-yang:cont1.cont2.list1[1].list4[1]"));
+ assertThat(list41.children().containsKey("leaf8"), is(true));
+ l = ((LeafNode) list41.children().get("leaf8"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list4[1].leaf8"));
+
+ list5Holder = ((HolderNode) list11Child.get("list5"));
+ assertThat(list5Holder.uri(), is("test-yang:cont1.cont2.list1[1].list5"));
+ c = list5Holder.children();
+ list50 = ((MultiInstanceNode) c.get("0"));
+ assertThat(list50.uri(), is("test-yang:cont1.cont2.list1[1].list5[0]"));
+ assertThat(list50.children().containsKey("leaf9"), is(true));
+ l = ((LeafNode) list50.children().get("leaf9"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[0].leaf9"));
+ list51 = ((MultiInstanceNode) c.get("1"));
+ assertThat(list51.uri(), is("test-yang:cont1.cont2.list1[1].list5[1]"));
+ assertThat(list51.children().containsKey("leaf9"), is(true));
+ l = ((LeafNode) list51.children().get("leaf9"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list1[1].list5[1].leaf9"));
+
+ assertThat(childNodes.containsKey("list2"), is(true));
+ HolderNode list2Holder = ((HolderNode) childNodes.get("list2"));
+ assertThat(list2Holder.uri(), is("test-yang:cont1.cont2.list2"));
+ InnerNode list20 = ((InnerNode) list2Holder.children().get("0"));
+ assertThat(list20.uri(), is("test-yang:cont1.cont2.list2[0]"));
+ assertThat(list20.children().containsKey("leaf4"), is(true));
+ l = ((LeafNode) list20.children().get("leaf4"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list2[0].leaf4"));
+ InnerNode list21 = ((InnerNode) list2Holder.children().get("1"));
+ assertThat(list21.uri(), is("test-yang:cont1.cont2.list2[1]"));
+ assertThat(list21.children().containsKey("leaf4"), is(true));
+ l = ((LeafNode) list21.children().get("leaf4"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list2[1].leaf4"));
+
+ assertThat(childNodes.containsKey("leaf5"), is(true));
+ l = ((LeafNode) childNodes.get("leaf5"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.leaf5"));
+ assertThat(childNodes.containsKey("leaf6"), is(true));
+ l = ((LeafNode) childNodes.get("leaf6"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.leaf6"));
+
+ HolderNode ll3Holder = ((HolderNode) childNodes.get("ll3"));
+ assertThat(ll3Holder.uri(), is("test-yang:cont1.cont2.ll3"));
+ assertThat(((LeafNode) ll3Holder.children().get("0")).name(), is("ll3"));
+ l = ((LeafNode) ll3Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[0]"));
+ assertThat(((LeafNode) ll3Holder.children().get("1")).name(), is("ll3"));
+ l = ((LeafNode) ll3Holder.children().get("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.ll3[1]"));
+
+ HolderNode ll4Holder = ((HolderNode) childNodes.get("ll4"));
+ assertThat(ll4Holder.uri(), is("test-yang:cont1.cont2.ll4"));
+ assertThat(((LeafNode) ll4Holder.children().get("0")).name(), is("ll4"));
+ l = ((LeafNode) ll4Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[0]"));
+ assertThat(((LeafNode) ll4Holder.children().get("1")).name(), is("ll4"));
+ l = ((LeafNode) ll4Holder.children().get("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.ll4[1]"));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testAugment() throws SvcLogicException {
+ String uri = "test-yang:cont1/cont2";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont1.cont2.cont4.leaf10", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:cont5.leaf13", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:list7[0].leaf14", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:list7[1].leaf14", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:leaf15", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:ll6[0]", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:ll6[1]", "abc");
+ params.put("test-yang:cont1.cont2.list6[0].leaf11", "abc");
+ params.put("test-yang:cont1.cont2.list6[1].leaf11", "abc");
+ params.put("test-yang:cont1.cont2.leaf12", "abc");
+ params.put("test-yang:cont1.cont2.ll5[0]", "abc");
+ params.put("test-yang:cont1.cont2.ll5[1]", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont4"), is(true));
+ SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont4"));
+ for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
+ : cont4.augmentations().asMap().entrySet()) {
+ Collection<PropertiesNode> child = augToChild.getValue();
+ if (!child.isEmpty()) {
+ List<String> expectedNodes = new LinkedList<>();
+ expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont5");
+ expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:list7");
+ expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:leaf15");
+ expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:ll6");
+ assertThat(expectedNodes.size(), is(child.size()));
+ for (PropertiesNode pNode : child) {
+ assertThat(expectedNodes.contains(pNode.uri()), is(true));
+ if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:cont5")) {
+ assertThat(((SingleInstanceNode) pNode).children().containsKey("leaf13"), is(true));
+ LeafNode l = ((LeafNode) ((SingleInstanceNode) pNode).children().get("leaf13"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont5.leaf13"));
+ } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:list7")) {
+ ListHolderNode list7Holder = ((ListHolderNode) pNode);
+ MultiInstanceNode list7 = ((MultiInstanceNode) list7Holder.child("0"));
+ assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0]"));
+ Map<String, DataNodeChild> list7Child = list7.children();
+ assertThat(list7Child.containsKey("leaf14"), is(true));
+ LeafNode l = ((LeafNode) list7Child.get("leaf14"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[0].leaf14"));
+ list7 = ((MultiInstanceNode) list7Holder.child("1"));
+ assertThat(list7.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1]"));
+ list7Child = list7.children();
+ assertThat(list7Child.containsKey("leaf14"), is(true));
+ l = ((LeafNode) list7Child.get("leaf14"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:list7[1].leaf14"));
+ } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:leaf15")) {
+ LeafNode leaf15 = ((LeafNode) pNode);
+ assertThat(leaf15.name(), is("leaf15"));
+ assertThat(leaf15.uri(), is("test-yang:cont1.cont2.cont4.test-augment:leaf15"));
+ } else if (pNode.uri().equals("test-yang:cont1.cont2.cont4.test-augment:ll6")) {
+ LeafListHolderNode ll6Holder = ((LeafListHolderNode) pNode);
+ assertThat(ll6Holder.children().containsKey("0"), is(true));
+ LeafNode l = ((LeafNode) ll6Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[0]"));
+ assertThat(ll6Holder.children().containsKey("1"), is(true));
+ l = ((LeafNode) ll6Holder.children().get("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:ll6[1]"));
+ }
+ }
+ }
+ }
+ assertThat(cont4.uri(), is("test-yang:cont1.cont2.cont4"));
+ assertThat(cont4.children().containsKey("leaf10"), is(true));
+ LeafNode l = ((LeafNode) cont4.children().get("leaf10"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.leaf10"));
+
+ assertThat(childNodes.containsKey("list6"), is(true));
+ HolderNode list6Holder = ((ListHolderNode) childNodes.get("list6"));
+ assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.list6"));
+ MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
+ assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[0]"));
+ Map<String, DataNodeChild> list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf11"), is(true));
+ l = ((LeafNode) list6Child.get("leaf11"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list6[0].leaf11"));
+ list6 = ((MultiInstanceNode) list6Holder.child("1"));
+ assertThat(list6.uri(), is("test-yang:cont1.cont2.list6[1]"));
+ list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf11"), is(true));
+ l = ((LeafNode) list6Child.get("leaf11"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.list6[1].leaf11"));
+
+ assertThat(childNodes.containsKey("leaf12"), is(true));
+ LeafNode leaf12 = ((LeafNode) childNodes.get("leaf12"));
+ assertThat(leaf12.name(), is("leaf12"));
+ assertThat(leaf12.uri(), is("test-yang:cont1.cont2.leaf12"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll5"));
+ assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.ll5"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[0]"));
+ assertThat(ll5Holder.children().containsKey("1"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("1"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.ll5[1]"));
+
+ Map<String, String> output = ser.decode(node);
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testChoiceCase1() throws SvcLogicException {
+ String uri = "test-yang:cont8";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont8.cont6.leaf16", "abc");
+ params.put("test-yang:cont8.list8[0].leaf18", "abc");
+ params.put("test-yang:cont8.list8[1].leaf18", "abc");
+ params.put("test-yang:cont8.leaf19", "abc");
+ params.put("test-yang:cont8.ll7[0]", "abc");
+ params.put("test-yang:cont8.ll7[1]", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont6"), is(true));
+ SingleInstanceNode cont6 = ((SingleInstanceNode) childNodes.get("cont6"));
+ assertThat(cont6.uri(), is("test-yang:cont8.cont6"));
+ assertThat(cont6.children().containsKey("leaf16"), is(true));
+ LeafNode l = ((LeafNode) cont6.children().get("leaf16"));
+ assertThat(l.uri(), is("test-yang:cont8.cont6.leaf16"));
+
+ assertThat(childNodes.containsKey("list8"), is(true));
+ HolderNode list6Holder = ((ListHolderNode) childNodes.get("list8"));
+ assertThat(list6Holder.uri(), is("test-yang:cont8.list8"));
+ MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
+ assertThat(list6.uri(), is("test-yang:cont8.list8[0]"));
+ Map<String, DataNodeChild> list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf18"), is(true));
+ l = ((LeafNode) list6Child.get("leaf18"));
+ assertThat(l.uri(), is("test-yang:cont8.list8[0].leaf18"));
+ list6 = ((MultiInstanceNode) list6Holder.child("1"));
+ list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf18"), is(true));
+ l = ((LeafNode) list6Child.get("leaf18"));
+ assertThat(l.uri(), is("test-yang:cont8.list8[1].leaf18"));
+
+ assertThat(childNodes.containsKey("leaf19"), is(true));
+ LeafNode leaf12 = ((LeafNode) childNodes.get("leaf19"));
+ assertThat(leaf12.name(), is("leaf19"));
+ assertThat(leaf12.uri(), is("test-yang:cont8.leaf19"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll7"));
+ assertThat(ll5Holder.uri(), is("test-yang:cont8.ll7"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont8.ll7[0]"));
+ assertThat(ll5Holder.children().containsKey("1"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("1"));
+ assertThat(l.uri(), is("test-yang:cont8.ll7[1]"));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testChoiceCase2() throws SvcLogicException {
+ String uri = "test-yang:cont9";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont9.leaf20", "abc");
+ params.put("test-yang:cont9.ll8[0]", "abc");
+ params.put("test-yang:cont9.cont11.leaf25", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont11"), is(true));
+ SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont11"));
+ assertThat(cont4.uri(), is("test-yang:cont9.cont11"));
+ assertThat(cont4.children().containsKey("leaf25"), is(true));
+ LeafNode l = ((LeafNode) cont4.children().get("leaf25"));
+ assertThat(l.uri(), is("test-yang:cont9.cont11.leaf25"));
+
+ assertThat(childNodes.containsKey("leaf20"), is(true));
+ l = ((LeafNode) childNodes.get("leaf20"));
+ assertThat(l.uri(), is("test-yang:cont9.leaf20"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll8"));
+ assertThat(ll5Holder.uri(), is("test-yang:cont9.ll8"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont9.ll8[0]"));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testChoiceCase3() throws SvcLogicException {
+ String uri = "test-yang:cont8/cont6";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont8.cont6.test-augment:leaf21", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
+ : node.augmentations().asMap().entrySet()) {
+ Collection<PropertiesNode> child = augToChild.getValue();
+ if (!child.isEmpty()) {
+ List<String> expectedNodes = new LinkedList<>();
+ expectedNodes.add("test-yang:cont8.cont6.test-augment:leaf21");
+ assertThat(expectedNodes.size(), is(child.size()));
+ for (PropertiesNode pNode : child) {
+ assertThat(expectedNodes.contains(pNode.uri()), is(true));
+ }
+ }
+ }
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("leaf21"), is(true));
+ LeafNode leaf12 = ((LeafNode) childNodes.get("leaf21"));
+ assertThat(leaf12.name(), is("leaf21"));
+ assertThat(leaf12.uri(), is("test-yang:cont8.cont6.test-augment:leaf21"));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testGrouping() throws SvcLogicException {
+ String uri = "test-yang:cont13";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont13.cont12.leaf26", "abc");
+ params.put("test-yang:cont13.list9[0].leaf27", "abc");
+ params.put("test-yang:cont13.leaf28", "abc");
+ params.put("test-yang:cont13.ll9[0]", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont12"), is(true));
+ SingleInstanceNode cont4 = ((SingleInstanceNode) childNodes.get("cont12"));
+ assertThat(cont4.uri(), is("test-yang:cont13.cont12"));
+ assertThat(cont4.children().containsKey("leaf26"), is(true));
+ LeafNode l = ((LeafNode) cont4.children().get("leaf26"));
+ assertThat(l.uri(), is("test-yang:cont13.cont12.leaf26"));
+
+ assertThat(childNodes.containsKey("list9"), is(true));
+ HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
+ assertThat(list6Holder.uri(), is("test-yang:cont13.list9"));
+ MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
+ assertThat(list6.uri(), is("test-yang:cont13.list9[0]"));
+ Map<String, DataNodeChild> list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf27"), is(true));
+ l = ((LeafNode) list6Child.get("leaf27"));
+ assertThat(l.uri(), is("test-yang:cont13.list9[0].leaf27"));
+
+ assertThat(childNodes.containsKey("leaf28"), is(true));
+ LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
+ assertThat(leaf12.name(), is("leaf28"));
+ assertThat(leaf12.uri(), is("test-yang:cont13.leaf28"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testGrouping2() throws SvcLogicException {
+ String uri = "test-yang:cont9/cont11";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont9.cont11.leaf25", "abc");
+ params.put("test-yang:cont9.cont11.cont13.cont12.leaf26", "abc");
+ params.put("test-yang:cont9.cont11.cont13.list9[0].leaf27", "abc");
+ params.put("test-yang:cont9.cont11.cont13.leaf28", "abc");
+ params.put("test-yang:cont9.cont11.cont13.ll9[0]", "abc");
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont13"), is(true));
+ SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
+ assertThat(cont13.uri(), is("test-yang:cont9.cont11.cont13"));
+ SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
+ assertThat(cont12.children().containsKey("leaf26"), is(true));
+ assertThat(cont12.uri(), is("test-yang:cont9.cont11.cont13.cont12"));
+ assertThat(cont12.children().containsKey("leaf26"), is(true));
+ LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
+ assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.cont12.leaf26"));
+
+ assertThat(cont13.children().containsKey("list9"), is(true));
+ HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
+ assertThat(list6Holder.uri(), is("test-yang:cont9.cont11.cont13.list9"));
+ MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
+ assertThat(list6.uri(), is("test-yang:cont9.cont11.cont13.list9[0]"));
+ Map<String, DataNodeChild> list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf27"), is(true));
+ l = ((LeafNode) list6Child.get("leaf27"));
+ assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.list9[0].leaf27"));
+
+ assertThat(cont13.children().containsKey("leaf28"), is(true));
+ LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
+ assertThat(leaf12.name(), is("leaf28"));
+ assertThat(leaf12.uri(), is("test-yang:cont9.cont11.cont13.leaf28"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
+ assertThat(ll5Holder.uri(), is("test-yang:cont9.cont11.cont13.ll9"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont9.cont11.cont13.ll9[0]"));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testGrouping3() throws SvcLogicException {
+ String uri = "test-augment:cont13";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-augment:cont13.cont12.leaf26", "abc");
+ params.put("test-augment:cont13.list9[0].leaf27", "abc");
+ params.put("test-augment:cont13.leaf28", "abc");
+ params.put("test-augment:cont13.ll9[0]", "abc");
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont12"), is(true));
+ SingleInstanceNode cont12 = ((SingleInstanceNode) childNodes.get("cont12"));
+ assertThat(cont12.uri(), is("test-augment:cont13.cont12"));
+ assertThat(cont12.children().containsKey("leaf26"), is(true));
+ LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
+ assertThat(l.uri(), is("test-augment:cont13.cont12.leaf26"));
+
+ assertThat(childNodes.containsKey("list9"), is(true));
+ HolderNode list6Holder = ((ListHolderNode) childNodes.get("list9"));
+ assertThat(list6Holder.uri(), is("test-augment:cont13.list9"));
+ MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
+ assertThat(list6.uri(), is("test-augment:cont13.list9[0]"));
+ Map<String, DataNodeChild> list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf27"), is(true));
+ l = ((LeafNode) list6Child.get("leaf27"));
+ assertThat(l.uri(), is("test-augment:cont13.list9[0].leaf27"));
+
+ assertThat(childNodes.containsKey("leaf28"), is(true));
+ LeafNode leaf12 = ((LeafNode) childNodes.get("leaf28"));
+ assertThat(leaf12.name(), is("leaf28"));
+ assertThat(leaf12.uri(), is("test-augment:cont13.leaf28"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) childNodes.get("ll9"));
+ assertThat(ll5Holder.uri(), is("test-augment:cont13.ll9"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-augment:cont13.ll9[0]"));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testGrouping4() throws SvcLogicException {
+ String uri = "test-yang:cont1/cont2/cont4";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.cont12.leaf26", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0].leaf27", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.leaf28", "abc");
+ params.put("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9[0]", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
+ : node.augmentations().asMap().entrySet()) {
+ Collection<PropertiesNode> child = augToChild.getValue();
+ if (!child.isEmpty()) {
+ List<String> expectedNodes = new LinkedList<>();
+ expectedNodes.add("test-yang:cont1.cont2.cont4.test-augment:cont13");
+ assertThat(expectedNodes.size(), is(child.size()));
+ for (PropertiesNode pNode : child) {
+ assertThat(expectedNodes.contains(pNode.uri()), is(true));
+ SingleInstanceNode cont13 = ((SingleInstanceNode) pNode);
+ assertThat(cont13.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13"));
+ SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
+ assertThat(cont12.children().containsKey("leaf26"), is(true));
+ LeafNode l = ((LeafNode) cont12.children().get("leaf26"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.cont12.leaf26"));
+
+ assertThat(cont13.children().containsKey("list9"), is(true));
+ HolderNode list6Holder = ((ListHolderNode) cont13.children().get("list9"));
+ assertThat(list6Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9"));
+ MultiInstanceNode list6 = ((MultiInstanceNode) list6Holder.child("0"));
+ assertThat(list6.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0]"));
+ Map<String, DataNodeChild> list6Child = list6.children();
+ assertThat(list6Child.containsKey("leaf27"), is(true));
+ l = ((LeafNode) list6Child.get("leaf27"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.list9[0].leaf27"));
+
+ assertThat(cont13.children().containsKey("leaf28"), is(true));
+ LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
+ assertThat(leaf12.name(), is("leaf28"));
+ assertThat(leaf12.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.leaf28"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
+ assertThat(ll5Holder.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:cont1.cont2.cont4.test-augment:cont13.ll9[0]"));
+ }
+ }
+ }
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testRpcInput() throws SvcLogicException {
+ String uri = "test-yang:create-sfc";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:create-sfc.input.cont14.leaf28", "abc");
+ params.put("test-yang:create-sfc.input.list10[0].leaf29", "abc");
+ params.put("test-yang:create-sfc.input.leaf30", "abc");
+ params.put("test-yang:create-sfc.input.ll10[0]", "abc");
+ params.put("test-yang:create-sfc.input.cont15.leaf31", "abc");
+ params.put("test-yang:create-sfc.input.cont13.cont12.leaf26", "abc");
+ params.put("test-yang:create-sfc.input.cont13.list9[0].leaf27", "abc");
+ params.put("test-yang:create-sfc.input.cont13.leaf28", "abc");
+ params.put("test-yang:create-sfc.input.cont13.ll9[0]", "abc");
+ params.put("test-yang:create-sfc.input.test-augment:leaf36", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ PropertiesNode input = childNodes.get("input");
+ assertThat(input.uri(), is("test-yang:create-sfc.input"));
+ for (Map.Entry<Object, Collection<PropertiesNode>> augToChild
+ : node.augmentations().asMap().entrySet()) {
+ Collection<PropertiesNode> child = augToChild.getValue();
+ if (!child.isEmpty()) {
+ List<String> expectedNodes = new LinkedList<>();
+ expectedNodes.add("test-yang:create-sfc.input.test-augment:leaf36");
+ assertThat(expectedNodes.size(), is(child.size()));
+ for (PropertiesNode pNode : child) {
+ assertThat(expectedNodes.contains(pNode.uri()), is(true));
+ LeafNode leaf37 = ((LeafNode) pNode);
+ assertThat(leaf37.name(), is("leaf36"));
+ assertThat(leaf37.uri(), is("test-yang:create-sfc.input.test-augment:leaf36"));
+ }
+ }
+ }
+ childNodes = ((InnerNode) input).children();
+
+ assertThat(childNodes.containsKey("cont14"), is(true));
+ SingleInstanceNode cont14 = ((SingleInstanceNode) childNodes.get("cont14"));
+ assertThat(cont14.uri(), is("test-yang:create-sfc.input.cont14"));
+ assertThat(cont14.children().containsKey("leaf28"), is(true));
+ LeafNode l = ((LeafNode) cont14.children().get("leaf28"));
+ assertThat(l.uri(), is("test-yang:create-sfc.input.cont14.leaf28"));
+
+ assertThat(childNodes.containsKey("list10"), is(true));
+ HolderNode list10Holder = ((ListHolderNode) childNodes.get("list10"));
+ assertThat(list10Holder.uri(), is("test-yang:create-sfc.input.list10"));
+ MultiInstanceNode list10 = ((MultiInstanceNode) list10Holder.child("0"));
+ assertThat(list10.uri(), is("test-yang:create-sfc.input.list10[0]"));
+ Map<String, DataNodeChild> list10Child = list10.children();
+ assertThat(list10Child.containsKey("leaf29"), is(true));
+ l = ((LeafNode) list10Child.get("leaf29"));
+ assertThat(l.uri(), is("test-yang:create-sfc.input.list10[0].leaf29"));
+
+ assertThat(childNodes.containsKey("leaf30"), is(true));
+ LeafNode leaf30 = ((LeafNode) childNodes.get("leaf30"));
+ assertThat(leaf30.name(), is("leaf30"));
+ assertThat(leaf30.uri(), is("test-yang:create-sfc.input.leaf30"));
+
+ LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll10"));
+ assertThat(ll10Holder.uri(), is("test-yang:create-sfc.input.ll10"));
+ assertThat(ll10Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll10Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:create-sfc.input.ll10[0]"));
+
+ assertThat(childNodes.containsKey("cont15"), is(true));
+ SingleInstanceNode cont15 = ((SingleInstanceNode) childNodes.get("cont15"));
+ assertThat(cont15.uri(), is("test-yang:create-sfc.input.cont15"));
+ assertThat(cont15.children().containsKey("leaf31"), is(true));
+ l = ((LeafNode) cont15.children().get("leaf31"));
+ assertThat(l.uri(), is("test-yang:create-sfc.input.cont15.leaf31"));
+
+ assertThat(childNodes.containsKey("cont13"), is(true));
+ SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
+ assertThat(cont13.uri(), is("test-yang:create-sfc.input.cont13"));
+ SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
+ assertThat(cont12.uri(), is("test-yang:create-sfc.input.cont13.cont12"));
+ assertThat(cont12.children().containsKey("leaf26"), is(true));
+ l = ((LeafNode) cont12.children().get("leaf26"));
+ assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.cont12.leaf26"));
+
+ assertThat(cont13.children().containsKey("list9"), is(true));
+ HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
+ assertThat(list9Holder.uri(), is("test-yang:create-sfc.input.cont13.list9"));
+ MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
+ assertThat(list9.uri(), is("test-yang:create-sfc.input.cont13.list9[0]"));
+ Map<String, DataNodeChild> list6Child = list9.children();
+ assertThat(list6Child.containsKey("leaf27"), is(true));
+ l = ((LeafNode) list6Child.get("leaf27"));
+ assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.list9[0].leaf27"));
+
+ assertThat(cont13.children().containsKey("leaf28"), is(true));
+ LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
+ assertThat(leaf12.name(), is("leaf28"));
+ assertThat(leaf12.uri(), is("test-yang:create-sfc.input.cont13.leaf28"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
+ assertThat(ll5Holder.uri(), is("test-yang:create-sfc.input.cont13.ll9"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:create-sfc.input.cont13.ll9[0]"));
+
+ Map<String, String> output = ser.decode(node);
+ assertThat(output.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testRpcOutput() throws SvcLogicException {
+ String uri = "test-yang:create-sfc";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:create-sfc.output.cont16.leaf32", "abc");
+ params.put("test-yang:create-sfc.output.list11[0].leaf33", "abc");
+ params.put("test-yang:create-sfc.output.leaf34", "abc");
+ params.put("test-yang:create-sfc.output.ll11[0]", "abc");
+ params.put("test-yang:create-sfc.output.cont17.leaf35", "abc");
+ params.put("test-yang:create-sfc.output.cont13.cont12.leaf26", "abc");
+ params.put("test-yang:create-sfc.output.cont13.list9[0].leaf27", "abc");
+ params.put("test-yang:create-sfc.output.cont13.leaf28", "abc");
+ params.put("test-yang:create-sfc.output.cont13.ll9[0]", "abc");
+ params.put("test-yang:create-sfc.output.test-augment:leaf37", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ PropertiesNode output = childNodes.get("output");
+ assertThat(output.uri(), is("test-yang:create-sfc.output"));
+ for (Map.Entry<Object, Collection<PropertiesNode>> augmentationToChild :
+ node.augmentations().asMap().entrySet()) {
+ Collection<PropertiesNode> c = augmentationToChild.getValue();
+ if(!c.isEmpty()) {
+ List<String> expectedNodes = new LinkedList<>();
+ expectedNodes.add("test-yang:create-sfc.output.test-augment:leaf37");
+ assertThat(expectedNodes.size(), is(expectedNodes));
+ for (PropertiesNode pNode : c) {
+ assertThat(expectedNodes.contains(pNode.uri()), is(true));
+ LeafNode leaf37 = ((LeafNode) pNode);
+ assertThat(leaf37.name(), is("leaf37"));
+ assertThat(leaf37.uri(), is("test-yang:create-sfc.output.test-augment:leaf37"));
+ }
+ }
+ }
+ childNodes = ((InnerNode) output).children();
+
+ assertThat(childNodes.containsKey("cont16"), is(true));
+ SingleInstanceNode cont16 = ((SingleInstanceNode) childNodes.get("cont16"));
+ assertThat(cont16.uri(), is("test-yang:create-sfc.output.cont16"));
+ assertThat(cont16.children().containsKey("leaf32"), is(true));
+ LeafNode l = ((LeafNode) cont16.children().get("leaf32"));
+ assertThat(l.uri(), is("test-yang:create-sfc.output.cont16.leaf32"));
+
+ assertThat(childNodes.containsKey("list11"), is(true));
+ HolderNode list11Holder = ((ListHolderNode) childNodes.get("list11"));
+ assertThat(list11Holder.uri(), is("test-yang:create-sfc.output.list11"));
+ MultiInstanceNode list11 = ((MultiInstanceNode) list11Holder.child("0"));
+ assertThat(list11.uri(), is("test-yang:create-sfc.output.list11[0]"));
+ Map<String, DataNodeChild> list11Child = list11.children();
+ assertThat(list11Child.containsKey("leaf33"), is(true));
+ l = ((LeafNode) list11Child.get("leaf33"));
+ assertThat(l.uri(), is("test-yang:create-sfc.output.list11[0].leaf33"));
+
+ assertThat(childNodes.containsKey("leaf34"), is(true));
+ LeafNode leaf34 = ((LeafNode) childNodes.get("leaf34"));
+ assertThat(leaf34.name(), is("leaf34"));
+ assertThat(leaf34.uri(), is("test-yang:create-sfc.output.leaf34"));
+
+ LeafListHolderNode ll10Holder = ((LeafListHolderNode) childNodes.get("ll11"));
+ assertThat(ll10Holder.uri(), is("test-yang:create-sfc.output.ll11"));
+ assertThat(ll10Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll10Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:create-sfc.output.ll11[0]"));
+
+ assertThat(childNodes.containsKey("cont17"), is(true));
+ SingleInstanceNode cont17 = ((SingleInstanceNode) childNodes.get("cont17"));
+ assertThat(cont17.uri(), is("test-yang:create-sfc.output.cont17"));
+ assertThat(cont17.children().containsKey("leaf35"), is(true));
+ l = ((LeafNode) cont17.children().get("leaf35"));
+ assertThat(l.uri(), is("test-yang:create-sfc.output.cont17.leaf35"));
+
+ assertThat(childNodes.containsKey("cont13"), is(true));
+ SingleInstanceNode cont13 = ((SingleInstanceNode) childNodes.get("cont13"));
+ assertThat(cont13.uri(), is("test-yang:create-sfc.output.cont13"));
+ SingleInstanceNode cont12 = ((SingleInstanceNode) cont13.children().get("cont12"));
+ assertThat(cont12.uri(), is("test-yang:create-sfc.output.cont13.cont12"));
+ assertThat(cont12.children().containsKey("leaf26"), is(true));
+ l = ((LeafNode) cont12.children().get("leaf26"));
+ assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.cont12.leaf26"));
+
+ assertThat(cont13.children().containsKey("list9"), is(true));
+ HolderNode list9Holder = ((ListHolderNode) cont13.children().get("list9"));
+ assertThat(list9Holder.uri(), is("test-yang:create-sfc.output.cont13.list9"));
+ MultiInstanceNode list9 = ((MultiInstanceNode) list9Holder.child("0"));
+ assertThat(list9.uri(), is("test-yang:create-sfc.output.cont13.list9[0]"));
+ Map<String, DataNodeChild> list6Child = list9.children();
+ assertThat(list6Child.containsKey("leaf27"), is(true));
+ l = ((LeafNode) list6Child.get("leaf27"));
+ assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.list9[0].leaf27"));
+
+ assertThat(cont13.children().containsKey("leaf28"), is(true));
+ LeafNode leaf12 = ((LeafNode) cont13.children().get("leaf28"));
+ assertThat(leaf12.name(), is("leaf28"));
+ assertThat(leaf12.uri(), is("test-yang:create-sfc.output.cont13.leaf28"));
+
+ LeafListHolderNode ll5Holder = ((LeafListHolderNode) cont13.children().get("ll9"));
+ assertThat(ll5Holder.uri(), is("test-yang:create-sfc.output.cont13.ll9"));
+ assertThat(ll5Holder.children().containsKey("0"), is(true));
+ l = ((LeafNode) ll5Holder.children().get("0"));
+ assertThat(l.uri(), is("test-yang:create-sfc.output.cont13.ll9[0]"));
+
+ Map<String, String> output1 = ser.decode(node);
+ assertThat(output1.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output1.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testContainerSameName() throws SvcLogicException {
+ String uri = "test-yang:cont18";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont18.cont18.list12[0].list12[0].leaf36", "abc");
+ params.put("test-yang:cont18.cont18.list12[0].leaf36", "hi");
+ params.put("test-yang:cont18.cont18.list12[1].list12[0].leaf36", "xyz");
+ params.put("test-yang:cont18.cont18.list12[1].list12[1].leaf36", "hey!");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+
+ assertThat(childNodes.containsKey("cont18"), is(true));
+ node = childNodes.get("cont18");
+ assertThat(node.uri(), is("test-yang:cont18.cont18"));
+ childNodes = ((InnerNode) node).children();
+
+ assertThat(childNodes.containsKey("list12"), is(true));
+ HolderNode holder = ((ListHolderNode) childNodes.get("list12"));
+ assertThat(holder.uri(), is("test-yang:cont18.cont18.list12"));
+ MultiInstanceNode node1 = ((MultiInstanceNode) holder.child("0"));
+ assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0]"));
+ Map<String, DataNodeChild> list12Child = node1.children();
+
+ assertThat(list12Child.containsKey("leaf36"), is(true));
+ LeafNode leaf = ((LeafNode) list12Child.get("leaf36"));
+ assertThat(leaf.value(), is("hi"));
+ assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].leaf36"));
+
+ assertThat(list12Child.containsKey("list12"), is(true));
+ HolderNode holder1 = ((ListHolderNode) list12Child.get("list12"));
+ assertThat(holder1.uri(), is("test-yang:cont18.cont18.list12[0].list12"));
+ node1 = ((MultiInstanceNode) holder1.child("0"));
+ assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[0].list12[0]"));
+ list12Child = node1.children();
+ assertThat(list12Child.containsKey("leaf36"), is(true));
+ leaf = ((LeafNode) list12Child.get("leaf36"));
+ assertThat(leaf.value(), is("abc"));
+ assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[0].list12[0].leaf36"));
+
+ node1 = ((MultiInstanceNode) holder.child("1"));
+ assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1]"));
+ list12Child = node1.children();
+ assertThat(list12Child.containsKey("list12"), is(true));
+ holder = ((ListHolderNode) list12Child.get("list12"));
+ assertThat(holder.uri(), is("test-yang:cont18.cont18.list12[1].list12"));
+ node1 = ((MultiInstanceNode) holder.child("0"));
+ assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[0]"));
+ assertThat(node1.children().containsKey("leaf36"), is(true));
+ leaf = ((LeafNode) node1.children().get("leaf36"));
+ assertThat(leaf.value(), is("xyz"));
+ assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[0].leaf36"));
+
+ node1 = ((MultiInstanceNode) holder.child("1"));
+ assertThat(node1.uri(), is("test-yang:cont18.cont18.list12[1].list12[1]"));
+ assertThat(node1.children().containsKey("leaf36"), is(true));
+ leaf = ((LeafNode) node1.children().get("leaf36"));
+ assertThat(leaf.value(), is("hey!"));
+ assertThat(leaf.uri(), is("test-yang:cont18.cont18.list12[1].list12[1].leaf36"));
+
+ Map<String, String> output1 = ser.decode(node);
+ assertThat(output1.size(), is(params.size()));
+ for (Map.Entry<String, String> entry : output1.entrySet()) {
+ assertTrue(params.containsKey(entry.getKey()));
+ }
+ }
+
+ @Test
+ public void testPropertiesWithoutSchema() throws SvcLogicException {
+ String uri = "test-yang:cont18";
+ Map<String, String> params = new HashMap<>();
+ params.put("test-yang:cont18.leaf40", "abc");
+ params.put("leaf41", "hi");
+ params.put("test-yang:cont18.leaf41", "abc");
+
+ InstanceIdentifierContext<?> iCtx = ParserIdentifier
+ .toInstanceIdentifier(uri, context, null);
+ PropertiesNodeSerializer ser = new MdsalPropertiesNodeSerializer(
+ iCtx.getSchemaNode(), context, uri);
+ PropertiesNode node = ser.encode(params);
+
+ Map<String, PropertiesNode> childNodes = ((RootNode) node).children();
+ assertThat(childNodes.containsKey("leaf40"), is(true));
+ node = childNodes.get("leaf40");
+ assertThat(node.uri(), is("test-yang:cont18.leaf40"));
+ }
+
+ public static SchemaContext compileYangFile() throws FileNotFoundException {
+ String path = PropertiesSerializerTest.class.getResource("/yang").getPath();
+ File dir = new File(path);
+ String[] fileList = dir.list();
+ List<File> yangFiles = new ArrayList<File>();
+ if (fileList == null) {
+ throw new FileNotFoundException("/yang");
+ }
+ for (int i = 0; i < fileList.length; i++) {
+ final String fileName = fileList[i];
+ if (new File(dir, fileName).isDirectory() == false) {
+ yangFiles.add(new File(dir, fileName));
+ }
+ }
+ return YangParserTestUtils.parseYangFiles(yangFiles);
+ }
+} \ No newline at end of file
diff --git a/restconf-client/provider/src/test/resources/yang/test-augment.yang b/restconf-client/provider/src/test/resources/yang/test-augment.yang
new file mode 100644
index 00000000..bac19171
--- /dev/null
+++ b/restconf-client/provider/src/test/resources/yang/test-augment.yang
@@ -0,0 +1,85 @@
+module test-augment {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:augment";
+ prefix "hello";
+
+ import test-yang {
+ prefix t;
+ }
+
+ revision "2015-01-05" {
+ description "Initial revision of hello model";
+ }
+
+ augment "/t:cont1/t:cont2/t:cont4" {
+ container cont5 {
+ leaf leaf13 {
+ type string;
+ }
+ }
+ list list7 {
+ leaf leaf14 {
+ type string;
+ }
+ }
+ leaf leaf15 {
+ type string;
+ }
+ leaf-list ll6 {
+ type string;
+ }
+ uses "t:g1";
+ }
+
+ uses "t:g1";
+ augment "/t:ch1/t:c1/t:cont8/t:cont6" {
+ choice ch2 {
+ case c3 {
+ leaf leaf21 {
+ type string;
+ }
+ }
+ case c4 {
+ leaf leaf22 {
+ type string;
+ }
+ }
+ }
+ }
+
+ augment "/t:ch1" {
+ case c5 {
+ container cont10 {
+ leaf leaf23 {
+ type string;
+ }
+ }
+ }
+ }
+
+ augment "/t:ch1/t:c1" {
+ container cont7 {
+ leaf leaf24 {
+ type string;
+ }
+ }
+ }
+
+ augment "/t:cont13/t:cont12" {
+ leaf leaf29 {
+ type string;
+ }
+ }
+
+ augment "/t:create-sfc/t:input" {
+ leaf leaf36 {
+ type string;
+ }
+ }
+
+ augment "/t:create-sfc/t:output" {
+ leaf leaf37 {
+ type string;
+ }
+ }
+} \ No newline at end of file
diff --git a/restconf-client/provider/src/test/resources/yang/test-yang.yang b/restconf-client/provider/src/test/resources/yang/test-yang.yang
new file mode 100644
index 00000000..e99d87bf
--- /dev/null
+++ b/restconf-client/provider/src/test/resources/yang/test-yang.yang
@@ -0,0 +1,231 @@
+module test-yang {
+ yang-version 1;
+ namespace "urn:opendaylight:params:xml:ns:yang:test";
+ prefix "hello";
+
+ revision "2015-01-05" {
+ description "Initial revision of hello model";
+ }
+
+ container cont1 {
+ container cont2 {
+ container cont3 {
+ leaf leaf10 {
+ type string;
+ }
+ }
+ list list1 {
+ key "leaf1 leaf2";
+ leaf leaf1 {
+ type string;
+ }
+ leaf leaf2 {
+ type string;
+ }
+ leaf leaf3 {
+ type string;
+ }
+ leaf-list ll1 {
+ type string;
+ }
+ leaf-list ll2 {
+ type string;
+ }
+ container cont4 {
+ leaf leaf11 {
+ type string;
+ }
+ }
+ list list4 {
+ leaf leaf8 {
+ type string;
+ }
+ }
+ list list5 {
+ leaf leaf9 {
+ type string;
+ }
+ }
+ }
+ list list2 {
+ leaf leaf4 {
+ type string;
+ }
+ }
+ leaf leaf5 {
+ type string;
+ }
+ leaf leaf6 {
+ type string;
+ }
+ leaf-list ll3 {
+ type string;
+ }
+ leaf-list ll4 {
+ type string;
+ }
+ }
+ }
+
+ augment "/cont1/cont2" {
+ container cont4 {
+ leaf leaf10 {
+ type string;
+ }
+ }
+ list list6 {
+ leaf leaf11 {
+ type string;
+ }
+ }
+ leaf leaf12 {
+ type string;
+ }
+ leaf-list ll5 {
+ type string;
+ }
+ }
+
+ choice ch1 {
+ case c1 {
+ container cont8 {
+ container cont6 {
+ leaf leaf16 {
+ type string;
+ }
+ }
+ list list8 {
+ leaf leaf18 {
+ type string;
+ }
+ }
+ leaf leaf19 {
+ type string;
+ }
+ leaf-list ll7 {
+ type string;
+ }
+ }
+ }
+ case c2 {
+ container cont9 {
+ leaf leaf20 {
+ type string;
+ }
+ leaf-list ll8 {
+ type string;
+ }
+ container cont11 {
+ choice ch3 {
+ case c1 {
+ leaf leaf25 {
+ type string;
+ }
+ uses g1;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ grouping g1 {
+ container cont13 {
+ container cont12 {
+ leaf leaf26 {
+ type string;
+ }
+ }
+ list list9 {
+ leaf leaf27 {
+ type string;
+ }
+ }
+ leaf leaf28 {
+ type string;
+ }
+ leaf-list ll9 {
+ type string;
+ }
+ }
+ }
+
+ uses g1;
+
+ rpc create-sfc {
+ input {
+ container cont14 {
+ leaf leaf28 {
+ type string;
+ }
+ }
+ list list10 {
+ leaf leaf29 {
+ type string;
+ }
+ }
+ leaf leaf30 {
+ type string;
+ }
+ leaf-list ll10 {
+ type string;
+ }
+ choice ch3 {
+ case c1 {
+ container cont15 {
+ leaf leaf31 {
+ type string;
+ }
+ }
+ }
+ }
+ uses g1;
+ }
+ output {
+ container cont16 {
+ leaf leaf32 {
+ type string;
+ }
+ }
+ list list11 {
+ leaf leaf33 {
+ type string;
+ }
+ }
+ leaf leaf34 {
+ type string;
+ }
+ leaf-list ll11 {
+ type string;
+ }
+ choice ch4 {
+ case c1 {
+ container cont17 {
+ leaf leaf35 {
+ type string;
+ }
+ }
+ }
+ }
+ uses g1;
+ }
+ }
+
+ container cont18 {
+ container cont18 {
+ list list12 {
+ list list12 {
+ leaf leaf36 {
+ type string;
+ }
+ }
+ leaf leaf36 {
+ type string;
+ }
+ }
+ }
+ leaf leaf40 {
+ type string;
+ }
+ }
+} \ No newline at end of file