From 4f1692c802228d396f60fa2374646024781c1c12 Mon Sep 17 00:00:00 2001 From: Igor Foltin Date: Thu, 30 Mar 2017 15:43:06 +0200 Subject: [PATCH] Bug 8083: Preliminary unit tests A bunch of unit tests which were used for the purpose of investigation of this bug Change-Id: I393d3fba5a0046173c1da4993f3dbd40acddd833 Signed-off-by: Igor Foltin --- .../yang/data/codec/gson/Bug8083Test.java | 84 +++++++++++++++++++ .../src/test/resources/bug8083/json/baz.json | 12 +++ .../src/test/resources/bug8083/json/foo.json | 5 ++ .../test/resources/bug8083/json/foobar.json | 14 ++++ .../src/test/resources/bug8083/json/zab.json | 12 +++ .../src/test/resources/bug8083/yang/bar.yang | 17 ++++ .../src/test/resources/bug8083/yang/baz.yang | 23 +++++ .../src/test/resources/bug8083/yang/foo.yang | 19 +++++ .../test/resources/bug8083/yang/foobar.yang | 27 ++++++ .../src/test/resources/bug8083/yang/zab.yang | 31 +++++++ .../yang/data/codec/xml/Bug8083Test.java | 78 +++++++++++++++++ .../src/test/resources/bug8083/xml/baz.xml | 12 +++ .../src/test/resources/bug8083/xml/foobar.xml | 14 ++++ .../src/test/resources/bug8083/xml/zab.xml | 13 +++ .../src/test/resources/bug8083/yang/baz.yang | 23 +++++ .../test/resources/bug8083/yang/foobar.yang | 27 ++++++ .../src/test/resources/bug8083/yang/zab.yang | 31 +++++++ 17 files changed, 442 insertions(+) create mode 100644 yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/json/baz.json create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/json/foo.json create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/json/foobar.json create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/json/zab.json create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/yang/bar.yang create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/yang/baz.yang create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foo.yang create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foobar.yang create mode 100644 yang/yang-data-codec-gson/src/test/resources/bug8083/yang/zab.yang create mode 100644 yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java create mode 100644 yang/yang-data-codec-xml/src/test/resources/bug8083/xml/baz.xml create mode 100644 yang/yang-data-codec-xml/src/test/resources/bug8083/xml/foobar.xml create mode 100644 yang/yang-data-codec-xml/src/test/resources/bug8083/xml/zab.xml create mode 100644 yang/yang-data-codec-xml/src/test/resources/bug8083/yang/baz.yang create mode 100644 yang/yang-data-codec-xml/src/test/resources/bug8083/yang/foobar.yang create mode 100644 yang/yang-data-codec-xml/src/test/resources/bug8083/yang/zab.yang 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 index 0000000000..618dca1e55 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/Bug8083Test.java @@ -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 index 0000000000..177a07a65c --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/baz.json @@ -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 index 0000000000..3c6a525370 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/foo.json @@ -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 index 0000000000..f8a0d0d938 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/foobar.json @@ -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 index 0000000000..3016a8b824 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/json/zab.json @@ -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 index 0000000000..7e6ad769b2 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/bar.yang @@ -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 index 0000000000..0690b1fcd3 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/baz.yang @@ -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 index 0000000000..478bfc7177 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foo.yang @@ -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 index 0000000000..ec42babc83 --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/foobar.yang @@ -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 index 0000000000..5af952988a --- /dev/null +++ b/yang/yang-data-codec-gson/src/test/resources/bug8083/yang/zab.yang @@ -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 index 0000000000..48c14b7296 --- /dev/null +++ b/yang/yang-data-codec-xml/src/test/java/org/opendaylight/yangtools/yang/data/codec/xml/Bug8083Test.java @@ -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 index 0000000000..43f669b833 --- /dev/null +++ b/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/baz.xml @@ -0,0 +1,12 @@ + + + + + + + 150 + + + /baz:top-cont/baz:keyed-list[baz:empty-key-leaf='']/baz:regular-leaf + + \ 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 index 0000000000..352c0aff6c --- /dev/null +++ b/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/foobar.xml @@ -0,0 +1,14 @@ + + + + + + /foobar:top-cont/foobar:leaf-b + 150 + + + + /foobar:top-cont/foobar:keyed-list[foobar:iid-key-leaf='/foobar:top-cont/foobar:leaf-b']/foobar:regular-leaf + 50 + + \ 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 index 0000000000..1b4de0d58a --- /dev/null +++ b/yang/yang-data-codec-xml/src/test/resources/bug8083/xml/zab.xml @@ -0,0 +1,13 @@ + + + + + + derived-id + 150 + + + + /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-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 index 0000000000..0690b1fcd3 --- /dev/null +++ b/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/baz.yang @@ -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 index 0000000000..ec42babc83 --- /dev/null +++ b/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/foobar.yang @@ -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 index 0000000000..5af952988a --- /dev/null +++ b/yang/yang-data-codec-xml/src/test/resources/bug8083/yang/zab.yang @@ -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 -- 2.36.6