Adjust for DataTreeCandidateNode API change 06/106606/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jun 2023 18:11:53 +0000 (20:11 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jun 2023 18:40:12 +0000 (20:40 +0200)
The return types have changed, adjust to that.

Change-Id: I97b60e91319c14664d7cfcad63b899cab792f87f
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/BindingStructuralType.java
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/BindingStructuralTypeTest.java
dom/mdsal-dom-broker/src/test/java/org/opendaylight/mdsal/dom/broker/DOMDataTreeListenerTest.java

index 5d9f7b3765514ce999987d815ac10ea1c461d6b3..71aeb9b2923fba2577dba0bc730d698283d9c4b7 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.mdsal.binding.dom.adapter;
 
 import com.google.common.annotations.Beta;
-import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -68,14 +67,11 @@ public enum BindingStructuralType {
     UNKNOWN;
 
     public static BindingStructuralType from(final DataTreeCandidateNode domChildNode) {
-        Optional<NormalizedNode> dataBased = domChildNode.getDataAfter();
-        if (!dataBased.isPresent()) {
-            dataBased = domChildNode.getDataBefore();
+        var dataBased = domChildNode.dataAfter();
+        if (dataBased == null) {
+            dataBased = domChildNode.dataBefore();
         }
-        if (dataBased.isPresent()) {
-            return from(dataBased.orElseThrow());
-        }
-        return from(domChildNode.getIdentifier());
+        return dataBased != null ? from(dataBased) : from(domChildNode.name());
     }
 
     private static BindingStructuralType from(final PathArgument identifier) {
@@ -105,12 +101,12 @@ public enum BindingStructuralType {
     }
 
     public static BindingStructuralType recursiveFrom(final DataTreeCandidateNode node) {
-        final BindingStructuralType type = BindingStructuralType.from(node);
+        final var type = BindingStructuralType.from(node);
         return switch (type) {
             case INVISIBLE_CONTAINER, INVISIBLE_LIST -> {
                 // This node is invisible, try to resolve using a child node
-                for (final DataTreeCandidateNode child : node.getChildNodes()) {
-                    final BindingStructuralType childType = recursiveFrom(child);
+                for (var child : node.childNodes()) {
+                    final var childType = recursiveFrom(child);
                     yield switch (childType) {
                             case INVISIBLE_CONTAINER, INVISIBLE_LIST ->
                                 // Invisible nodes are not addressable
index 4469c0c07646f7047b4ba3a226a18023dfddf270..eeb519109fabc338be49b7140044eca7c363da23 100644 (file)
@@ -9,21 +9,24 @@ package org.opendaylight.mdsal.binding.dom.adapter;
 
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
 
-import java.util.Optional;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
 
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class BindingStructuralTypeTest {
+    @Mock
+    private NormalizedNode normalizedNode;
+    @Mock
+    private DataTreeCandidateNode dataTreeCandidateNode;
+
     @Test
-    public void basicTest() throws Exception {
-        final NormalizedNode normalizedNode = mock(NormalizedNode.class);
-        final Optional<?> optional = Optional.of(normalizedNode);
-        final DataTreeCandidateNode dataTreeCandidateNode = mock(DataTreeCandidateNode.class);
-        doReturn(optional).when(dataTreeCandidateNode).getDataAfter();
-        doReturn(optional).when(dataTreeCandidateNode).getDataBefore();
+    public void basicTest() {
+        doReturn(normalizedNode).when(dataTreeCandidateNode).dataBefore();
         assertEquals(BindingStructuralType.UNKNOWN, BindingStructuralType.from(dataTreeCandidateNode));
     }
 }
\ No newline at end of file
index 6cc6775ad92a196a9d8d2c6118cb7c64e1fa1ea2..6524e46da82b34b5df0bf0512e56bfd0a9014d53 100644 (file)
@@ -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;
 
@@ -39,7 +37,7 @@ 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.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
@@ -66,12 +64,12 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest {
             .build();
 
     private static final NormalizedNode TEST_CONTAINER = Builders.containerBuilder()
-            .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TestModel.TEST_QNAME))
+            .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))
+            .withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
             .withChild(OUTER_LIST_2)
             .build();
 
@@ -265,7 +263,7 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest {
         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)).orElseThrow();
+                new NodeIdentifier(TestModel.OUTER_LIST_QNAME));
         checkChange(OUTER_LIST, OUTER_LIST_2, ModificationType.WRITE, modifiedChild);
         listenerReg.close();
     }
@@ -369,32 +367,20 @@ public class DOMDataTreeListenerTest extends AbstractDatastoreTest {
         assertNotNull(candidate);
         candidateRoot = candidate.getRootNode();
         checkChange(OUTER_LIST, listAfter, ModificationType.SUBTREE_MODIFIED, candidateRoot);
-        final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1).orElseThrow();
+        final DataTreeCandidateNode entry1Canditate = candidateRoot.getModifiedChild(outerListEntryId1);
         checkChange(outerListEntry1, null, ModificationType.DELETE, entry1Canditate);
-        final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2).orElseThrow();
+        final DataTreeCandidateNode entry2Canditate = candidateRoot.getModifiedChild(outerListEntryId2);
         checkChange(null, outerListEntry2, ModificationType.WRITE, entry2Canditate);
-        final DataTreeCandidateNode entry3Canditate = candidateRoot.getModifiedChild(outerListEntryId3).orElseThrow();
+        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().orElseThrow());
-        } else {
-            assertFalse(candidateNode.getDataBefore().isPresent());
-        }
-
-        if (expectedAfter != null) {
-            assertTrue(candidateNode.getDataAfter().isPresent());
-            assertEquals(expectedAfter, candidateNode.getDataAfter().orElseThrow());
-        } else {
-            assertFalse(candidateNode.getDataAfter().isPresent());
-        }
-
-        assertEquals(expectedMod, candidateNode.getModificationType());
+        assertEquals(expectedBefore, candidateNode.dataBefore());
+        assertEquals(expectedAfter, candidateNode.dataAfter());
+        assertEquals(expectedMod, candidateNode.modificationType());
     }
 
     private DOMDataTreeChangeService getDOMDataTreeChangeService() {