X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfClientSessionTest.java;fp=opendaylight%2Fnetconf%2Fnetconf-client%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fclient%2FNetconfClientSessionTest.java;h=4175190e143aca575239c6f957d34a30f09458c2;hp=0000000000000000000000000000000000000000;hb=3c2b9f44d59d735907ef541d36542443221c5c68;hpb=ce9ca282f8e0eb5a0cd1b97cab882f9f80fa598a diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionTest.java new file mode 100644 index 0000000000..4175190e14 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.netconf.client; + +import com.google.common.collect.Lists; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelPipeline; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.opendaylight.controller.netconf.client.NetconfClientSession; +import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; +import org.opendaylight.controller.netconf.nettyutil.handler.NetconfEXICodec; +import org.openexi.proc.common.EXIOptions; + +import java.util.ArrayList; +import java.util.Collection; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.mock; + +public class NetconfClientSessionTest { + + @Mock + ChannelHandler channelHandler; + + @Mock + Channel channel; + + @Before + public void setUp() throws Exception { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testNetconfClientSession() throws Exception { + NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); + long sessId = 20L; + Collection caps = Lists.newArrayList("cap1", "cap2"); + + NetconfEXICodec codec = new NetconfEXICodec(new EXIOptions()); + ChannelPipeline pipeline = mock(ChannelPipeline.class); + + Mockito.doReturn(pipeline).when(channel).pipeline(); + Mockito.doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class)); + Mockito.doReturn("").when(channelHandler).toString(); + + NetconfClientSession session = new NetconfClientSession(sessionListener, channel, sessId, caps); + session.addExiHandlers(codec); + session.stopExiCommunication(); + + assertEquals(caps, session.getServerCapabilities()); + assertEquals(session, session.thisInstance()); + + Mockito.verify(pipeline, Mockito.times(4)).replace(anyString(), anyString(), Mockito.any(ChannelHandler.class)); + } +}