Bug 2562: Binding Data Codec: Incorrectly deserialized unkeyed list from NormalizedNode 35/36435/2
authorFilip Gregor <fgregor@cisco.com>
Fri, 18 Mar 2016 10:21:03 +0000 (11:21 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 21 Mar 2016 11:01:17 +0000 (11:01 +0000)
added test show that this is no longer an issue

Change-Id: I3f84b0ebc71d1fef85068e2ff7b06a78c397e4c8
Signed-off-by: Filip Gregor <fgregor@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug2562DeserializedUnkeyedListTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-2562.yang [new file with mode: 0644]

diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug2562DeserializedUnkeyedListTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug2562DeserializedUnkeyedListTest.java
new file mode 100644 (file)
index 0000000..1d4a708
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2016 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.controller.md.sal.binding.impl.test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains;
+import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty;
+
+import java.util.ArrayList;
+import org.junit.Test;
+import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.Root;
+import org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.RootBuilder;
+import org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.Fooroot;
+import org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.FoorootBuilder;
+import org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.fooroot.Barroot;
+import org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.fooroot.BarrootBuilder;
+import org.opendaylight.yang.gen.v1.opendaylight.test.bug._2562.namespace.rev160101.root.fooroot.BarrootKey;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Bug2562DeserializedUnkeyedListTest extends AbstractDataChangeListenerTest {
+    private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
+
+    private void writeRoot(final LogicalDatastoreType store) {
+        final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
+        final Barroot barRoot = new BarrootBuilder().setType(2).setValue(2).setKey(new BarrootKey(2)).build();
+        final ArrayList barRootList = new ArrayList();
+        barRootList.add(barRoot);
+        final Fooroot fooRoot = new FoorootBuilder().setBarroot(barRootList).build();
+        final ArrayList fooRootList = new ArrayList();
+        fooRootList.add(fooRoot);
+        final Root root = new RootBuilder().setFooroot(fooRootList).build();
+
+        readWriteTransaction.put(store, ROOT_PATH, root);
+        assertCommit(readWriteTransaction.submit());
+    }
+
+    @Test
+    public void writeListToList2562Root() {
+        final AbstractDataChangeListenerTest.TestListener listenerRoot = createListener(LogicalDatastoreType.CONFIGURATION,
+                ROOT_PATH, AsyncDataBroker.DataChangeScope.ONE);
+        listenerRoot.startCapture();
+        writeRoot(LogicalDatastoreType.CONFIGURATION);
+        final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> eventRoot = listenerRoot.event();
+
+        assertContains(eventRoot.getCreatedData(), ROOT_PATH);
+        assertEmpty(eventRoot.getUpdatedData());
+        assertEmpty(eventRoot.getRemovedPaths());
+        assertNotNull(eventRoot.toString());
+    }
+}
diff --git a/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-2562.yang b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-2562.yang
new file mode 100644 (file)
index 0000000..75102ed
--- /dev/null
@@ -0,0 +1,19 @@
+module opendaylight-test-bug-2562 {
+    yang-version 1;
+    namespace "opendaylight-test-bug-2562:namespace";
+    prefix "ty";
+    revision "2016-01-01" {
+        description
+            "bug 2562 Binding Data Codec: Incorrectly deserialized unkeyed list from NormalizedNode";
+    }
+
+    container root {
+        list fooroot {
+            list barroot {
+                key "type";
+                leaf type { type int32; }
+                leaf value { type int32; }
+            }
+        }
+    }
+}
\ No newline at end of file

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.