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 com.google.common.collect.Lists;
12 import io.netty.channel.Channel;
13 import io.netty.channel.ChannelHandler;
14 import io.netty.channel.ChannelPipeline;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.controller.netconf.client.NetconfClientSession;
21 import org.opendaylight.controller.netconf.client.NetconfClientSessionListener;
22 import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXICodec;
23 import org.openexi.proc.common.EXIOptions;
25 import java.util.Collection;
27 import static org.junit.Assert.assertEquals;
28 import static org.mockito.Matchers.any;
29 import static org.mockito.Matchers.anyString;
30 import static org.mockito.Mockito.mock;
32 public class NetconfClientSessionTest {
35 ChannelHandler channelHandler;
41 public void setUp() throws Exception {
42 MockitoAnnotations.initMocks(this);
46 public void testNetconfClientSession() throws Exception {
47 NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
49 Collection<String> caps = Lists.newArrayList("cap1", "cap2");
51 NetconfEXICodec codec = new NetconfEXICodec(new EXIOptions());
52 ChannelPipeline pipeline = mock(ChannelPipeline.class);
54 Mockito.doReturn(pipeline).when(channel).pipeline();
55 Mockito.doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
56 Mockito.doReturn("").when(channelHandler).toString();
58 NetconfClientSession session = new NetconfClientSession(sessionListener, channel, sessId, caps);
59 session.addExiHandlers(codec);
60 session.stopExiCommunication();
62 assertEquals(caps, session.getServerCapabilities());
63 assertEquals(session, session.thisInstance());
65 Mockito.verify(pipeline, Mockito.times(4)).replace(anyString(), anyString(), Mockito.any(ChannelHandler.class));