Adopt odlparent-10.0.0/yangtools-8.0.0-SNAPSHOT
[mdsal.git] / dom / mdsal-dom-broker / src / test / java / org / opendaylight / mdsal / dom / broker / DOMDataTreeListenerTest.java
index 86a424d7e961459fe760c58a058da1cebfb06319..39947d728bf1b907cadc95283bf20d64015c25b1 100644 (file)
@@ -19,7 +19,6 @@ import com.google.common.util.concurrent.ForwardingExecutorService;
 import com.google.common.util.concurrent.ListeningExecutorService;
 import com.google.common.util.concurrent.MoreExecutors;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
@@ -35,48 +34,43 @@ import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeListener;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
-import org.opendaylight.mdsal.dom.broker.util.TestModel;
 import org.opendaylight.mdsal.dom.spi.store.DOMStore;
 import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.util.concurrent.DeadlockDetectingListeningExecutorService;
 import org.opendaylight.yangtools.util.concurrent.SpecialExecutors;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate;
+import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
+import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
 
-public class DOMDataTreeListenerTest {
+public class DOMDataTreeListenerTest extends AbstractDatastoreTest {
 
-    private SchemaContext schemaContext;
     private AbstractDOMDataBroker domBroker;
     private ListeningExecutorService executor;
     private ExecutorService futureExecutor;
     private CommitExecutorService commitExecutor;
 
-    private static final DataContainerChild<?, ?> OUTER_LIST =
-            ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+    private static final MapNode OUTER_LIST = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
             .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1))
             .build();
 
-    private static final DataContainerChild<?, ?> OUTER_LIST_2 =
-            ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
+    private static final MapNode OUTER_LIST_2 = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
             .withChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2))
             .build();
 
-    private static final NormalizedNode<?, ?> TEST_CONTAINER = Builders.containerBuilder()
+    private static final NormalizedNode TEST_CONTAINER = Builders.containerBuilder()
             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
             .withChild(OUTER_LIST)
             .build();
 
-    private static final NormalizedNode<?, ?> TEST_CONTAINER_2 = Builders.containerBuilder()
+    private static final NormalizedNode TEST_CONTAINER_2 = Builders.containerBuilder()
             .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
             .withChild(OUTER_LIST_2)
             .build();
@@ -93,10 +87,9 @@ public class DOMDataTreeListenerTest {
                 MoreExecutors.newDirectExecutorService());
         final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG",
                 MoreExecutors.newDirectExecutorService());
-        schemaContext = TestModel.createTestContext();
 
-        operStore.onGlobalContextUpdated(schemaContext);
-        configStore.onGlobalContextUpdated(schemaContext);
+        operStore.onModelContextUpdated(SCHEMA_CONTEXT);
+        configStore.onModelContextUpdated(SCHEMA_CONTEXT);
 
         final ImmutableMap<LogicalDatastoreType, DOMStore> stores = ImmutableMap.<LogicalDatastoreType,
                 DOMStore>builder()
@@ -142,10 +135,10 @@ public class DOMDataTreeListenerTest {
         latch.await(5, TimeUnit.SECONDS);
 
         assertEquals(1, listener.getReceivedChanges().size());
-        final Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
+        final List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
         assertEquals(1, changes.size());
 
-        final DataTreeCandidate candidate = changes.iterator().next();
+        final DataTreeCandidate candidate = changes.get(0);
         assertNotNull(candidate);
         final DataTreeCandidateNode candidateRoot = candidate.getRootNode();
         checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
@@ -174,10 +167,10 @@ public class DOMDataTreeListenerTest {
         latch.await(5, TimeUnit.SECONDS);
 
         assertEquals(2, listener.getReceivedChanges().size());
-        Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
+        List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
         assertEquals(1, changes.size());
 
-        DataTreeCandidate candidate = changes.iterator().next();
+        DataTreeCandidate candidate = changes.get(0);
         assertNotNull(candidate);
         DataTreeCandidateNode candidateRoot = candidate.getRootNode();
         checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
@@ -185,7 +178,7 @@ public class DOMDataTreeListenerTest {
         changes = listener.getReceivedChanges().get(1);
         assertEquals(1, changes.size());
 
-        candidate = changes.iterator().next();
+        candidate = changes.get(0);
         assertNotNull(candidate);
         candidateRoot = candidate.getRootNode();
         checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.WRITE, candidateRoot);
@@ -215,10 +208,10 @@ public class DOMDataTreeListenerTest {
         latch.await(5, TimeUnit.SECONDS);
 
         assertEquals(2, listener.getReceivedChanges().size());
-        Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
+        List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
         assertEquals(1, changes.size());
 
-        DataTreeCandidate candidate = changes.iterator().next();
+        DataTreeCandidate candidate = changes.get(0);
         assertNotNull(candidate);
         DataTreeCandidateNode candidateRoot = candidate.getRootNode();
         checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
@@ -226,7 +219,7 @@ public class DOMDataTreeListenerTest {
         changes = listener.getReceivedChanges().get(1);
         assertEquals(1, changes.size());
 
-        candidate = changes.iterator().next();
+        candidate = changes.get(0);
         assertNotNull(candidate);
         candidateRoot = candidate.getRootNode();
         checkChange(TEST_CONTAINER, null, ModificationType.DELETE, candidateRoot);
@@ -256,10 +249,10 @@ public class DOMDataTreeListenerTest {
         latch.await(5, TimeUnit.SECONDS);
 
         assertEquals(2, listener.getReceivedChanges().size());
-        Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
+        List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
         assertEquals(1, changes.size());
 
-        DataTreeCandidate candidate = changes.iterator().next();
+        DataTreeCandidate candidate = changes.get(0);
         assertNotNull(candidate);
         DataTreeCandidateNode candidateRoot = candidate.getRootNode();
         checkChange(null, TEST_CONTAINER, ModificationType.WRITE, candidateRoot);
@@ -267,7 +260,7 @@ public class DOMDataTreeListenerTest {
         changes = listener.getReceivedChanges().get(1);
         assertEquals(1, changes.size());
 
-        candidate = changes.iterator().next();
+        candidate = changes.get(0);
         assertNotNull(candidate);
         candidateRoot = candidate.getRootNode();
         checkChange(TEST_CONTAINER, TEST_CONTAINER_2, ModificationType.SUBTREE_MODIFIED, candidateRoot);
@@ -300,10 +293,10 @@ public class DOMDataTreeListenerTest {
         latch.await(1, TimeUnit.SECONDS);
 
         assertEquals(2, listener.getReceivedChanges().size());
-        Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
+        List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
         assertEquals(1, changes.size());
 
-        DataTreeCandidate candidate = changes.iterator().next();
+        DataTreeCandidate candidate = changes.get(0);
         assertNotNull(candidate);
         DataTreeCandidateNode candidateRoot = candidate.getRootNode();
         checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
@@ -311,7 +304,7 @@ public class DOMDataTreeListenerTest {
         changes = listener.getReceivedChanges().get(1);
         assertEquals(1, changes.size());
 
-        candidate = changes.iterator().next();
+        candidate = changes.get(0);
         assertNotNull(candidate);
         candidateRoot = candidate.getRootNode();
         checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, candidateRoot);
@@ -334,15 +327,12 @@ public class DOMDataTreeListenerTest {
         final ListenerRegistration<TestDataTreeListener> listenerReg =
                 dataTreeChangeService.registerDataTreeChangeListener(OUTER_LIST_DATA_TREE_ID, listener);
 
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId1 =
-                new YangInstanceIdentifier.NodeIdentifierWithPredicates(
-                        TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId2 =
-                new YangInstanceIdentifier.NodeIdentifierWithPredicates(
-                        TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
-        final YangInstanceIdentifier.NodeIdentifierWithPredicates outerListEntryId3 =
-                new YangInstanceIdentifier.NodeIdentifierWithPredicates(
-                        TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
+        final NodeIdentifierWithPredicates outerListEntryId1 =
+                NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
+        final NodeIdentifierWithPredicates outerListEntryId2 =
+                NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
+        final NodeIdentifierWithPredicates outerListEntryId3 =
+                NodeIdentifierWithPredicates.of(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 3);
 
         final MapEntryNode outerListEntry1 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);
         final MapEntryNode outerListEntry2 = ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 2);
@@ -364,10 +354,10 @@ public class DOMDataTreeListenerTest {
         latch.await(5, TimeUnit.SECONDS);
 
         assertEquals(2, listener.getReceivedChanges().size());
-        Collection<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
+        List<DataTreeCandidate> changes = listener.getReceivedChanges().get(0);
         assertEquals(1, changes.size());
 
-        DataTreeCandidate candidate = changes.iterator().next();
+        DataTreeCandidate candidate = changes.get(0);
         assertNotNull(candidate);
         DataTreeCandidateNode candidateRoot = candidate.getRootNode();
         checkChange(null, OUTER_LIST, ModificationType.WRITE, candidateRoot);
@@ -375,7 +365,7 @@ public class DOMDataTreeListenerTest {
         changes = listener.getReceivedChanges().get(1);
         assertEquals(1, changes.size());
 
-        candidate = changes.iterator().next();
+        candidate = changes.get(0);
         assertNotNull(candidate);
         candidateRoot = candidate.getRootNode();
         checkChange(OUTER_LIST, listAfter, ModificationType.SUBTREE_MODIFIED, candidateRoot);
@@ -388,10 +378,8 @@ public class DOMDataTreeListenerTest {
         listenerReg.close();
     }
 
-    private static void checkChange(final NormalizedNode<?, ?> expectedBefore,
-                                    final NormalizedNode<?, ?> expectedAfter,
-                                    final ModificationType expectedMod,
-                                    final DataTreeCandidateNode candidateNode) {
+    private static void checkChange(final NormalizedNode expectedBefore, final NormalizedNode expectedAfter,
+                                    final ModificationType expectedMod, final DataTreeCandidateNode candidateNode) {
         if (expectedBefore != null) {
             assertTrue(candidateNode.getDataBefore().isPresent());
             assertEquals(expectedBefore, candidateNode.getDataBefore().get());
@@ -428,8 +416,7 @@ public class DOMDataTreeListenerTest {
     }
 
     static class TestDataTreeListener implements DOMDataTreeChangeListener {
-
-        private final List<Collection<DataTreeCandidate>> receivedChanges = new ArrayList<>();
+        private final List<List<DataTreeCandidate>> receivedChanges = new ArrayList<>();
         private final CountDownLatch latch;
 
         TestDataTreeListener(final CountDownLatch latch) {
@@ -437,12 +424,17 @@ public class DOMDataTreeListenerTest {
         }
 
         @Override
-        public void onDataTreeChanged(final Collection<DataTreeCandidate> changes) {
+        public void onDataTreeChanged(final List<DataTreeCandidate> changes) {
             receivedChanges.add(changes);
             latch.countDown();
         }
 
-        public List<Collection<DataTreeCandidate>> getReceivedChanges() {
+        @Override
+        public void onInitialData() {
+            // noop
+        }
+
+        List<List<DataTreeCandidate>> getReceivedChanges() {
             return receivedChanges;
         }
     }