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