From: Robert Varga Date: Sat, 5 Aug 2023 21:37:02 +0000 (+0200) Subject: Enforce stubbing in netconf-topology X-Git-Tag: v6.0.1~2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=044fe2ab870acc2faeb711157b44e618d2563f67;p=netconf.git Enforce stubbing in netconf-topology Fixup existing stubbing and switch Mockito configuration to throw exception when an unstubbed method is invoked. Change-Id: Ic854ae949b454e780f267b112c9939c20cbfe44d Signed-off-by: Robert Varga (cherry picked from commit e129dfb7393b4c4cbee911066bc901f3f4b4a0ec) --- diff --git a/apps/netconf-topology/pom.xml b/apps/netconf-topology/pom.xml index c89bf4da39..0243f63f73 100644 --- a/apps/netconf-topology/pom.xml +++ b/apps/netconf-topology/pom.xml @@ -49,6 +49,10 @@ org.awaitility awaitility + + org.opendaylight.yangtools + mockito-configuration + org.opendaylight.mdsal mdsal-binding-test-utils diff --git a/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java b/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java index a75d462e15..db38ad754d 100644 --- a/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java +++ b/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfDeviceTopologyAdapterTest.java @@ -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(); diff --git a/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfTopologyRPCProviderTest.java b/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfTopologyRPCProviderTest.java index 760e47f7ef..75b388de76 100644 --- a/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfTopologyRPCProviderTest.java +++ b/apps/netconf-topology/src/test/java/org/opendaylight/netconf/topology/spi/NetconfTopologyRPCProviderTest.java @@ -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(); } }