Enforce stubbing in netconf-topology 78/107278/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 5 Aug 2023 21:37:02 +0000 (23:37 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 7 Aug 2023 08:28:31 +0000 (10:28 +0200)
Fixup existing stubbing and switch Mockito configuration to throw
exception when an unstubbed method is invoked.

Change-Id: Ic854ae949b454e780f267b112c9939c20cbfe44d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit e129dfb7393b4c4cbee911066bc901f3f4b4a0ec)

apps/netconf-topology/pom.xml
apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java
apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfTopologyRPCProviderTest.java

index c89bf4da39e41efadfedc481248d95500cd076dd..0243f63f73e5fe6f245eda2217c874025e45c4f1 100644 (file)
             <groupId>org.awaitility</groupId>
             <artifactId>awaitility</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>mockito-configuration</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.opendaylight.mdsal</groupId>
             <artifactId>mdsal-binding-test-utils</artifactId>
index a75d462e15aab2feabadbe1215480d8b925bb80d..db38ad754d0f6f6971a2444e3b79b3c6bcd07c93 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.netconf.topology.spi;
 
 import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
@@ -30,6 +31,7 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.netconf.client.mdsal.NetconfDeviceCapabilities;
 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev221225.NetconfNode;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
@@ -61,7 +63,8 @@ public class NetconfDeviceTopologyAdapterTest {
     public void before() {
         doReturn(mockTx).when(mockChain).newWriteOnlyTransaction();
         // FIXME: exact match
-        doNothing().when(mockTx).put(any(LogicalDatastoreType.class), any(InstanceIdentifier.class), any(Node.class));
+        doNothing().when(mockTx).put(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class),
+            any(Node.class));
         doReturn("test transaction").when(mockTx).getIdentifier();
         doReturn(CommitInfo.emptyFluentFuture()).when(mockTx).commit();
 
@@ -71,12 +74,18 @@ public class NetconfDeviceTopologyAdapterTest {
 
     @Test
     public void replaceChainIfFailed() {
+        doNothing().when(mockChain).close();
+        doReturn("mockChain").when(mockChain).toString();
         adapter.onTransactionChainFailed(mockChain, mockTx, new Exception("chain failed"));
         verify(mockBroker, times(2)).createMergingTransactionChain(any());
     }
 
     @Test
     public void testFailedDevice() {
+        // FIXME: exact match
+        doNothing().when(mockTx).mergeParentStructurePut(eq(LogicalDatastoreType.OPERATIONAL),
+            any(InstanceIdentifier.class), any(NetconfNode.class));
+
         adapter.setDeviceAsFailed(null);
 
         verify(mockChain, times(2)).newWriteOnlyTransaction();
@@ -87,6 +96,8 @@ public class NetconfDeviceTopologyAdapterTest {
 
     @Test
     public void testDeviceUpdate() throws Exception {
+        doNothing().when(mockTx).mergeParentStructurePut(eq(LogicalDatastoreType.OPERATIONAL),
+            any(InstanceIdentifier.class), any(NetconfNode.class));
         adapter.updateDeviceData(true, NetconfDeviceCapabilities.empty(), new SessionIdType(Uint32.ONE));
 
         verify(mockChain, times(2)).newWriteOnlyTransaction();
@@ -96,6 +107,9 @@ public class NetconfDeviceTopologyAdapterTest {
 
     @Test
     public void testRemoveDeviceConfiguration() throws Exception {
+        // FIXME: exact match
+        doNothing().when(mockTx).delete(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
+        doNothing().when(mockChain).close();
         listeners.getValue().onTransactionChainSuccessful(mockChain);
         adapter.close();
 
index 760e47f7efaa4643245b696c8d741ebbb6b744c5..75b388de76b2be3fb516496d88e9a296dcf07f03 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.netconf.topology.spi;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.doReturn;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -52,7 +52,7 @@ public class NetconfTopologyRPCProviderTest {
 
     @Before
     public void setUp() {
-        when(encryptionService.encrypt(TEST_PWD)).thenReturn(ENC_PWD);
+        doReturn(ENC_PWD).when(encryptionService).encrypt(TEST_PWD);
         rpcProvider = new NetconfTopologyRPCProvider(dataBroker, encryptionService, TOPOLOGY_ID);
     }
 
@@ -99,8 +99,7 @@ public class NetconfTopologyRPCProviderTest {
             .setHost(new Host(new IpAddress(new Ipv4Address("10.18.16.188"))))
             .setPort(new PortNumber(Uint16.valueOf(830)))
             .setTcpOnly(Boolean.FALSE)
-            // FIXME: do we really want 'toString()' here?
-            .setNodeId(NODE_ID.toString())
+            .setNodeId(NODE_ID.getValue())
             .build();
     }
 }