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