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 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.controller.netconf.nettyutil.handler.NetconfEXICodec;
27 import org.openexi.proc.common.EXIOptions;
29 public class NetconfClientSessionTest {
32 ChannelHandler channelHandler;
38 public void setUp() throws Exception {
39 MockitoAnnotations.initMocks(this);
43 public void testNetconfClientSession() throws Exception {
44 NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
46 Collection<String> caps = Lists.newArrayList("cap1", "cap2");
48 NetconfEXICodec codec = new NetconfEXICodec(new EXIOptions());
49 ChannelPipeline pipeline = mock(ChannelPipeline.class);
51 Mockito.doReturn(pipeline).when(channel).pipeline();
52 Mockito.doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
53 Mockito.doReturn("").when(channelHandler).toString();
55 NetconfClientSession session = new NetconfClientSession(sessionListener, channel, sessId, caps);
56 session.addExiHandlers(codec);
57 session.stopExiCommunication();
59 assertEquals(caps, session.getServerCapabilities());
60 assertEquals(session, session.thisInstance());
62 Mockito.verify(pipeline, Mockito.times(4)).replace(anyString(), anyString(), Mockito.any(ChannelHandler.class));