Deprecate all MD-SAL APIs
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / Bug4513Test.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc., Inocybe Technologies and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.md.sal.binding.impl.test;
9
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;
14
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
33 /**
34  * Regression test suite for https://bugs.opendaylight.org/show_bug.cgi?id=4513 - Change event is empty when
35  * Homogeneous composite key is used homogeneous composite key is used.
36  */
37 @Deprecated
38 public class Bug4513Test extends AbstractDataBrokerTest {
39
40     @SuppressWarnings({ "rawtypes", "unchecked" })
41     @Test
42     public void testDataTreeChangeListener() {
43         DataBroker dataBroker = getDataBroker();
44
45         DataTreeChangeListener<ListItem> listener = mock(DataTreeChangeListener.class);
46         InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class)
47                 .child(ListItem.class).build();
48         ListenerRegistration<DataTreeChangeListener<ListItem>> reg = dataBroker.registerDataTreeChangeListener(
49                 new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, wildCard), listener);
50
51         final ListItem item = writeListItem();
52
53         ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class);
54
55         verify(listener, timeout(100)).onDataTreeChanged(captor.capture());
56
57         Collection<DataTreeModification<ListItem>> mods = captor.getValue();
58         assertEquals("ListItem", item, mods.iterator().next().getRootNode().getDataAfter());
59     }
60
61     private ListItem writeListItem() {
62         WriteTransaction writeTransaction = getDataBroker().newWriteOnlyTransaction();
63         final ListItem item = new ListItemBuilder().setSip("name").setOp(43L).build();
64         ListenerTestBuilder builder = new ListenerTestBuilder().setListItem(Arrays.asList(item));
65         writeTransaction.put(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(
66                 ListenerTest.class).build(), builder.build());
67         assertCommit(writeTransaction.submit());
68         return item;
69     }
70 }

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