Search in sources :

Example 1 with DataTreeChangeListener

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

the class Bug4513Test method testDataTreeChangeListener.

@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());
}
Also used : DataTreeModification(org.opendaylight.controller.md.sal.binding.api.DataTreeModification) DataTreeChangeListener(org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener) DataTreeIdentifier(org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier) Collection(java.util.Collection) ListItem(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.listener.rev150825.listener.test.ListItem) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) AsyncDataBroker(org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker) 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)

Example 2 with DataTreeChangeListener

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

the class TestableDataTreeChangeListenerModule method getTestableDataTreeChangeListener.

@SuppressWarnings({ "unchecked", "rawtypes" })
protected TestableDataTreeChangeListener getTestableDataTreeChangeListener(Injector injector) {
    TestableDataTreeChangeListener beforeTestableDataTreeChangeListener = new TestableDataTreeChangeListener();
    DataTreeChangeListener afterTestableDataTreeChangeListener = new DecrementingTestableDataTreeChangeDecoratorListener(beforeTestableDataTreeChangeListener);
    for (Key<?> key : injector.getAllBindings().keySet()) {
        if (ChainableDataTreeChangeListener.class.isAssignableFrom(key.getTypeLiteral().getRawType())) {
            ChainableDataTreeChangeListener chainableListener = (ChainableDataTreeChangeListener) injector.getInstance(key);
            chainableListener.addBeforeListener(beforeTestableDataTreeChangeListener);
            chainableListener.addAfterListener(afterTestableDataTreeChangeListener);
            LOG.info("AsyncEventsWaiter: {}", chainableListener);
        }
    }
    return beforeTestableDataTreeChangeListener;
}
Also used : DataTreeChangeListener(org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener) ChainableDataTreeChangeListener(org.opendaylight.genius.datastoreutils.ChainableDataTreeChangeListener) ChainableDataTreeChangeListener(org.opendaylight.genius.datastoreutils.ChainableDataTreeChangeListener)

Aggregations

DataTreeChangeListener (org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener)2 Collection (java.util.Collection)1 Test (org.junit.Test)1 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)1 DataTreeIdentifier (org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier)1 DataTreeModification (org.opendaylight.controller.md.sal.binding.api.DataTreeModification)1 AbstractDataBrokerTest (org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest)1 AsyncDataBroker (org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker)1 ChainableDataTreeChangeListener (org.opendaylight.genius.datastoreutils.ChainableDataTreeChangeListener)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