2 * Copyright (c) 2015 Cisco Systems, Inc., Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.md.sal.binding.impl.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.timeout;
13 import static org.mockito.Mockito.verify;
15 import java.util.Arrays;
16 import java.util.Collection;
17 import org.junit.Test;
18 import org.mockito.ArgumentCaptor;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
21 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
22 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
23 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
24 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
25 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTest;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTestBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItem;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItemBuilder;
30 import org.opendaylight.yangtools.concepts.ListenerRegistration;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.common.Uint32;
35 * Regression test suite for https://bugs.opendaylight.org/show_bug.cgi?id=4513 - Change event is empty when
36 * Homogeneous composite key is used homogeneous composite key is used.
39 public class Bug4513Test extends AbstractDataBrokerTest {
41 @SuppressWarnings({ "rawtypes", "unchecked" })
43 public void testDataTreeChangeListener() {
44 DataBroker dataBroker = getDataBroker();
46 DataTreeChangeListener<ListItem> listener = mock(DataTreeChangeListener.class);
47 InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class)
48 .child(ListItem.class).build();
49 ListenerRegistration<DataTreeChangeListener<ListItem>> reg = dataBroker.registerDataTreeChangeListener(
50 new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, wildCard), listener);
52 final ListItem item = writeListItem();
54 ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class);
56 verify(listener, timeout(100)).onDataTreeChanged(captor.capture());
58 Collection<DataTreeModification<ListItem>> mods = captor.getValue();
59 assertEquals("ListItem", item, mods.iterator().next().getRootNode().getDataAfter());
62 private ListItem writeListItem() {
63 WriteTransaction writeTransaction = getDataBroker().newWriteOnlyTransaction();
64 final ListItem item = new ListItemBuilder().setSip("name").setOp(Uint32.valueOf(43)).build();
65 ListenerTestBuilder builder = new ListenerTestBuilder().setListItem(Arrays.asList(item));
66 writeTransaction.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(
67 ListenerTest.class).build(), builder.build());
68 assertCommit(writeTransaction.submit());