Bug 8083: Preliminary unit tests 06/54106/4
authorIgor Foltin <ifoltin@cisco.com>
Thu, 30 Mar 2017 13:43:06 +0000 (15:43 +0200)
committerRobert Varga <nite@hq.sk>
Thu, 18 May 2017 09:03:54 +0000 (09:03 +0000)
A bunch of unit tests which were used
for the purpose of investigation of this bug

Change-Id: I393d3fba5a0046173c1da4993f3dbd40acddd833
Signed-off-by: Igor Foltin <ifoltin@cisco.com>
17 files changed:
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/json/baz.json [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/json/foo.json [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/json/foobar.json [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/json/zab.json [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/yang/bar.yang [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/yang/baz.yang [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foo.yang [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foobar.yang [new file with mode: 0644]
yang/yang-data-codec-gson/src/test/resources/bug8083/yang/zab.yang [new file with mode: 0644]
yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java [new file with mode: 0644]
yang/yang-data-codec-xml/src/test/resources/bug8083/xml/baz.xml [new file with mode: 0644]
yang/yang-data-codec-xml/src/test/resources/bug8083/xml/foobar.xml [new file with mode: 0644]
yang/yang-data-codec-xml/src/test/resources/bug8083/xml/zab.xml [new file with mode: 0644]
yang/yang-data-codec-xml/src/test/resources/bug8083/yang/baz.yang [new file with mode: 0644]
yang/yang-data-codec-xml/src/test/resources/bug8083/yang/foobar.yang [new file with mode: 0644]
yang/yang-data-codec-xml/src/test/resources/bug8083/yang/zab.yang [new file with mode: 0644]

diff --git a/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java
new file mode 100644 (file)
index 0000000..618dca1
--- /dev/null
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yangtools.yang.data.codec.gson;
+
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadTextFile;
+
+import com.google.gson.stream.JsonReader;
+import java.io.StringReader;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Bug8083Test {
+
+    @Ignore("Instance-identifier codec has to be modified according to the RFC7951 to correctly parse this.")
+    @Test
+    public void testRFC7951InstanceIdentifierPath() throws Exception {
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSources("/bug8083/yang/");
+        final String inputJson = loadTextFile("/bug8083/json/foo.json");
+
+        // deserialization
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext);
+        jsonParser.parse(new JsonReader(new StringReader(inputJson)));
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+
+    @Ignore("JSONEmptyCodec needs to be fixed first.")
+    @Test
+    public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/baz.yang");
+        final String inputJson = loadTextFile("/bug8083/json/baz.json");
+
+        // deserialization
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext);
+        jsonParser.parse(new JsonReader(new StringReader(inputJson)));
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+
+    @Test
+    public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/zab.yang");
+        final String inputJson = loadTextFile("/bug8083/json/zab.json");
+
+        // deserialization
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext);
+        jsonParser.parse(new JsonReader(new StringReader(inputJson)));
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+
+    @Test
+    public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception {
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/foobar.yang");
+        final String inputJson = loadTextFile("/bug8083/json/foobar.json");
+
+        // deserialization
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final JsonParserStream jsonParser = JsonParserStream.create(streamWriter, schemaContext);
+        jsonParser.parse(new JsonReader(new StringReader(inputJson)));
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+}
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/json/baz.json b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/baz.json
new file mode 100644 (file)
index 0000000..177a07a
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "top-cont": {
+    "keyed-list":[
+      {
+        "empty-key-leaf": [null],
+        "regular-leaf": 150
+      }
+    ],
+
+    "iid-leaf": "/baz:top-cont/baz:keyed-list[baz:empty-key-leaf='[null]']/baz:regular-leaf"
+  }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/json/foo.json b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/foo.json
new file mode 100644 (file)
index 0000000..3c6a525
--- /dev/null
@@ -0,0 +1,5 @@
+{
+  "top": {
+    "foo": "/example-foomod:top/foo-list[name='key-value']/example-barmod:bar-container/bar-leaf"
+  }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/json/foobar.json b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/foobar.json
new file mode 100644 (file)
index 0000000..f8a0d0d
--- /dev/null
@@ -0,0 +1,14 @@
+{
+  "top-cont": {
+    "keyed-list":[
+      {
+        "iid-key-leaf": "/foobar:top-cont/foobar:leaf-b",
+        "regular-leaf": 150
+      }
+    ],
+
+    "iid-leaf":
+      "/foobar:top-cont/foobar:keyed-list[foobar:iid-key-leaf='/foobar:top-cont/foobar:leaf-b']/foobar:regular-leaf",
+    "leaf-b": 200
+  }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/json/zab.json b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/zab.json
new file mode 100644 (file)
index 0000000..3016a8b
--- /dev/null
@@ -0,0 +1,12 @@
+{
+  "top-cont": {
+    "keyed-list":[
+      {
+        "identityref-key-leaf": "derived-id",
+        "regular-leaf": 150
+      }
+    ],
+
+    "iid-leaf": "/zab:top-cont/zab:keyed-list[zab:identityref-key-leaf='derived-id']/zab:regular-leaf"
+  }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/bar.yang b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/bar.yang
new file mode 100644 (file)
index 0000000..7e6ad76
--- /dev/null
@@ -0,0 +1,17 @@
+module example-barmod {
+
+    namespace "http://example.com/barmod";
+    prefix "barmod";
+
+    import example-foomod {
+        prefix "foomod";
+    }
+
+    augment "/foomod:top/foomod:foo-list" {
+        container bar-container {
+            leaf bar-leaf {
+                type string;
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/baz.yang b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/baz.yang
new file mode 100644 (file)
index 0000000..0690b1f
--- /dev/null
@@ -0,0 +1,23 @@
+module baz {
+
+    namespace baz-ns;
+    prefix baz-prefix;
+
+    container top-cont {
+        list keyed-list {
+            key empty-key-leaf;
+
+            leaf empty-key-leaf {
+                type empty;
+            }
+
+            leaf regular-leaf {
+                type int32;
+            }
+        }
+
+        leaf iid-leaf {
+            type instance-identifier;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foo.yang b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foo.yang
new file mode 100644 (file)
index 0000000..478bfc7
--- /dev/null
@@ -0,0 +1,19 @@
+module example-foomod {
+
+    namespace "http://example.com/foomod";
+    prefix "foomod";
+
+    container top {
+        leaf foo {
+            type instance-identifier;
+        }
+
+        list foo-list {
+            key name;
+
+            leaf name {
+                type string;
+            }
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foobar.yang b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foobar.yang
new file mode 100644 (file)
index 0000000..ec42bab
--- /dev/null
@@ -0,0 +1,27 @@
+module foobar {
+
+    namespace foobar-ns;
+    prefix foobar-prefix;
+
+    container top-cont {
+        list keyed-list {
+            key iid-key-leaf;
+
+            leaf iid-key-leaf {
+                type instance-identifier;
+            }
+
+            leaf regular-leaf {
+                type int32;
+            }
+        }
+
+        leaf iid-leaf {
+            type instance-identifier;
+        }
+
+        leaf leaf-b {
+            type int32;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/zab.yang b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/zab.yang
new file mode 100644 (file)
index 0000000..5af9529
--- /dev/null
@@ -0,0 +1,31 @@
+module zab {
+
+    namespace zab-ns;
+    prefix zab-prefix;
+
+    identity base-id;
+
+    identity derived-id {
+        base base-id;
+    }
+
+    container top-cont {
+        list keyed-list {
+            key identityref-key-leaf;
+
+            leaf identityref-key-leaf {
+                type identityref {
+                    base base-id;
+                }
+            }
+
+            leaf regular-leaf {
+                type int32;
+            }
+        }
+
+        leaf iid-leaf {
+            type instance-identifier;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java
new file mode 100644 (file)
index 0000000..48c14b7
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yangtools.yang.data.codec.xml;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNormalizedNodeStreamWriter;
+import org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+
+public class Bug8083Test {
+
+    @Ignore("XMLEmptyCodec needs to be fixed first.")
+    @Test
+    public void testInstanceIdentifierPathWithEmptyListKey() throws Exception {
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/baz.yang");
+        final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/baz.xml");
+
+        final XMLInputFactory factory = XMLInputFactory.newInstance();
+        final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+
+        // deserialization
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext);
+        xmlParser.parse(reader);
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+
+    @Test
+    public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception {
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/zab.yang");
+        final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/zab.xml");
+
+        final XMLInputFactory factory = XMLInputFactory.newInstance();
+        final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+
+        // deserialization
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext);
+        xmlParser.parse(reader);
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+
+    @Test
+    public void testInstanceIdentifierPathWithInstanceIdentifierListKey() throws Exception {
+        final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/bug8083/yang/foobar.yang");
+        final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/foobar.xml");
+
+        final XMLInputFactory factory = XMLInputFactory.newInstance();
+        final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
+
+        // deserialization
+        final NormalizedNodeResult result = new NormalizedNodeResult();
+        final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
+        final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext);
+        xmlParser.parse(reader);
+        final NormalizedNode<?, ?> transformedInput = result.getResult();
+        assertNotNull(transformedInput);
+    }
+}
diff --git a/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/baz.xml b/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/baz.xml
new file mode 100644 (file)
index 0000000..43f669b
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root xmlns="baz-ns">
+    <top-cont>
+        <keyed-list>
+            <empty-key-leaf/>
+            <regular-leaf>150</regular-leaf>
+        </keyed-list>
+
+        <iid-leaf xmlns:baz="baz-ns">/baz:top-cont/baz:keyed-list[baz:empty-key-leaf='']/baz:regular-leaf</iid-leaf>
+    </top-cont>
+</root>
\ No newline at end of file
diff --git a/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/foobar.xml b/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/foobar.xml
new file mode 100644 (file)
index 0000000..352c0af
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root xmlns="foobar-ns">
+    <top-cont>
+        <keyed-list>
+            <iid-key-leaf xmlns:foobar="foobar-ns">/foobar:top-cont/foobar:leaf-b</iid-key-leaf>
+            <regular-leaf>150</regular-leaf>
+        </keyed-list>
+
+        <iid-leaf xmlns:foobar="foobar-ns">
+            /foobar:top-cont/foobar:keyed-list[foobar:iid-key-leaf='/foobar:top-cont/foobar:leaf-b']/foobar:regular-leaf</iid-leaf>
+        <leaf-b>50</leaf-b>
+    </top-cont>
+</root>
\ No newline at end of file
diff --git a/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/zab.xml b/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/zab.xml
new file mode 100644 (file)
index 0000000..1b4de0d
--- /dev/null
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root xmlns="zab-ns">
+    <top-cont>
+        <keyed-list>
+            <identityref-key-leaf>derived-id</identityref-key-leaf>
+            <regular-leaf>150</regular-leaf>
+        </keyed-list>
+
+        <iid-leaf xmlns:zab="zab-ns">
+            /zab:top-cont/zab:keyed-list[zab:identityref-key-leaf='derived-id']/zab:regular-leaf</iid-leaf>
+    </top-cont>
+</root>
\ No newline at end of file
diff --git a/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/baz.yang b/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/baz.yang
new file mode 100644 (file)
index 0000000..0690b1f
--- /dev/null
@@ -0,0 +1,23 @@
+module baz {
+
+    namespace baz-ns;
+    prefix baz-prefix;
+
+    container top-cont {
+        list keyed-list {
+            key empty-key-leaf;
+
+            leaf empty-key-leaf {
+                type empty;
+            }
+
+            leaf regular-leaf {
+                type int32;
+            }
+        }
+
+        leaf iid-leaf {
+            type instance-identifier;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/foobar.yang b/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/foobar.yang
new file mode 100644 (file)
index 0000000..ec42bab
--- /dev/null
@@ -0,0 +1,27 @@
+module foobar {
+
+    namespace foobar-ns;
+    prefix foobar-prefix;
+
+    container top-cont {
+        list keyed-list {
+            key iid-key-leaf;
+
+            leaf iid-key-leaf {
+                type instance-identifier;
+            }
+
+            leaf regular-leaf {
+                type int32;
+            }
+        }
+
+        leaf iid-leaf {
+            type instance-identifier;
+        }
+
+        leaf leaf-b {
+            type int32;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/zab.yang b/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/zab.yang
new file mode 100644 (file)
index 0000000..5af9529
--- /dev/null
@@ -0,0 +1,31 @@
+module zab {
+
+    namespace zab-ns;
+    prefix zab-prefix;
+
+    identity base-id;
+
+    identity derived-id {
+        base base-id;
+    }
+
+    container top-cont {
+        list keyed-list {
+            key identityref-key-leaf;
+
+            leaf identityref-key-leaf {
+                type identityref {
+                    base base-id;
+                }
+            }
+
+            leaf regular-leaf {
+                type int32;
+            }
+        }
+
+        leaf iid-leaf {
+            type instance-identifier;
+        }
+    }
+}
\ No newline at end of file