Teach netconf-client abount maximum incoming chunk size
[netconf.git] / netconf / netconf-client / src / test / java / org / opendaylight / netconf / client / NetconfClientDispatcherImplTest.java
index 82172d771ec15676ed33a8b909c8c2d33d0f0bea..62a2b33eb9c81299c6f289af2ca7d1bb89beebbc 100644 (file)
@@ -9,7 +9,7 @@
 package org.opendaylight.netconf.client;
 
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doReturn;
 
 import io.netty.channel.Channel;
@@ -23,13 +23,14 @@ import java.net.InetSocketAddress;
 import java.util.concurrent.Future;
 import org.junit.Test;
 import org.mockito.Mockito;
-import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
 import org.opendaylight.netconf.api.messages.NetconfHelloMessageAdditionalHeader;
 import org.opendaylight.netconf.client.conf.NetconfClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfiguration;
 import org.opendaylight.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
-import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
+import org.opendaylight.netconf.nettyutil.ReconnectFuture;
+import org.opendaylight.netconf.nettyutil.ReconnectStrategy;
+import org.opendaylight.netconf.nettyutil.ReconnectStrategyFactory;
+import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
 
 public class NetconfClientDispatcherImplTest {
     @Test
@@ -47,9 +48,12 @@ public class NetconfClientDispatcherImplTest {
         ChannelPromise promise = Mockito.mock(ChannelPromise.class);
         doReturn(promise).when(chf).addListener(any(GenericFutureListener.class));
         doReturn(thr).when(chf).cause();
+        doReturn(true).when(chf).isDone();
+        doReturn(false).when(chf).isSuccess();
 
         Long timeout = 200L;
-        NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
+        NetconfHelloMessageAdditionalHeader header =
+                new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id");
         NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener();
         InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830);
         ReconnectStrategyFactory reconnectStrategyFactory = Mockito.mock(ReconnectStrategyFactory.class);
@@ -62,37 +66,53 @@ public class NetconfClientDispatcherImplTest {
         doReturn("").when(reconnectStrategyFactory).toString();
         doReturn(reconnect).when(reconnectStrategyFactory).createReconnectStrategy();
 
-        NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create().
-                withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH).
-                withAddress(address).
-                withConnectionTimeoutMillis(timeout).
-                withReconnectStrategy(reconnect).
-                withAdditionalHeader(header).
-                withSessionListener(listener).
-                withConnectStrategyFactory(reconnectStrategyFactory).
-                withAuthHandler(handler).build();
-
-        NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create().
-                withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP).
-                withAddress(address).
-                withConnectionTimeoutMillis(timeout).
-                withReconnectStrategy(reconnect).
-                withAdditionalHeader(header).
-                withSessionListener(listener).
-                withConnectStrategyFactory(reconnectStrategyFactory).
-                withAuthHandler(handler).build();
+        NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create()
+                .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH)
+                .withAddress(address)
+                .withConnectionTimeoutMillis(timeout)
+                .withReconnectStrategy(reconnect)
+                .withAdditionalHeader(header)
+                .withSessionListener(listener)
+                .withConnectStrategyFactory(reconnectStrategyFactory)
+                .withAuthHandler(handler).build();
+
+        NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create()
+                .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP)
+                .withAddress(address)
+                .withConnectionTimeoutMillis(timeout)
+                .withReconnectStrategy(reconnect)
+                .withAdditionalHeader(header)
+                .withSessionListener(listener)
+                .withConnectStrategyFactory(reconnectStrategyFactory)
+                .withAuthHandler(handler).build();
 
         NetconfClientDispatcherImpl dispatcher = new NetconfClientDispatcherImpl(bossGroup, workerGroup, timer);
         Future<NetconfClientSession> sshSession = dispatcher.createClient(cfg);
         Future<NetconfClientSession> tcpSession = dispatcher.createClient(cfg2);
 
-        Future<Void> sshReconn = dispatcher.createReconnectingClient(cfg);
-        Future<Void> tcpReconn = dispatcher.createReconnectingClient(cfg2);
+        ReconnectFuture sshReconn = dispatcher.createReconnectingClient(cfg);
+        final ReconnectFuture tcpReconn = dispatcher.createReconnectingClient(cfg2);
 
         assertNotNull(sshSession);
         assertNotNull(tcpSession);
         assertNotNull(sshReconn);
         assertNotNull(tcpReconn);
 
+        SslHandlerFactory sslHandlerFactory = Mockito.mock(SslHandlerFactory.class);
+        NetconfReconnectingClientConfiguration cfg3 = NetconfReconnectingClientConfigurationBuilder.create()
+                .withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TLS)
+                .withAddress(address)
+                .withConnectionTimeoutMillis(timeout)
+                .withReconnectStrategy(reconnect)
+                .withAdditionalHeader(header)
+                .withSessionListener(listener)
+                .withConnectStrategyFactory(reconnectStrategyFactory)
+                .withSslHandlerFactory(sslHandlerFactory).build();
+
+        Future<NetconfClientSession> tlsSession = dispatcher.createClient(cfg3);
+        ReconnectFuture tlsReconn = dispatcher.createReconnectingClient(cfg3);
+
+        assertNotNull(tlsSession);
+        assertNotNull(tlsReconn);
     }
 }