--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "top": {
+ "foo": "/example-foomod:top/foo-list[name='key-value']/example-barmod:bar-container/bar-leaf"
+ }
+}
\ No newline at end of file
--- /dev/null
+{
+ "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
--- /dev/null
+{
+ "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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+/*
+ * 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);
+ }
+}
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+<?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
--- /dev/null
+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
--- /dev/null
+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
--- /dev/null
+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