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
9 package org.opendaylight.netconf.client;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.anyString;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
18 import io.netty.channel.Channel;
19 import io.netty.channel.ChannelHandler;
20 import io.netty.channel.ChannelPipeline;
21 import io.netty.util.concurrent.Promise;
22 import org.junit.Test;
23 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
24 import org.opendaylight.protocol.framework.SessionListenerFactory;
25 import org.opendaylight.protocol.framework.SessionNegotiator;
27 public class SshClientChannelInitializerTest {
29 public void test() throws Exception {
31 AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
32 NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class);
33 NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
35 SessionNegotiator<?> sessionNegotiator = mock(SessionNegotiator.class);
36 doReturn("").when(sessionNegotiator).toString();
37 doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(any(SessionListenerFactory.class),
38 any(Channel.class), any(Promise.class));
39 ChannelPipeline pipeline = mock(ChannelPipeline.class);
40 doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
41 Channel channel = mock(Channel.class);
42 doReturn(pipeline).when(channel).pipeline();
43 doReturn("").when(channel).toString();
44 doReturn(pipeline).when(pipeline).addFirst(any(ChannelHandler.class));
45 doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class));
47 Promise<NetconfClientSession> promise = mock(Promise.class);
48 doReturn("").when(promise).toString();
50 SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler,
51 negotiatorFactory, sessionListener);
52 initializer.initialize(channel, promise);
53 verify(pipeline, times(1)).addFirst(any(ChannelHandler.class));