Bug 4798: Can not define a list as a subordinate 92/35392/4
authorFilip Gregor <fgregor@cisco.com>
Fri, 5 Feb 2016 14:12:07 +0000 (15:12 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 7 Mar 2016 12:23:36 +0000 (13:23 +0100)
added check for NodeIdentifierWithPredicates

Change-Id: If21b06a035232f04deda8369fb09b48d0fe45def
Signed-off-by: Filip Gregor <fgregor@cisco.com>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/ChoiceNodeCodecContext.java
binding/mdsal-binding-dom-codec/src/test/java/org/opendaylight/yangtools/binding/data/codec/test/NormalizedNodeSerializeDeserializeTest.java
binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java
binding/mdsal-binding-test-model/src/main/yang/opendaylight-bug-4798.yang [new file with mode: 0644]

index 47a783ac1edf485f9e48311473a907e7e97fbdfe..6e5bba69c70795150bc7a717396b8071576800da 100644 (file)
@@ -137,7 +137,13 @@ final class ChoiceNodeCodecContext<D extends DataObject> extends DataContainerCo
 
     @Override
     public NodeCodecContext<?> yangPathArgumentChild(final YangInstanceIdentifier.PathArgument arg) {
-        final DataContainerCodecPrototype<?> cazeProto = byYangCaseChild.get(arg);
+        final DataContainerCodecPrototype<?> cazeProto;
+        if (arg instanceof YangInstanceIdentifier.NodeIdentifierWithPredicates) {
+            cazeProto = byYangCaseChild.get(new NodeIdentifier(arg.getNodeType()));
+        } else {
+            cazeProto = byYangCaseChild.get(arg);
+        }
+
         childNonNull(cazeProto != null, arg,"Argument %s is not valid child of %s", arg, getSchema());
         return cazeProto.get().yangPathArgumentChild(arg);
     }
index 3a9ce5ae5d76ae3bf715ac9e707d3da1030b516b..efc5077877fa8b246bdca83cdc092af2c7d0cf3e 100644 (file)
@@ -8,6 +8,8 @@
 package org.opendaylight.yangtools.binding.data.codec.test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.top;
 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList;
 import static org.opendaylight.yangtools.yang.data.impl.schema.Builders.augmentationBuilder;
@@ -50,6 +52,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.te
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListKey;
+import org.opendaylight.yang.gen.v1.urn.test.foo4798.rev160101.Root;
 import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
 import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
 import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
@@ -67,6 +70,7 @@ import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableCo
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetEntryNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapEntryNodeBuilder;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedMapNodeBuilder;
 
@@ -274,6 +278,82 @@ public class NormalizedNodeSerializeDeserializeTest extends AbstractBindingRunti
         assertEquals(choiceContainer, entry.getValue());
     }
 
+    @Test
+    public void test4798() {
+        final QName containerIdentifierQname4798 = Root.QNAME;
+        final QName choiceIdentifierQname4798 = QName.create(containerIdentifierQname4798, "bug4798-choice");
+        final QName nestedListQname4798 = QName.create(containerIdentifierQname4798, "list-in-case");
+        final QName nestedListKeyQname4798 = QName.create(containerIdentifierQname4798, "test-leaf");
+        final QName nestedContainerValidQname = QName.create(containerIdentifierQname4798, "case-b-container");
+        final QName nestedContainerOuterQname = QName.create(containerIdentifierQname4798, "outer-container");
+        final QName nestedContainerLeafOuterQname = QName.create(containerIdentifierQname4798,
+                "leaf-in-outer-container");
+
+        final YangInstanceIdentifier yangInstanceIdentifierOuter = YangInstanceIdentifier.of(containerIdentifierQname4798);
+        final ContainerNode containerNodeOuter = ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerIdentifierQname4798))
+                .withChild(ImmutableContainerNodeBuilder.create()
+                        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(nestedContainerOuterQname))
+                        .withChild((leafNode(nestedContainerLeafOuterQname, "bar")))
+                        .build())
+                .build();
+        final Map.Entry<InstanceIdentifier<?>, DataObject> entryContainer = registry.fromNormalizedNode
+                 (yangInstanceIdentifierOuter, containerNodeOuter);
+        assertNotNull(entryContainer.getValue());
+        assertNotNull(entryContainer.getKey());
+
+        final YangInstanceIdentifier.NodeIdentifierWithPredicates nodeIdentifierWithPredicates4798 = new YangInstanceIdentifier
+                .NodeIdentifierWithPredicates( nestedListQname4798, nestedListKeyQname4798, "foo" );
+        final YangInstanceIdentifier yangInstanceIdentifier4798 = YangInstanceIdentifier.of(containerIdentifierQname4798)
+                .node(choiceIdentifierQname4798)
+                .node(nestedListQname4798)
+                .node(nodeIdentifierWithPredicates4798);
+
+        final YangInstanceIdentifier yangInstanceIdentifierValid = YangInstanceIdentifier.of(containerIdentifierQname4798)
+                .node(choiceIdentifierQname4798)
+                .node(nestedContainerValidQname)
+                .node(nestedListQname4798)
+                .node(nodeIdentifierWithPredicates4798);
+        final ContainerNode containerNodeValid = ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerIdentifierQname4798))
+                .withChild(ImmutableChoiceNodeBuilder.create()
+                        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(choiceIdentifierQname4798))
+                        .withChild(ImmutableContainerNodeBuilder.create()
+                                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(nestedContainerValidQname))
+                                .withChild(ImmutableMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier
+                                        .NodeIdentifier(nestedListQname4798))
+                                        .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "foo"))
+                                        .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "bar"))
+                                        .build())
+                                .build())
+                        .build())
+                .build();
+        try {
+            final Map.Entry<InstanceIdentifier<?>, DataObject> entryChoiceContainer = registry.fromNormalizedNode
+                    (yangInstanceIdentifierValid, containerNodeValid);
+            fail("Incorect YangInstanceIdentifier should fail");
+        } catch (IllegalStateException e) {
+        }
+
+        final ContainerNode containerNode4798 = ImmutableContainerNodeBuilder.create()
+                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerIdentifierQname4798))
+                .withChild(ImmutableChoiceNodeBuilder.create()
+                        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(choiceIdentifierQname4798))
+                        .withChild(ImmutableMapNodeBuilder.create().withNodeIdentifier(new YangInstanceIdentifier
+                                .NodeIdentifier(nestedListQname4798))
+                                .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "foo"))
+                                .withChild(mapEntry(nestedListQname4798, nestedListKeyQname4798, "bar"))
+                                .build())
+                        .build())
+                .build();
+        try {
+            final Map.Entry<InstanceIdentifier<?>, DataObject> entry4798 = registry.fromNormalizedNode
+                    (yangInstanceIdentifier4798, containerNode4798);
+            fail("Incorect YangInstanceIdentifier should fail");
+        } catch (IllegalStateException e) {
+        }
+    }
+
     @Test
     public void choiceFromNormalized() {
         final ContainerNode choiceContainerBI = ImmutableContainerNodeBuilder.create()
index 7d45f8f3e44855df84b677a700604123cbdff82d..d8701b5ef4abc31bc61d9567c6b6bee7c391b0c1 100644 (file)
@@ -27,6 +27,7 @@ import static org.opendaylight.yangtools.sal.java.api.generator.test.Compilation
 import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp;
 import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles;
 import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation;
+
 import com.google.common.base.Predicate;
 import com.google.common.collect.Collections2;
 import com.google.common.collect.ImmutableSet;
diff --git a/binding/mdsal-binding-test-model/src/main/yang/opendaylight-bug-4798.yang b/binding/mdsal-binding-test-model/src/main/yang/opendaylight-bug-4798.yang
new file mode 100644 (file)
index 0000000..ee082aa
--- /dev/null
@@ -0,0 +1,38 @@
+module opendaylight-bug-4798.yang {
+    namespace "urn:test:foo4798";
+    prefix foo;
+
+    revision 2016-01-01 {
+    }
+
+    container root {
+        choice bug4798-choice {
+            case case-a {
+                list list-in-case {
+                    key "test-leaf";
+                    leaf test-leaf {
+                        type string;
+                        config true;
+                    }
+                }
+            }
+            case case-b {
+                container case-b-container {
+                    list list-in-case {
+                        key "test-leaf";
+                        leaf test-leaf {
+                            type string;
+                            config true;
+                        }
+                    }
+                }
+            }
+        }
+        container outer-container {
+            leaf leaf-in-outer-container {
+                type string;
+                config true;
+            }
+        }
+    }
+}
\ No newline at end of file