X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=opendaylight%2Fmd-sal%2Fsal-binding-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fbinding%2Fimpl%2Ftest%2FDataTreeChangeListenerTest.java;h=234cb959b11dcce8f1e4af7dfb0ab6dba8136fd7;hb=03c13bd8a8bb89a729d739eb2fcd501a4dfa5439;hp=4e9a79f8690bd63c0f6839930c3df68ca5252b61;hpb=8a8de0bffed5b6c9b4ac821dfafa7e944c70ef9d;p=controller.git diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/DataTreeChangeListenerTest.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/DataTreeChangeListenerTest.java index 4e9a79f869..234cb959b1 100644 --- a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/DataTreeChangeListenerTest.java +++ b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/impl/test/DataTreeChangeListenerTest.java @@ -11,6 +11,9 @@ package org.opendaylight.controller.md.sal.binding.impl.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.timeout; +import static org.mockito.Mockito.verify; import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_BAR_KEY; import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY; import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.USES_ONE_KEY; @@ -22,10 +25,13 @@ import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUti import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.util.concurrent.SettableFuture; +import java.util.ArrayList; import java.util.Collection; import java.util.concurrent.TimeUnit; import org.junit.Before; import org.junit.Test; +import org.mockito.Matchers; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataObjectModification; import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType; import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener; @@ -37,8 +43,10 @@ import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBro import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TwoLevelList; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument; @@ -67,8 +75,8 @@ public class DataTreeChangeListenerTest extends AbstractConcurrentDataBrokerTest private SettableFuture>> changes = SettableFuture.create(); @Override - public void onDataTreeChanged(final Collection> changes) { - this.changes.set(changes); + public void onDataTreeChanged(final Collection> modification) { + this.changes.set(modification); } @@ -77,7 +85,6 @@ public class DataTreeChangeListenerTest extends AbstractConcurrentDataBrokerTest changes = SettableFuture.create(); return result; } - } @Override @@ -101,23 +108,28 @@ public class DataTreeChangeListenerTest extends AbstractConcurrentDataBrokerTest createAndVerifyTop(listener); putTx(BAR_PATH, BAR_DATA).submit().checkedGet(); - final DataObjectModification afterBarPutEvent = Iterables.getOnlyElement(listener.nextEvent()).getRootNode(); + final DataObjectModification afterBarPutEvent = Iterables.getOnlyElement(listener.nextEvent()) + .getRootNode(); verifyModification(afterBarPutEvent, TOP_ARGUMENT, ModificationType.SUBTREE_MODIFIED); - final DataObjectModification barPutMod = afterBarPutEvent.getModifiedChildListItem(TopLevelList.class, TOP_BAR_KEY); + final DataObjectModification barPutMod = afterBarPutEvent + .getModifiedChildListItem(TopLevelList.class, TOP_BAR_KEY); assertNotNull(barPutMod); verifyModification(barPutMod, BAR_ARGUMENT, ModificationType.WRITE); deleteTx(BAR_PATH).submit().checkedGet(); - final DataObjectModification afterBarDeleteEvent = Iterables.getOnlyElement(listener.nextEvent()).getRootNode(); + final DataObjectModification afterBarDeleteEvent = Iterables.getOnlyElement(listener.nextEvent()) + .getRootNode(); verifyModification(afterBarDeleteEvent, TOP_ARGUMENT, ModificationType.SUBTREE_MODIFIED); - final DataObjectModification barDeleteMod = afterBarDeleteEvent.getModifiedChildListItem(TopLevelList.class, TOP_BAR_KEY); + final DataObjectModification barDeleteMod = afterBarDeleteEvent + .getModifiedChildListItem(TopLevelList.class, TOP_BAR_KEY); verifyModification(barDeleteMod, BAR_ARGUMENT, ModificationType.DELETE); } @Test public void testWildcardedListListener() throws Exception { final EventCapturingListener listener = new EventCapturingListener<>(); - final DataTreeIdentifier wildcard = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, TOP_PATH.child(TopLevelList.class)); + final DataTreeIdentifier wildcard = new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, + TOP_PATH.child(TopLevelList.class)); dataBrokerImpl.registerDataTreeChangeListener(wildcard, listener); putTx(TOP_PATH, TOP_INITIAL_DATA).submit().checkedGet(); @@ -137,7 +149,28 @@ public class DataTreeChangeListenerTest extends AbstractConcurrentDataBrokerTest verifyModification(barDeleteEvent.getRootNode(), BAR_ARGUMENT, ModificationType.DELETE); } + @SuppressWarnings("unchecked") + @Test + public void testWildcardNotificationOfPreexistingData() throws Exception { + InstanceIdentifier id = InstanceIdentifier.builder(Top.class).build(); + ArrayList list = new ArrayList<>(); + list.add(new TopLevelListBuilder().setName("name").build()); + TopBuilder builder = new TopBuilder().setTopLevelList(list); + + DataBroker dataBroker = getDataBroker(); + WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction(); + writeTransaction.put(LogicalDatastoreType.OPERATIONAL, id, builder.build()); + assertCommit(writeTransaction.submit()); + + DataTreeChangeListener listener = mock(DataTreeChangeListener.class); + InstanceIdentifier wildcard = InstanceIdentifier.builder(Top.class).child(TopLevelList.class) + .build(); + dataBroker.registerDataTreeChangeListener(new DataTreeIdentifier<>(LogicalDatastoreType.OPERATIONAL, wildcard), + listener); + + verify(listener, timeout(1000)).onDataTreeChanged(Matchers.anyObject()); + } private void createAndVerifyTop(final EventCapturingListener listener) throws Exception { putTx(TOP_PATH,TOP_INITIAL_DATA).submit().checkedGet(); @@ -150,8 +183,8 @@ public class DataTreeChangeListenerTest extends AbstractConcurrentDataBrokerTest assertEquals(TOP_INITIAL_DATA, initialNode.getDataAfter()); } - private void verifyModification(final DataObjectModification barWrite, final PathArgument pathArg, - final ModificationType eventType) { + private void verifyModification(final DataObjectModification barWrite, + final PathArgument pathArg, final ModificationType eventType) { assertEquals(pathArg.getType(), barWrite.getDataType()); assertEquals(eventType,barWrite.getModificationType()); assertEquals(pathArg, barWrite.getIdentifier());