Remove NetconfTopology
[netconf.git] / apps / netconf-topology-impl / src / test / java / org / opendaylight / netconf / topology / impl / NetconfTopologyImplTest.java
index e1939535b49e255731c3f83ed370c56c42c6c35d..7c37b77e0fef279f41bf858c893d76317fec2c3f 100644 (file)
@@ -11,16 +11,14 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
 
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.MoreExecutors;
 import io.netty.util.concurrent.EventExecutor;
 import java.util.Collection;
@@ -43,10 +41,13 @@ import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.netconf.client.NetconfClientDispatcher;
 import org.opendaylight.netconf.client.NetconfClientSessionListener;
+import org.opendaylight.netconf.client.SslHandlerFactory;
 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.netconf.client.mdsal.api.BaseNetconfSchemas;
+import org.opendaylight.netconf.client.mdsal.api.CredentialProvider;
 import org.opendaylight.netconf.client.mdsal.api.SchemaResourceManager;
+import org.opendaylight.netconf.client.mdsal.api.SslHandlerFactoryProvider;
 import org.opendaylight.netconf.client.mdsal.impl.DefaultBaseNetconfSchemas;
 import org.opendaylight.netconf.topology.spi.AbstractNetconfTopology;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Host;
@@ -70,7 +71,6 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.common.Decimal64;
-import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.Uint16;
 import org.opendaylight.yangtools.yang.common.Uint32;
 import org.opendaylight.yangtools.yang.parser.api.YangParserException;
@@ -100,6 +100,10 @@ public class NetconfTopologyImplTest {
     @Mock
     private RpcProviderService rpcProviderService;
     @Mock
+    private CredentialProvider credentialProvider;
+    @Mock
+    private SslHandlerFactoryProvider sslHandlerFactoryProvider;
+    @Mock
     private WriteTransaction wtx;
 
     private TestingNetconfTopologyImpl topology;
@@ -113,7 +117,7 @@ public class NetconfTopologyImplTest {
 
         topology = new TestingNetconfTopologyImpl(TOPOLOGY_ID, mockedClientDispatcher, mockedEventExecutor,
             mockedKeepaliveExecutor, mockedProcessingExecutor, mockedResourceManager, dataBroker, mountPointService,
-            encryptionService, rpcProviderService);
+            encryptionService, rpcProviderService, credentialProvider, sslHandlerFactoryProvider);
         //verify initialization of topology
         verify(wtx).merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.builder(NetworkTopology.class)
                 .child(Topology.class, new TopologyKey(new TopologyId(TOPOLOGY_ID))).build(),
@@ -125,11 +129,11 @@ public class NetconfTopologyImplTest {
     @Test
     public void testOnDataTreeChange() {
         final DataObjectModification<Node> newNode = mock(DataObjectModification.class);
-        when(newNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
+        doReturn(DataObjectModification.ModificationType.WRITE).when(newNode).getModificationType();
 
         NodeKey key = new NodeKey(NODE_ID);
         PathArgument pa = IdentifiableItem.of(Node.class, key);
-        when(newNode.getIdentifier()).thenReturn(pa);
+        doReturn(pa).when(newNode).getIdentifier();
 
         final NodeBuilder nn = new NodeBuilder()
                 .withKey(key)
@@ -146,26 +150,24 @@ public class NetconfTopologyImplTest {
                         .setPassword("testpassword")
                         .build())
                     .build());
-
-        when(newNode.getDataAfter()).thenReturn(nn.build());
+        doReturn(nn.build()).when(newNode).getDataAfter();
 
         final Collection<DataTreeModification<Node>> changes = new HashSet<>();
         final DataTreeModification<Node> ch = mock(DataTreeModification.class);
-        when(ch.getRootNode()).thenReturn(newNode);
+        doReturn(newNode).when(ch).getRootNode();
         changes.add(ch);
         spyTopology.onDataTreeChanged(changes);
-        verify(spyTopology).connectNode(NetconfTopologyImpl.getNodeId(pa), nn.build());
+        verify(spyTopology).ensureNode(nn.build());
 
-        when(newNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
+        doReturn(DataObjectModification.ModificationType.DELETE).when(newNode).getModificationType();
         spyTopology.onDataTreeChanged(changes);
-        verify(spyTopology).disconnectNode(NetconfTopologyImpl.getNodeId(pa));
+        verify(spyTopology).deleteNode(NetconfTopologyImpl.getNodeId(pa));
 
-        when(newNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
+        doReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED).when(newNode).getModificationType();
         spyTopology.onDataTreeChanged(changes);
 
-        //one in previous creating and deleting node and one in updating
-        verify(spyTopology, times(2)).disconnectNode(NetconfTopologyImpl.getNodeId(pa));
-        verify(spyTopology, times(2)).connectNode(NetconfTopologyImpl.getNodeId(pa), nn.build());
+        // one in previous creating and deleting node and one in updating
+        verify(spyTopology, times(2)).ensureNode(nn.build());
     }
 
     @Test
@@ -202,12 +204,15 @@ public class NetconfTopologyImplTest {
         assertNotNull(configuration3.getAuthHandler());
         assertNull(configuration3.getSslHandlerFactory());
 
+        final var sslHandlerFactory = mock(SslHandlerFactory.class);
+        doReturn(sslHandlerFactory).when(sslHandlerFactoryProvider).getSslHandlerFactory(null);
+
         final NetconfReconnectingClientConfiguration configuration4 =
                 spyTopology.getClientConfig(sessionListener, nodeBuilder
                         .setProtocol(new ProtocolBuilder().setName(Name.TLS).build()).build(), NODE_ID);
         assertEquals(NetconfClientConfiguration.NetconfClientProtocol.TLS, configuration4.getProtocol());
         assertNull(configuration4.getAuthHandler());
-        assertNotNull(configuration4.getSslHandlerFactory());
+        assertSame(sslHandlerFactory, configuration4.getSslHandlerFactory());
     }
 
     public static class TestingNetconfTopologyImpl extends NetconfTopologyImpl {
@@ -228,20 +233,22 @@ public class NetconfTopologyImplTest {
                                           final SchemaResourceManager schemaRepositoryProvider,
                                           final DataBroker dataBroker, final DOMMountPointService mountPointService,
                                           final AAAEncryptionService encryptionService,
-                                          final RpcProviderService rpcProviderService) {
-            super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor,
-                  processingExecutor, schemaRepositoryProvider, dataBroker,
-                  mountPointService, encryptionService, rpcProviderService, BASE_SCHEMAS, null);
+                                          final RpcProviderService rpcProviderService,
+                                          final CredentialProvider credentialProvider,
+                                          final SslHandlerFactoryProvider sslHandlerFactoryProvider) {
+            super(topologyId, clientDispatcher, eventExecutor, keepaliveExecutor, processingExecutor,
+                schemaRepositoryProvider, dataBroker, mountPointService, encryptionService, rpcProviderService,
+                BASE_SCHEMAS, credentialProvider, sslHandlerFactoryProvider, null);
         }
 
         @Override
-        public ListenableFuture<Empty> connectNode(final NodeId nodeId, final Node configNode) {
-            return Futures.immediateFuture(Empty.value());
+        public void ensureNode(final Node configNode) {
+            // No-op
         }
 
         @Override
-        public ListenableFuture<Empty> disconnectNode(final NodeId nodeId) {
-            return Futures.immediateFuture(Empty.value());
+        public void deleteNode(final NodeId nodeId) {
+            // No-op
         }
     }