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
9 package org.opendaylight.controller.netconf.client;
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.AbstractChannelInitializer;
17 import org.opendaylight.protocol.framework.SessionListenerFactory;
18 import org.opendaylight.protocol.framework.SessionNegotiator;
20 import static org.mockito.Mockito.*;
22 public class TcpClientChannelInitializerTest {
24 public void testInitializeSessionNegotiator() throws Exception {
25 NetconfClientSessionNegotiatorFactory factory = mock(NetconfClientSessionNegotiatorFactory.class);
26 SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class);
27 doReturn("").when(sessionNegotiator).toString();
28 doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(SessionListenerFactory.class), any(Channel.class), any(Promise.class));
29 NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class);
30 TcpClientChannelInitializer initializer = new TcpClientChannelInitializer(factory, listener);
31 ChannelPipeline pipeline = mock(ChannelPipeline.class);
32 doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class));
33 Channel channel = mock(Channel.class);
34 doReturn(pipeline).when(channel).pipeline();
35 doReturn("").when(channel).toString();
37 Promise<NetconfClientSession> promise = mock(Promise.class);
38 doReturn("").when(promise).toString();
40 initializer.initializeSessionNegotiator(channel, promise);
41 verify(pipeline, times(1)).addAfter(anyString(), anyString(), any(ChannelHandler.class));