import org.opendaylight.mdsal.binding.api.DataTreeModification;
import org.opendaylight.mdsal.binding.api.WriteTransaction;
import org.opendaylight.mdsal.binding.dom.adapter.BindingDOMDataBrokerAdapter;
+import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
-import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
public class DataTreeChangeListenerTest extends AbstractDataBrokerTest {
private static final class EventCapturingListener<T extends DataObject> implements DataTreeChangeListener<T> {
- private SettableFuture<Collection<DataTreeModification<T>>> changes = SettableFuture.create();
+ private SettableFuture<Collection<DataTreeModification<T>>> futureChanges = SettableFuture.create();
@Override
public void onDataTreeChanged(final Collection<DataTreeModification<T>> changes) {
- this.changes.set(changes);
+ this.futureChanges.set(changes);
}
Collection<DataTreeModification<T>> nextEvent() throws Exception {
- final Collection<DataTreeModification<T>> result = changes.get(200,TimeUnit.MILLISECONDS);
- changes = SettableFuture.create();
+ final Collection<DataTreeModification<T>> result = futureChanges.get(200,TimeUnit.MILLISECONDS);
+ futureChanges = SettableFuture.create();
return result;
}
-
}
@Override
createAndVerifyTop(listener);
- putTx(BAR_PATH, BAR_DATA).submit().get();
+ putTx(BAR_PATH, BAR_DATA).commit().get();
final DataObjectModification<Top> afterBarPutEvent
= Iterables.getOnlyElement(listener.nextEvent()).getRootNode();
verifyModification(afterBarPutEvent, TOP_ARGUMENT, ModificationType.SUBTREE_MODIFIED);
assertNotNull(barPutMod);
verifyModification(barPutMod, BAR_ARGUMENT, ModificationType.WRITE);
- deleteTx(BAR_PATH).submit().get();
+ deleteTx(BAR_PATH).commit().get();
final DataObjectModification<Top> afterBarDeleteEvent
= Iterables.getOnlyElement(listener.nextEvent()).getRootNode();
verifyModification(afterBarDeleteEvent, TOP_ARGUMENT, ModificationType.SUBTREE_MODIFIED);
LogicalDatastoreType.OPERATIONAL, TOP_PATH.child(TopLevelList.class));
dataBrokerImpl.registerDataTreeChangeListener(wildcard, listener);
- putTx(TOP_PATH, TOP_INITIAL_DATA).submit().get();
+ putTx(TOP_PATH, TOP_INITIAL_DATA).commit().get();
final DataTreeModification<TopLevelList> fooWriteEvent = Iterables.getOnlyElement(listener.nextEvent());
assertEquals(FOO_PATH, fooWriteEvent.getRootPath().getRootIdentifier());
verifyModification(fooWriteEvent.getRootNode(), FOO_ARGUMENT, ModificationType.WRITE);
- putTx(BAR_PATH, BAR_DATA).submit().get();
+ putTx(BAR_PATH, BAR_DATA).commit().get();
final DataTreeModification<TopLevelList> barWriteEvent = Iterables.getOnlyElement(listener.nextEvent());
assertEquals(BAR_PATH, barWriteEvent.getRootPath().getRootIdentifier());
verifyModification(barWriteEvent.getRootNode(), BAR_ARGUMENT, ModificationType.WRITE);
- deleteTx(BAR_PATH).submit().get();
+ deleteTx(BAR_PATH).commit().get();
final DataTreeModification<TopLevelList> barDeleteEvent = Iterables.getOnlyElement(listener.nextEvent());
assertEquals(BAR_PATH, barDeleteEvent.getRootPath().getRootIdentifier());
verifyModification(barDeleteEvent.getRootNode(), BAR_ARGUMENT, ModificationType.DELETE);
}
+ @Test
+ public void testWildcardedListListenerWithPreexistingData() throws Exception {
+ putTx(TOP_PATH, TOP_INITIAL_DATA).commit().get();
+
+ final EventCapturingListener<TopLevelList> listener = new EventCapturingListener<>();
+ final DataTreeIdentifier<TopLevelList> wildcard = DataTreeIdentifier.create(
+ LogicalDatastoreType.OPERATIONAL, TOP_PATH.child(TopLevelList.class));
+ dataBrokerImpl.registerDataTreeChangeListener(wildcard, listener);
+
+ final DataTreeModification<TopLevelList> fooWriteEvent = Iterables.getOnlyElement(listener.nextEvent());
+ assertEquals(FOO_PATH, fooWriteEvent.getRootPath().getRootIdentifier());
+ verifyModification(fooWriteEvent.getRootNode(), FOO_ARGUMENT, ModificationType.WRITE);
+ }
+
private void createAndVerifyTop(final EventCapturingListener<Top> listener) throws Exception {
- putTx(TOP_PATH,TOP_INITIAL_DATA).submit().get();
+ putTx(TOP_PATH,TOP_INITIAL_DATA).commit().get();
final Collection<DataTreeModification<Top>> events = listener.nextEvent();
assertFalse("Non empty collection should be received.",events.isEmpty());