Move BindingReflections to mdsal-binding-spec-util
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / test / DataTreeChangeListenerTest.java
index 2edb74c99166256a09d7d6360cad3e873b3afd3d..35e79fa12edb1cf4e59ee17fafebf07f4fd83d18 100644 (file)
@@ -33,6 +33,7 @@ import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
 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;
@@ -42,7 +43,6 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 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 {
 
@@ -63,20 +63,19 @@ 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
@@ -99,7 +98,7 @@ public class DataTreeChangeListenerTest extends AbstractDataBrokerTest {
 
         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);
@@ -108,7 +107,7 @@ public class DataTreeChangeListenerTest extends AbstractDataBrokerTest {
         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);
@@ -126,25 +125,39 @@ public class DataTreeChangeListenerTest extends AbstractDataBrokerTest {
                 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());