Expose a List of changes in DOMDataTreeChangeListener
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / Mdsal298Test.java
index 258eacee00aceeca46e4d5b68d556273b0192afa..794a3eeb9d8cfc8f8528ef5b51527d58d5a3fccd 100644 (file)
@@ -8,15 +8,13 @@
 package org.opendaylight.mdsal.binding.dom.adapter;
 
 import static org.junit.Assert.assertEquals;
-import static org.mockito.ArgumentMatchers.anyCollection;
+import static org.mockito.ArgumentMatchers.anyList;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.verify;
 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION;
 
-import java.util.Collection;
-import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
 import org.junit.Test;
@@ -105,38 +103,38 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
                 .build());
         domTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<Container>> capture = captor.getValue();
+        List<DataTreeModification<Container>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
-        final DataTreeModification<Container> change = capture.iterator().next();
+        final DataTreeModification<Container> change = capture.get(0);
         assertEquals(CONTAINER_TID, change.getRootPath());
         final DataObjectModification<Container> changedContainer = change.getRootNode();
-        assertEquals(new NodeStep<>(Container.class), changedContainer.getIdentifier());
-        assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.getModificationType());
+        assertEquals(new NodeStep<>(Container.class), changedContainer.step());
+        assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.modificationType());
 
-        final Container containerAfter = changedContainer.getDataAfter();
+        final Container containerAfter = changedContainer.dataAfter();
         assertEquals(new ContainerBuilder()
             .setKeyed(List.of(
                 new KeyedBuilder().setFoo("foo").withKey(new KeyedKey("foo")).build(),
                 new KeyedBuilder().setFoo("bar").withKey(new KeyedKey("bar")).build()))
             .build(), containerAfter);
 
-        final Collection<? extends DataObjectModification<?>> changedChildren = changedContainer.getModifiedChildren();
+        final var changedChildren = changedContainer.modifiedChildren();
         assertEquals(2, changedChildren.size());
 
-        final Iterator<? extends DataObjectModification<?>> it = changedChildren.iterator();
+        final var it = changedChildren.iterator();
         final DataObjectModification<?> changedChild1 = it.next();
-        assertEquals(ModificationType.WRITE, changedChild1.getModificationType());
-        assertEquals(List.of(), changedChild1.getModifiedChildren());
-        final Keyed child1After = (Keyed) changedChild1.getDataAfter();
+        assertEquals(ModificationType.WRITE, changedChild1.modificationType());
+        assertEquals(List.of(), changedChild1.modifiedChildren());
+        final Keyed child1After = (Keyed) changedChild1.dataAfter();
         assertEquals("foo", child1After.getFoo());
 
         final DataObjectModification<?> changedChild2 = it.next();
-        assertEquals(ModificationType.WRITE, changedChild2.getModificationType());
-        assertEquals(List.of(), changedChild2.getModifiedChildren());
-        final Keyed child2After = (Keyed) changedChild2.getDataAfter();
+        assertEquals(ModificationType.WRITE, changedChild2.modificationType());
+        assertEquals(List.of(), changedChild2.modifiedChildren());
+        final Keyed child2After = (Keyed) changedChild2.dataAfter();
         assertEquals("bar", child2After.getFoo());
     }
 
@@ -160,25 +158,25 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
                 .build());
         domTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<Container>> capture = captor.getValue();
+        List<DataTreeModification<Container>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
-        final DataTreeModification<Container> change = capture.iterator().next();
+        final DataTreeModification<Container> change = capture.get(0);
         assertEquals(CONTAINER_TID, change.getRootPath());
         final DataObjectModification<Container> changedContainer = change.getRootNode();
-        assertEquals(new NodeStep<>(Container.class), changedContainer.getIdentifier());
-        assertEquals(ModificationType.WRITE, changedContainer.getModificationType());
+        assertEquals(new NodeStep<>(Container.class), changedContainer.step());
+        assertEquals(ModificationType.WRITE, changedContainer.modificationType());
 
-        final Container containerAfter = changedContainer.getDataAfter();
+        final Container containerAfter = changedContainer.dataAfter();
         assertEquals(new ContainerBuilder()
                 .setUnkeyed(List.of(
                     new UnkeyedBuilder().setFoo("foo").build(),
                     new UnkeyedBuilder().setFoo("bar").build()))
                 .build(), containerAfter);
 
-        final Collection<? extends DataObjectModification<?>> changedChildren = changedContainer.getModifiedChildren();
+        final var changedChildren = changedContainer.modifiedChildren();
         assertEquals(0, changedChildren.size());
     }
 
@@ -186,31 +184,30 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
     public void testChoiceDataTreeModificationAddressable() throws InterruptedException, ExecutionException {
         final DataTreeChangeListener<WithChoice> listener = assertWrittenWithChoice();
 
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
 
         final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(CONFIGURATION, ADDRESSABLE_CASE, new AddressableBuilder().build());
         writeTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<WithChoice>> capture = captor.getValue();
+        List<DataTreeModification<WithChoice>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
         final DataTreeModification<WithChoice> choiceChange = capture.iterator().next();
         assertEquals(CHOICE_CONTAINER_TID, choiceChange.getRootPath());
         final DataObjectModification<WithChoice> changedContainer = choiceChange.getRootNode();
-        assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.getModificationType());
-        assertEquals(new NodeStep<>(WithChoice.class), changedContainer.getIdentifier());
+        assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.modificationType());
+        assertEquals(new NodeStep<>(WithChoice.class), changedContainer.step());
 
-        final Collection<? extends DataObjectModification<?>> choiceChildren = changedContainer.getModifiedChildren();
+        final var choiceChildren = changedContainer.modifiedChildren();
         assertEquals(1, choiceChildren.size());
 
-        final DataObjectModification<Addressable> changedCase = (DataObjectModification<Addressable>) choiceChildren
-                .iterator().next();
-        assertEquals(ModificationType.WRITE, changedCase.getModificationType());
-        assertEquals(new NodeStep<>(Addressable.class), changedCase.getIdentifier());
-        assertEquals(new AddressableBuilder().build(), changedCase.getDataAfter());
+        final var changedCase = (DataObjectModification<Addressable>) choiceChildren.iterator().next();
+        assertEquals(ModificationType.WRITE, changedCase.modificationType());
+        assertEquals(new NodeStep<>(Addressable.class), changedCase.step());
+        assertEquals(new AddressableBuilder().build(), changedCase.dataAfter());
     }
 
     @Test
@@ -218,32 +215,31 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
         final DataTreeChangeListener<AddressableCont> listener = assertWrittenContainer(AddressableCont.QNAME,
             AddressableCont.class, new AddressableContBuilder().build());
 
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
 
         final WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
         writeTx.put(CONFIGURATION, ADDRESSABLE_CONTAINER.child(AddressableChild.class),
             new AddressableChildBuilder().build());
         writeTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<AddressableCont>> capture = captor.getValue();
+        final List<DataTreeModification<AddressableCont>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
         final DataTreeModification<AddressableCont> contChange = capture.iterator().next();
         assertEquals(ADDRESSABLE_CONTAINER_TID, contChange.getRootPath());
         final DataObjectModification<AddressableCont> changedContainer = contChange.getRootNode();
-        assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.getModificationType());
-        assertEquals(new NodeStep<>(AddressableCont.class), changedContainer.getIdentifier());
+        assertEquals(ModificationType.SUBTREE_MODIFIED, changedContainer.modificationType());
+        assertEquals(new NodeStep<>(AddressableCont.class), changedContainer.step());
 
-        final Collection<? extends DataObjectModification<?>> contChildren = changedContainer.getModifiedChildren();
+        final var contChildren = changedContainer.modifiedChildren();
         assertEquals(1, contChildren.size());
 
-        final DataObjectModification<Addressable> changedChild = (DataObjectModification<Addressable>) contChildren
-                .iterator().next();
-        assertEquals(ModificationType.WRITE, changedChild.getModificationType());
-        assertEquals(new NodeStep<>(AddressableChild.class), changedChild.getIdentifier());
-        assertEquals(new AddressableChildBuilder().build(), changedChild.getDataAfter());
+        final var changedChild = (DataObjectModification<Addressable>) contChildren.iterator().next();
+        assertEquals(ModificationType.WRITE, changedChild.modificationType());
+        assertEquals(new NodeStep<>(AddressableChild.class), changedChild.step());
+        assertEquals(new AddressableChildBuilder().build(), changedChild.dataAfter());
     }
 
     @Test
@@ -251,7 +247,7 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
         final DataTreeChangeListener<UnaddressableCont> listener = assertWrittenContainer(UnaddressableCont.QNAME,
             UnaddressableCont.class, new UnaddressableContBuilder().build());
 
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
 
         final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction();
         domTx.put(CONFIGURATION, YangInstanceIdentifier.of(UNADDRESSABLE_CONTAINER_NID)
@@ -259,18 +255,18 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
             ImmutableNodes.leafNode(BAZ_QNAME, "baz"));
         domTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<UnaddressableCont>> capture = captor.getValue();
+        List<DataTreeModification<UnaddressableCont>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
         final DataTreeModification<UnaddressableCont> contChange = capture.iterator().next();
         assertEquals(UNADDRESSABLE_CONTAINER_TID, contChange.getRootPath());
         final DataObjectModification<UnaddressableCont> changedContainer = contChange.getRootNode();
-        assertEquals(ModificationType.WRITE, changedContainer.getModificationType());
-        assertEquals(new NodeStep<>(UnaddressableCont.class), changedContainer.getIdentifier());
+        assertEquals(ModificationType.WRITE, changedContainer.modificationType());
+        assertEquals(new NodeStep<>(UnaddressableCont.class), changedContainer.step());
 
-        final Collection<? extends DataObjectModification<?>> contChildren = changedContainer.getModifiedChildren();
+        final var contChildren = changedContainer.modifiedChildren();
         assertEquals(0, contChildren.size());
     }
 
@@ -278,7 +274,7 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
     public void testChoiceDataTreeModificationUnaddressable() throws InterruptedException, ExecutionException {
         final DataTreeChangeListener<WithChoice> listener = assertWrittenWithChoice();
 
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
 
         final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction();
         domTx.put(CONFIGURATION, YangInstanceIdentifier.of(CHOICE_CONTAINER_NID).node(Foo.QNAME),
@@ -291,20 +287,20 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
                 .build());
         domTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<WithChoice>> capture = captor.getValue();
+        List<DataTreeModification<WithChoice>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
-        final DataTreeModification<WithChoice> choiceChange = capture.iterator().next();
+        final DataTreeModification<WithChoice> choiceChange = capture.get(0);
         assertEquals(CHOICE_CONTAINER_TID, choiceChange.getRootPath());
         final DataObjectModification<WithChoice> changedContainer = choiceChange.getRootNode();
 
         // Should be write
-        assertEquals(ModificationType.WRITE, changedContainer.getModificationType());
-        assertEquals(new NodeStep<>(WithChoice.class), changedContainer.getIdentifier());
+        assertEquals(ModificationType.WRITE, changedContainer.modificationType());
+        assertEquals(new NodeStep<>(WithChoice.class), changedContainer.step());
 
-        final Collection<? extends DataObjectModification<?>> choiceChildren = changedContainer.getModifiedChildren();
+        final var choiceChildren = changedContainer.modifiedChildren();
         assertEquals(0, choiceChildren.size());
     }
 
@@ -312,7 +308,7 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
             final Class<T> bindingClass, final T expected)
             throws InterruptedException, ExecutionException {
         final DataTreeChangeListener<T> listener = mock(DataTreeChangeListener.class);
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
 
         final DataTreeIdentifier<T> dti = DataTreeIdentifier.of(CONFIGURATION, InstanceIdentifier.create(bindingClass));
         getDataBroker().registerDataTreeChangeListener(dti, listener);
@@ -322,32 +318,32 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
             ImmutableNodes.newContainerBuilder().withNodeIdentifier(new NodeIdentifier(qname)).build());
         domTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<T>> capture = captor.getValue();
+        List<DataTreeModification<T>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
         final DataTreeModification<T> change = capture.iterator().next();
         assertEquals(dti, change.getRootPath());
         final DataObjectModification<T> changedContainer = change.getRootNode();
-        assertEquals(ModificationType.WRITE, changedContainer.getModificationType());
-        assertEquals(new NodeStep<>(bindingClass), changedContainer.getIdentifier());
+        assertEquals(ModificationType.WRITE, changedContainer.modificationType());
+        assertEquals(new NodeStep<>(bindingClass), changedContainer.step());
 
-        final T containerAfter = changedContainer.getDataAfter();
+        final T containerAfter = changedContainer.dataAfter();
         assertEquals(expected, containerAfter);
 
         // No further modifications should occur
-        assertEquals(List.of(), changedContainer.getModifiedChildren());
+        assertEquals(List.of(), changedContainer.modifiedChildren());
 
         reset(listener);
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
         return listener;
     }
 
     private DataTreeChangeListener<WithChoice> assertWrittenWithChoice() throws InterruptedException,
             ExecutionException {
         final DataTreeChangeListener<WithChoice> listener = mock(DataTreeChangeListener.class);
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
         getDataBroker().registerDataTreeChangeListener(CHOICE_CONTAINER_TID, listener);
 
         final DOMDataTreeWriteTransaction domTx = getDomBroker().newWriteOnlyTransaction();
@@ -357,25 +353,25 @@ public class Mdsal298Test extends AbstractDataBrokerTest {
             .build());
         domTx.commit().get();
 
-        final var captor = ArgumentCaptor.forClass(Collection.class);
+        final var captor = ArgumentCaptor.forClass(List.class);
         verify(listener).onDataTreeChanged(captor.capture());
-        Collection<DataTreeModification<WithChoice>> capture = captor.getValue();
+        List<DataTreeModification<WithChoice>> capture = captor.getValue();
         assertEquals(1, capture.size());
 
         final DataTreeModification<WithChoice> change = capture.iterator().next();
         assertEquals(CHOICE_CONTAINER_TID, change.getRootPath());
         final DataObjectModification<WithChoice> changedContainer = change.getRootNode();
-        assertEquals(ModificationType.WRITE, changedContainer.getModificationType());
-        assertEquals(new NodeStep<>(WithChoice.class), changedContainer.getIdentifier());
+        assertEquals(ModificationType.WRITE, changedContainer.modificationType());
+        assertEquals(new NodeStep<>(WithChoice.class), changedContainer.step());
 
-        final WithChoice containerAfter = changedContainer.getDataAfter();
+        final WithChoice containerAfter = changedContainer.dataAfter();
         assertEquals(new WithChoiceBuilder().build(), containerAfter);
 
         // No further modifications should occur
-        assertEquals(List.of(), changedContainer.getModifiedChildren());
+        assertEquals(List.of(), changedContainer.modifiedChildren());
 
         reset(listener);
-        doNothing().when(listener).onDataTreeChanged(anyCollection());
+        doNothing().when(listener).onDataTreeChanged(anyList());
 
         return listener;
     }