Search in sources :

Example 1 with DataChangeListener

use of org.opendaylight.controller.md.sal.binding.api.DataChangeListener in project controller by opendaylight.

the class Bug4513Test method testDataChangeListener.

@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());
}
Also used : DataChangeListener(org.opendaylight.controller.md.sal.binding.api.DataChangeListener) ListItem(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItem) AsyncDataChangeEvent(org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent) AbstractDataBrokerTest(org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest) Test(org.junit.Test) ListenerTest(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTest)

Aggregations

Test (org.junit.Test)1 DataChangeListener (org.opendaylight.controller.md.sal.binding.api.DataChangeListener)1 AbstractDataBrokerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest)1 AsyncDataChangeEvent (org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent)1 ListenerTest (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.ListenerTest)1 ListItem (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItem)1