Remove CloseableUtil
[netconf.git] / protocol / netconf-server / src / test / java / org / opendaylight / netconf / server / mapping / operations / DefaultStopExiTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.server.mapping.operations;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.ArgumentMatchers.anyString;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17
18 import io.netty.channel.Channel;
19 import io.netty.channel.ChannelHandler;
20 import io.netty.channel.ChannelPipeline;
21 import org.junit.Test;
22 import org.opendaylight.netconf.api.xml.XmlElement;
23 import org.opendaylight.netconf.api.xml.XmlUtil;
24 import org.opendaylight.netconf.server.NetconfServerSession;
25 import org.w3c.dom.Document;
26
27 public class DefaultStopExiTest {
28     @Test
29     public void testHandleWithNoSubsequentOperations() throws Exception {
30         final DefaultStopExi exi = new DefaultStopExi("");
31         final Document doc = XmlUtil.newDocument();
32         Channel channel = mock(Channel.class);
33         doReturn("mockChannel").when(channel).toString();
34         ChannelPipeline pipeline = mock(ChannelPipeline.class);
35         doReturn(pipeline).when(channel).pipeline();
36         ChannelHandler channelHandler = mock(ChannelHandler.class);
37         doReturn(channelHandler).when(pipeline).replace(anyString(), anyString(), any(ChannelHandler.class));
38
39         NetconfServerSession serverSession = new NetconfServerSession(null, channel, 2L, null);
40         exi.setNetconfSession(serverSession);
41
42         assertNotNull(exi.handleWithNoSubsequentOperations(doc,
43                 XmlElement.fromDomElement(XmlUtil.readXmlToElement("<elem/>"))));
44         verify(pipeline, times(1)).replace(anyString(), anyString(), any(ChannelHandler.class));
45     }
46 }