Merge "Bug#1854 - Exit command in console causing OOM."
[controller.git] / opendaylight / netconf / netconf-client / src / test / java / org / opendaylight / controller / 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
9 package org.opendaylight.controller.netconf.client;
10
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;
19
20 import static org.mockito.Matchers.any;
21 import static org.mockito.Matchers.anyString;
22 import static org.mockito.Mockito.*;
23
24 public class SshClientChannelInitializerTest {
25     @Test
26     public void test() throws Exception {
27
28         AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
29         NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class);
30         NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
31
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));
42
43         Promise<NetconfClientSession> promise = mock(Promise.class);
44         doReturn("").when(promise).toString();
45
46         SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler, negotiatorFactory,
47                 sessionListener);
48         initializer.initialize(channel, promise);
49         verify(pipeline, times(1)).addFirst(any(ChannelHandler.class));
50     }
51 }