Integrate MRI projects for Neon
[netconf.git] / netconf / callhome-protocol / src / test / java / org / opendaylight / netconf / callhome / protocol / MinaSshNettyChannelTest.java
index 17193a238281311e1e4c794b04aaa9a68901fe89..805b921921cc963021bbcb9033c3ba807eee2c89 100644 (file)
@@ -5,11 +5,10 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.netconf.callhome.protocol;
 
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
@@ -21,42 +20,41 @@ import io.netty.channel.ChannelHandler;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelOutboundHandlerAdapter;
 import io.netty.channel.ChannelPromise;
-import org.apache.sshd.ClientChannel;
-import org.apache.sshd.ClientSession;
-import org.apache.sshd.common.future.SshFutureListener;
+import java.io.IOException;
+import org.apache.sshd.client.channel.ClientChannel;
+import org.apache.sshd.client.session.ClientSession;
 import org.apache.sshd.common.io.IoInputStream;
 import org.apache.sshd.common.io.IoOutputStream;
 import org.apache.sshd.common.io.IoReadFuture;
 import org.apache.sshd.common.io.IoWriteFuture;
-import org.apache.sshd.common.util.Buffer;
+import org.apache.sshd.common.util.buffer.Buffer;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.mockito.Mockito;
 
-
 public class MinaSshNettyChannelTest {
-    CallHomeSessionContext mockContext;
-    ClientSession mockSession;
-    ClientChannel mockChannel;
-    MinaSshNettyChannel instance;
+    private CallHomeSessionContext mockContext;
+    private ClientSession mockSession;
+    private ClientChannel mockChannel;
+    private MinaSshNettyChannel instance;
 
     @Before
-    public void setup() {
+    public void setup() throws IOException {
         IoReadFuture mockFuture = mock(IoReadFuture.class);
         IoInputStream mockIn = mock(IoInputStream.class);
         Mockito.doReturn(mockFuture).when(mockIn).read(any(Buffer.class));
-        IoOutputStream mockOut = mock(IoOutputStream.class);
         mockContext = mock(CallHomeSessionContext.class);
         mockSession = mock(ClientSession.class);
         mockChannel = mock(ClientChannel.class);
         Mockito.doReturn(mockIn).when(mockChannel).getAsyncOut();
+
+        IoOutputStream mockOut = mock(IoOutputStream.class);
         Mockito.doReturn(mockOut).when(mockChannel).getAsyncIn();
 
         IoWriteFuture mockWrFuture = mock(IoWriteFuture.class);
         Mockito.doReturn(false).when(mockOut).isClosed();
         Mockito.doReturn(false).when(mockOut).isClosing();
-        Mockito.doReturn(mockWrFuture).when(mockOut).write(any(Buffer.class));
+        Mockito.doReturn(mockWrFuture).when(mockOut).writePacket(any(Buffer.class));
         Mockito.doReturn(null).when(mockWrFuture).addListener(any());
 
         Mockito.doReturn(mockFuture).when(mockFuture).addListener(Mockito.any());
@@ -80,9 +78,6 @@ public class MinaSshNettyChannelTest {
         Mockito.doReturn(mockHandler).when(ctx).handler();
         ChannelPromise promise = mock(ChannelPromise.class);
 
-        ByteBufAllocator mockAlloc = mock(ByteBufAllocator.class);
-        ByteBuf bytes = new EmptyByteBuf(mockAlloc);
-
         // we would really like to just verify that the async handler write() was
         // called but it is a final class, so no mocking. instead we set up the
         // mock channel to have no async input, which will cause a failure later
@@ -97,6 +92,8 @@ public class MinaSshNettyChannelTest {
 
         // when
         ChannelOutboundHandlerAdapter outadapter = (ChannelOutboundHandlerAdapter) instance.pipeline().first();
+        ByteBufAllocator mockAlloc = mock(ByteBufAllocator.class);
+        ByteBuf bytes = new EmptyByteBuf(mockAlloc);
         outadapter.write(ctx, bytes, promise);
 
         // then