BUG-4513 UT for Change event is empty when homogenious composite key is used 79/28679/5
authorValentin Mayamsin <vmayamsi@cisco.com>
Wed, 21 Oct 2015 22:55:51 +0000 (15:55 -0700)
committerTom Pantelis <tompantelis@gmail.com>
Thu, 6 Jul 2017 18:05:49 +0000 (18:05 +0000)
The original DCL test passes now so whatever the issue was before has been
fixed. I also added a DTCL test.

Change-Id: I5c5037f49a77835dbfea1ce9db8b22d03b6191ec
Signed-off-by: Valentin Mayamsin <vmayamsi@cisco.com>
opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug4513Test.java [new file with mode: 0644]
opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-listener-test.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/Bug4513Test.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/Bug4513Test.java
new file mode 100644 (file)
index 0000000..82da427
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc., Inocybe Technologies 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.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.timeout;
+import static org.mockito.Mockito.verify;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
+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.yang.controller.md.sal.test.listener.rev150825.ListenerTest;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTestBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItem;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItemBuilder;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+/**
+ * Regression test suite for https://bugs.opendaylight.org/show_bug.cgi?id=4513 - Change event is empty when
+ * Homogeneous composite key is used homogeneous composite key is used.
+ */
+public class Bug4513Test extends AbstractDataBrokerTest {
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testDataChangeListener() throws Exception {
+        DataChangeListener listener = mock(DataChangeListener.class);
+        InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class)
+                .child(ListItem.class).build();
+        ListenerRegistration<DataChangeListener> reg = getDataBroker().registerDataChangeListener(
+                LogicalDatastoreType.OPERATIONAL, wildCard, listener, AsyncDataBroker.DataChangeScope.SUBTREE);
+
+        final ListItem item = writeListItem();
+
+        ArgumentCaptor<AsyncDataChangeEvent> captor = ArgumentCaptor.forClass(AsyncDataChangeEvent.class);
+
+        verify(listener, timeout(100)).onDataChanged(captor.capture());
+
+        AsyncDataChangeEvent event = captor.getValue();
+        assertEquals("createdData", 1, event.getCreatedData().size());
+        assertEquals("ListItem", item, event.getCreatedData().values().iterator().next());
+    }
+
+    @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Test
+    public void testDataTreeChangeListener() throws Exception {
+        DataBroker dataBroker = getDataBroker();
+
+        DataTreeChangeListener<ListItem> listener = mock(DataTreeChangeListener.class);
+        InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class)
+                .child(ListItem.class).build();
+        ListenerRegistration<DataTreeChangeListener<ListItem>> reg = dataBroker.registerDataTreeChangeListener(
+                new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, wildCard), listener);
+
+        final ListItem item = writeListItem();
+
+        ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class);
+
+        verify(listener, timeout(100)).onDataTreeChanged(captor.capture());
+
+        Collection<DataTreeModification<ListItem>> mods = captor.getValue();
+        assertEquals("ListItem", item, mods.iterator().next().getRootNode().getDataAfter());
+    }
+
+    private ListItem writeListItem() {
+        WriteTransaction writeTransaction = getDataBroker().newWriteOnlyTransaction();
+        final ListItem item = new ListItemBuilder().setSip("name").setOp(43L).build();
+        ListenerTestBuilder builder = new ListenerTestBuilder().setListItem(Arrays.asList(item));
+        writeTransaction.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(
+                ListenerTest.class).build(), builder.build());
+        assertCommit(writeTransaction.submit());
+        return item;
+    }
+}
diff --git a/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-listener-test.yang b/opendaylight/md-sal/sal-test-model/src/main/yang/opendaylight-listener-test.yang
new file mode 100644 (file)
index 0000000..3cad60e
--- /dev/null
@@ -0,0 +1,22 @@
+module listener-container {
+    yang-version 1;
+    namespace "urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:listener";
+    prefix "test";
+
+    revision "2015-08-25" {
+        description
+            "Initial revision.";
+    }
+
+    container listener-test {
+        list list-item {
+            key "sip op";
+            leaf sip {
+                type string;
+            }
+            leaf op {
+                type uint32;
+            }
+        }
+    }
+}

©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.