2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.client;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.ArgumentMatchers.anyString;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
17 import io.netty.channel.Channel;
18 import io.netty.channel.ChannelHandler;
19 import io.netty.channel.ChannelPipeline;
20 import io.netty.util.concurrent.Promise;
21 import org.junit.Test;
22 import org.opendaylight.netconf.api.NetconfSessionListenerFactory;
23 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
25 public class SshClientChannelInitializerTest {
27 public void test() throws Exception {
29 AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
30 NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class);
31 NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
33 NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class);
34 doReturn("").when(sessionNegotiator).toString();
35 doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(
36 any(NetconfSessionListenerFactory.class), any(Channel.class), any(Promise.class));
37 ChannelPipeline pipeline = mock(ChannelPipeline.class);
38 doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
39 Channel channel = mock(Channel.class);
40 doReturn(pipeline).when(channel).pipeline();
41 doReturn("").when(channel).toString();
42 doReturn(pipeline).when(pipeline).addFirst(any(ChannelHandler.class));
43 doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class));
45 Promise<NetconfClientSession> promise = mock(Promise.class);
46 doReturn("").when(promise).toString();
48 SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler,
49 negotiatorFactory, sessionListener);
50 initializer.initialize(channel, promise);
51 verify(pipeline, times(1)).addFirst(any(ChannelHandler.class));