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.netconf.client;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Matchers.anyString;
14 import static org.mockito.Mockito.mock;
16 import com.google.common.collect.Lists;
17 import io.netty.channel.Channel;
18 import io.netty.channel.ChannelHandler;
19 import io.netty.channel.ChannelPipeline;
20 import java.util.Collection;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.Mock;
24 import org.mockito.Mockito;
25 import org.mockito.MockitoAnnotations;
26 import org.opendaylight.netconf.nettyutil.handler.NetconfEXICodec;
27 import org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder;
28 import org.opendaylight.netconf.nettyutil.handler.NetconfMessageToEXIEncoder;
29 import org.openexi.proc.common.EXIOptions;
31 public class NetconfClientSessionTest {
34 ChannelHandler channelHandler;
40 public void setUp() throws Exception {
41 MockitoAnnotations.initMocks(this);
45 public void testNetconfClientSession() throws Exception {
46 NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
48 Collection<String> caps = Lists.newArrayList("cap1", "cap2");
50 NetconfEXICodec codec = new NetconfEXICodec(new EXIOptions());
51 ChannelPipeline pipeline = mock(ChannelPipeline.class);
53 Mockito.doReturn(pipeline).when(channel).pipeline();
54 Mockito.doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
55 Mockito.doReturn("").when(channelHandler).toString();
57 NetconfClientSession session = new NetconfClientSession(sessionListener, channel, sessId, caps);
58 final NetconfMessageToEXIEncoder exiEncoder = NetconfMessageToEXIEncoder.create(codec);
59 final NetconfEXIToMessageDecoder exiDecoder = NetconfEXIToMessageDecoder.create(codec);
60 session.addExiHandlers(exiDecoder, exiEncoder);
61 session.stopExiCommunication();
63 assertEquals(caps, session.getServerCapabilities());
64 assertEquals(session, session.thisInstance());
66 Mockito.verify(pipeline, Mockito.times(4)).replace(anyString(), anyString(), Mockito.any(ChannelHandler.class));