Bug 3090: An AsyncDataChangeEvent instance's getCreatedData() 43/36443/6
authorFilip Gregor <fgregor@cisco.com>
Fri, 18 Mar 2016 14:37:19 +0000 (15:37 +0100)
committerTony Tkacik <ttkacik@cisco.com>
Mon, 11 Apr 2016 11:03:24 +0000 (11:03 +0000)
added tests

Change-Id: Icfa7d1ef72962cb96929eddcabe51d7b0037f606
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/Bug3090MultiKeyList.java [new file with mode: 0644]
opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-3090.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/Bug3090MultiKeyList.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug3090MultiKeyList.java
new file mode 100644 (file)
index 0000000..83bb6a4
--- /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.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains;
+import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty;
+import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
+
+import java.util.ArrayList;
+import java.util.List;
+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.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.Root;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.RootBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRoot;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.opendaylight.test.bug._3090.rev160101.root.ListInRootBuilder;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class Bug3090MultiKeyList extends AbstractDataChangeListenerTest{
+    private static final InstanceIdentifier<Root> ROOT_PATH = InstanceIdentifier.create(Root.class);
+
+    private void write(final LogicalDatastoreType store) {
+        final ReadWriteTransaction readWriteTransaction = getDataBroker().newReadWriteTransaction();
+
+        final List<ListInRoot> listInRoots = new ArrayList<>();
+        for (int i = 0; i < 10; i++) {
+            listInRoots.add(new ListInRootBuilder()
+                .setLeafA("leaf a" + i)
+                .setLeafC("leaf c" + i)
+                .setLeafB("leaf b" + i)
+                .build()
+            );
+        }
+        final Root root = new RootBuilder().setListInRoot(listInRoots).build();
+        readWriteTransaction.put(store, ROOT_PATH, root);
+        assertCommit(readWriteTransaction.submit());
+    }
+
+    @Test
+    public void listWithMultiKeyTest() {
+        final AbstractDataChangeListenerTest.TestListener listener = createListener(CONFIGURATION, ROOT_PATH,
+                AsyncDataBroker.DataChangeScope.BASE);
+        listener.startCapture();
+
+        write(CONFIGURATION);
+        final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
+
+        assertContains(event.getCreatedData(), ROOT_PATH);
+        assertEmpty(event.getUpdatedData());
+        assertEmpty(event.getRemovedPaths());
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-3090.yang b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-test-bug-3090.yang
new file mode 100644 (file)
index 0000000..9818bd8
--- /dev/null
@@ -0,0 +1,28 @@
+module opendaylight-test-bug-3090 {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:opendaylight-test-bug-3090";
+    prefix "rpc";
+
+    description
+        "Test model for Bug 3090 - An AsyncDataChangeEvent instance's getCreatedData() method can't get data if list has multi-key";
+
+    revision "2016-01-01" {
+        description
+            "Bug 3090";
+    }
+
+    container root {
+        list list-in-root {
+            key "leaf-c leaf-a leaf-b";
+            leaf leaf-a {
+                type string;
+            }
+            leaf leaf-b {
+                type string;
+            }
+            leaf leaf-c {
+                type string;
+            }
+        }
+    }
+}
\ No newline at end of file