000cfbef3d039a643125ca032f93178c027576b2
[netconf.git] / netconf / netconf-client / src / test / java / org / opendaylight / netconf / client / TcpClientChannelInitializerTest.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.ChannelHandler;
19 import io.netty.channel.ChannelPipeline;
20 import io.netty.util.concurrent.Promise;
21 import org.junit.Test;
22 import org.opendaylight.netconf.api.NetconfSessionListenerFactory;
23
24 public class TcpClientChannelInitializerTest {
25     @Test
26     public void testInitializeSessionNegotiator() throws Exception {
27         NetconfClientSessionNegotiatorFactory factory = mock(NetconfClientSessionNegotiatorFactory.class);
28         NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class);
29         doReturn("").when(sessionNegotiator).toString();
30         doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(NetconfSessionListenerFactory.class),
31                 any(Channel.class), any(Promise.class));
32         NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class);
33         final TcpClientChannelInitializer initializer = new TcpClientChannelInitializer(factory, listener);
34         ChannelPipeline pipeline = mock(ChannelPipeline.class);
35         doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
36         Channel channel = mock(Channel.class);
37         doReturn(pipeline).when(channel).pipeline();
38         doReturn("").when(channel).toString();
39
40         Promise<NetconfClientSession> promise = mock(Promise.class);
41         doReturn("").when(promise).toString();
42
43         initializer.initializeSessionNegotiator(channel, promise);
44         verify(pipeline, times(1)).addAfter(anyString(), anyString(), any(ChannelHandler.class));
45     }
46 }