Move netconf-dom-api
[netconf.git] / netconf / netconf-client / src / test / java / org / opendaylight / netconf / client / SshClientChannelInitializerTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.client;
9
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;
16
17 import io.netty.channel.Channel;
18 import io.netty.channel.ChannelConfig;
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.api.NetconfSessionListenerFactory;
24 import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
25
26 public class SshClientChannelInitializerTest {
27     @Test
28     public void test() throws Exception {
29
30         AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
31         NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class);
32         NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
33
34         NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class);
35         doReturn("").when(sessionNegotiator).toString();
36         doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(
37             any(NetconfSessionListenerFactory.class), any(Channel.class), any(Promise.class));
38         ChannelPipeline pipeline = mock(ChannelPipeline.class);
39         doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
40         Channel channel = mock(Channel.class);
41         doReturn(pipeline).when(channel).pipeline();
42         doReturn("").when(channel).toString();
43         doReturn(pipeline).when(pipeline).addFirst(any(ChannelHandler.class));
44         doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class));
45         ChannelConfig channelConfig = mock(ChannelConfig.class);
46         doReturn(channelConfig).when(channel).config();
47         doReturn(1L).when(negotiatorFactory).getConnectionTimeoutMillis();
48         doReturn(channelConfig).when(channelConfig).setConnectTimeoutMillis(1);
49
50         Promise<NetconfClientSession> promise = mock(Promise.class);
51         doReturn("").when(promise).toString();
52
53         SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler,
54                 negotiatorFactory, sessionListener);
55         initializer.initialize(channel, promise);
56         verify(pipeline, times(1)).addFirst(any(ChannelHandler.class));
57     }
58 }