AnyData feature changes
Change-Id: Iccba22d731321f38b8146bbfc85477d2252a3b10
diff --git a/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java b/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
index be241ed..b3f7dda 100644
--- a/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
+++ b/serializers/xml/src/test/java/org/onosproject/yang/serializers/xml/XmlSerializerTest.java
@@ -59,6 +59,8 @@
private static YangSerializerContext context;
private static YangSerializer xmlSerializer;
+ public static final String LNS = "yrt:list.anydata";
+
@BeforeClass
public static void prepare() {
context = new MockYangSerializerContext();
@@ -526,4 +528,62 @@
}
return newCompBuilder.build();
}
+
+ /**
+ * Validates data node in which XML element is of type YANG anydata.
+ */
+ @Test
+ public void testListWithAnydata() {
+ String path = "src/test/resources/testListAnydata.xml";
+ DefaultCompositeStream external =
+ new DefaultCompositeStream(null, parseInput(path));
+ CompositeData compositeData = xmlSerializer.decode(external, context);
+ DataNode rootNode = validateRootDataNode(compositeData.resourceData());
+ List<String> keyNames = new LinkedList<>();
+ keyNames.add("k1");
+ keyNames.add("k2");
+ keyNames.add("k3");
+
+ List<String> keyNs = new LinkedList<>();
+ keyNs.add(LNS);
+ keyNs.add(LNS);
+ keyNs.add(LNS);
+
+ List<Object> values = new LinkedList<>();
+ values.add("k1_Value");
+ values.add("k2_Value");
+ values.add("k3_Value");
+
+ DataNode listl1 = validateListDataNode(rootNode, "l1", LNS,
+ keyNames, keyNs, values);
+ validateLeafDataNode(listl1, "k1", LNS, "k1_Value");
+ validateLeafDataNode(listl1, "k2", LNS, "k2_Value");
+ validateLeafDataNode(listl1, "k3", LNS, "k3_Value");
+ DataNode c1 = validateContainerDataNode(listl1, "c1", LNS);
+ DataNode mydata = validateContainerDataNode(c1, "mydata", LNS);
+ validateLeafDataNode(c1, "leaf_c1", LNS, "l1_value");
+
+ values = new LinkedList<>();
+ values.add("k1_Value1");
+ values.add("k2_Value2");
+ values.add("k3_Value3");
+
+ DataNode listl2 = validateListDataNode(rootNode, "l1", LNS,
+ keyNames, keyNs, values);
+ validateLeafDataNode(listl2, "k1", LNS, "k1_Value1");
+ validateLeafDataNode(listl2, "k2", LNS, "k2_Value2");
+ validateLeafDataNode(listl2, "k3", LNS, "k3_Value3");
+ c1 = validateContainerDataNode(listl2, "c1", LNS);
+ mydata = validateContainerDataNode(c1, "mydata", LNS);
+ validateLeafDataNode(c1, "leaf_c1", LNS, "l1_value1");
+
+ // validate module level anydata
+ validateContainerDataNode(rootNode, "mydata", LNS);
+
+ // encode test
+ CompositeStream compositeStream = xmlSerializer.encode(
+ getNewCompositeData(compositeData), context);
+ InputStream inputStream = compositeStream.resourceData();
+ assertThat(convertInputStreamToString(inputStream), is(parseXml(path)));
+ }
}
diff --git a/serializers/xml/src/test/resources/listAnydata.yang b/serializers/xml/src/test/resources/listAnydata.yang
new file mode 100644
index 0000000..b1b3d0b
--- /dev/null
+++ b/serializers/xml/src/test/resources/listAnydata.yang
@@ -0,0 +1,51 @@
+module listAnydata {
+
+ yang-version 1.1;
+
+ namespace "yrt:list.anydata";
+
+ prefix "l";
+
+ organization "ON-LAB";
+
+ description "This module defines for list.";
+
+ revision "2016-06-24" {
+ description "Initial revision.";
+ }
+
+ anydata mydata {
+ }
+
+ list l1 {
+ key "k1 k2 k3";
+ leaf k1 {
+ type string;
+ }
+
+ leaf k2 {
+ type string;
+ }
+
+ leaf k3 {
+ type string;
+ }
+
+ container c1 {
+ leaf leaf_c1 {
+ type string;
+ }
+ }
+ anydata mydata {
+ }
+ }
+
+ leaf-list leaf1 {
+ type string;
+ }
+
+ augment "/l:l1/l:c1/" {
+ anydata mydata {
+ }
+ }
+}
\ No newline at end of file
diff --git a/serializers/xml/src/test/resources/testListAnydata.xml b/serializers/xml/src/test/resources/testListAnydata.xml
new file mode 100644
index 0000000..8696d92
--- /dev/null
+++ b/serializers/xml/src/test/resources/testListAnydata.xml
@@ -0,0 +1,22 @@
+<l1 xmlns="yrt:list.anydata" operation="replace">
+<k1>k1_Value</k1>
+<k2>k2_Value</k2>
+<k3>k3_Value</k3>
+<c1>
+<mydata/>
+<leaf_c1>l1_value</leaf_c1>
+</c1>
+<mydata/>
+</l1>
+<l1 xmlns="yrt:list.anydata" operation="replace">
+<k1>k1_Value1</k1>
+<k2>k2_Value2</k2>
+<k3>k3_Value3</k3>
+<c1>
+<mydata/>
+<leaf_c1>l1_value1</leaf_c1>
+</c1>
+<mydata/>
+</l1>
+<mydata xmlns="yrt:list.anydata" operation="replace">
+</mydata>
\ No newline at end of file