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
8 package org.opendaylight.netconf.client;
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;
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;
25 public class TcpClientChannelInitializerTest {
27 public void testInitializeSessionNegotiator() throws Exception {
28 NetconfClientSessionNegotiatorFactory factory = mock(NetconfClientSessionNegotiatorFactory.class);
29 NetconfClientSessionNegotiator sessionNegotiator = mock(NetconfClientSessionNegotiator.class);
30 doReturn("").when(sessionNegotiator).toString();
31 doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(NetconfSessionListenerFactory.class),
32 any(Channel.class), any(Promise.class));
33 NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class);
34 final TcpClientChannelInitializer initializer = new TcpClientChannelInitializer(factory, listener);
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();
41 ChannelConfig channelConfig = mock(ChannelConfig.class);
42 doReturn(channelConfig).when(channel).config();
43 doReturn(1L).when(factory).getConnectionTimeoutMillis();
44 doReturn(channelConfig).when(channelConfig).setConnectTimeoutMillis(1);
46 Promise<NetconfClientSession> promise = mock(Promise.class);
47 doReturn("").when(promise).toString();
49 initializer.initializeSessionNegotiator(channel, promise);
50 verify(pipeline, times(1)).addAfter(anyString(), anyString(), any(ChannelHandler.class));