X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dom%2Fmdsal-dom-broker%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fdom%2Fbroker%2FDOMDataTreeListenerTest.java;h=7d506fe08d035ab8eb76ff8e9a711cf601c840b9;hb=c86b76bc49e598dbf62ee74be9518cef263d7586;hp=9c5848ca2211b5e13d1f414257991cbd2ed12ba1;hpb=5dc32173539f4571ddd636dab2b03d5460343116;p=mdsal.git diff --git a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMDataTreeListenerTest.java b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMDataTreeListenerTest.java index 9c5848ca22..7d506fe08d 100644 --- a/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMDataTreeListenerTest.java +++ b/dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMDataTreeListenerTest.java @@ -8,9 +8,7 @@ package org.opendaylight.mdsal.dom.broker; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.CONFIGURATION; import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL; @@ -19,7 +17,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,23 +32,21 @@ 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.YangInstanceIdentifier.NodeIdentifier; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild; 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.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 extends AbstractDatastoreTest { @@ -60,23 +55,21 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { 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() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) + private static final NormalizedNode TEST_CONTAINER = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) .withChild(OUTER_LIST) .build(); - private static final NormalizedNode TEST_CONTAINER_2 = Builders.containerBuilder() - .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME)) + private static final NormalizedNode TEST_CONTAINER_2 = Builders.containerBuilder() + .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)) .withChild(OUTER_LIST_2) .build(); @@ -93,8 +86,8 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { final InMemoryDOMDataStore configStore = new InMemoryDOMDataStore("CFG", MoreExecutors.newDirectExecutorService()); - operStore.onGlobalContextUpdated(SCHEMA_CONTEXT); - configStore.onGlobalContextUpdated(SCHEMA_CONTEXT); + operStore.onModelContextUpdated(SCHEMA_CONTEXT); + configStore.onModelContextUpdated(SCHEMA_CONTEXT); final ImmutableMap stores = ImmutableMap.builder() @@ -140,10 +133,10 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { latch.await(5, TimeUnit.SECONDS); assertEquals(1, listener.getReceivedChanges().size()); - final Collection changes = listener.getReceivedChanges().get(0); + final List 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); @@ -172,10 +165,10 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { latch.await(5, TimeUnit.SECONDS); assertEquals(2, listener.getReceivedChanges().size()); - Collection changes = listener.getReceivedChanges().get(0); + List 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); @@ -183,7 +176,7 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { 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); @@ -213,10 +206,10 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { latch.await(5, TimeUnit.SECONDS); assertEquals(2, listener.getReceivedChanges().size()); - Collection changes = listener.getReceivedChanges().get(0); + List 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); @@ -224,7 +217,7 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { 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); @@ -254,10 +247,10 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { latch.await(5, TimeUnit.SECONDS); assertEquals(2, listener.getReceivedChanges().size()); - Collection changes = listener.getReceivedChanges().get(0); + List 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); @@ -265,12 +258,12 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { 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); final DataTreeCandidateNode modifiedChild = candidateRoot.getModifiedChild( - new YangInstanceIdentifier.NodeIdentifier(TestModel.OUTER_LIST_QNAME)).get(); + new NodeIdentifier(TestModel.OUTER_LIST_QNAME)); checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild); listenerReg.close(); } @@ -298,10 +291,10 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { latch.await(1, TimeUnit.SECONDS); assertEquals(2, listener.getReceivedChanges().size()); - Collection changes = listener.getReceivedChanges().get(0); + List 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); @@ -309,7 +302,7 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { 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); @@ -359,10 +352,10 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { latch.await(5, TimeUnit.SECONDS); assertEquals(2, listener.getReceivedChanges().size()); - Collection changes = listener.getReceivedChanges().get(0); + List 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); @@ -370,42 +363,28 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { 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); - final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1).get(); + final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1); checkChange(outerListEntry1, null, ModificationType.DELETE, entry1Canditate); - final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2).get(); + final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2); checkChange(null, outerListEntry2, ModificationType.WRITE, entry2Canditate); - final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3).get(); + final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3); checkChange(null, outerListEntry3, ModificationType.WRITE, entry3Canditate); listenerReg.close(); } - 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()); - } else { - assertFalse(candidateNode.getDataBefore().isPresent()); - } - - if (expectedAfter != null) { - assertTrue(candidateNode.getDataAfter().isPresent()); - assertEquals(expectedAfter, candidateNode.getDataAfter().get()); - } else { - assertFalse(candidateNode.getDataAfter().isPresent()); - } - - assertEquals(expectedMod, candidateNode.getModificationType()); + private static void checkChange(final NormalizedNode expectedBefore, final NormalizedNode expectedAfter, + final ModificationType expectedMod, final DataTreeCandidateNode candidateNode) { + assertEquals(expectedBefore, candidateNode.dataBefore()); + assertEquals(expectedAfter, candidateNode.dataAfter()); + assertEquals(expectedMod, candidateNode.modificationType()); } private DOMDataTreeChangeService getDOMDataTreeChangeService() { - return domBroker.getExtensions().getInstance(DOMDataTreeChangeService.class); + return domBroker.extension(DOMDataTreeChangeService.class); } static class CommitExecutorService extends ForwardingExecutorService { @@ -423,8 +402,7 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { } static class TestDataTreeListener implements DOMDataTreeChangeListener { - - private final List> receivedChanges = new ArrayList<>(); + private final List> receivedChanges = new ArrayList<>(); private final CountDownLatch latch; TestDataTreeListener(final CountDownLatch latch) { @@ -432,12 +410,17 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest { } @Override - public void onDataTreeChanged(final Collection changes) { + public void onDataTreeChanged(final List changes) { receivedChanges.add(changes); latch.countDown(); } - public List> getReceivedChanges() { + @Override + public void onInitialData() { + // noop + } + + List> getReceivedChanges() { return receivedChanges; } }