Remove netconf from commons/opendaylight pom
[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 static org.mockito.Matchers.any;
12 import static org.mockito.Matchers.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;
17
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.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler;
24 import org.opendaylight.protocol.framework.SessionListenerFactory;
25 import org.opendaylight.protocol.framework.SessionNegotiator;
26
27 public class SshClientChannelInitializerTest {
28     @Test
29     public void test() throws Exception {
30
31         AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class);
32         NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class);
33         NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
34
35         SessionNegotiator<?> sessionNegotiator = mock(SessionNegotiator.class);
36         doReturn("").when(sessionNegotiator).toString();
37         doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(any(SessionListenerFactory.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
46         Promise<NetconfClientSession> promise = mock(Promise.class);
47         doReturn("").when(promise).toString();
48
49         SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler, negotiatorFactory,
50                 sessionListener);
51         initializer.initialize(channel, promise);
52         verify(pipeline, times(1)).addFirst(any(ChannelHandler.class));
53     }
54 }