OpenApi add POST request to device root
[netconf.git] / protocol / netconf-client / src / test / java / org / opendaylight / netconf / client / NetconfClientSessionNegotiatorTest.java
index 129793ee9405c01631374c76d5c61726b9352a61..790542cb4b5f2f044d58a409ea23d4981c735015 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.netconf.client;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.doAnswer;
@@ -29,36 +29,38 @@ import io.netty.channel.ChannelPromise;
 import io.netty.channel.EventLoop;
 import io.netty.handler.codec.MessageToByteEncoder;
 import io.netty.handler.ssl.SslHandler;
-import io.netty.util.HashedWheelTimer;
-import io.netty.util.Timer;
 import io.netty.util.concurrent.GenericFutureListener;
 import io.netty.util.concurrent.Promise;
 import java.io.InputStream;
 import java.util.Optional;
 import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
-import org.opendaylight.netconf.api.NetconfMessage;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.netconf.api.messages.HelloMessage;
+import org.opendaylight.netconf.api.messages.NetconfMessage;
+import org.opendaylight.netconf.api.messages.RpcMessage;
 import org.opendaylight.netconf.api.xml.XmlUtil;
+import org.opendaylight.netconf.common.impl.DefaultNetconfTimer;
 import org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder;
 import org.opendaylight.netconf.nettyutil.handler.NetconfEXIToMessageDecoder;
 import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder;
 import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToMessageDecoder;
 import org.opendaylight.netconf.nettyutil.handler.exi.EXIParameters;
-import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessage;
+import org.opendaylight.netconf.nettyutil.handler.exi.NetconfStartExiMessageProvider;
 import org.opendaylight.netconf.test.util.XmlFileLoader;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.netconf.base._1._0.rev110601.SessionIdType;
+import org.opendaylight.yangtools.yang.common.Uint32;
 import org.w3c.dom.Document;
 
-public class NetconfClientSessionNegotiatorTest {
+class NetconfClientSessionNegotiatorTest {
     private HelloMessage helloMessage;
     private ChannelPipeline pipeline;
     private ChannelPromise future;
     private Channel channel;
     private ChannelInboundHandlerAdapter channelInboundHandlerAdapter;
 
-    @Before
-    public void setUp() {
+    @BeforeEach
+    void setUp() {
         helloMessage = HelloMessage.createClientHello(Set.of("exi:1.0"), Optional.empty());
         pipeline = mockChannelPipeline();
         future = mockChannelFuture();
@@ -124,13 +126,13 @@ public class NetconfClientSessionNegotiatorTest {
 
     private NetconfClientSessionNegotiator createNetconfClientSessionNegotiator(
             final Promise<NetconfClientSession> promise,
-            final NetconfStartExiMessage startExi) {
+            final RpcMessage startExi) {
         ChannelProgressivePromise progressivePromise = mock(ChannelProgressivePromise.class);
         doReturn(progressivePromise).when(promise).setFailure(any(Throwable.class));
 
         long timeout = 10L;
         NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);
-        Timer timer = new HashedWheelTimer();
+        var timer = new DefaultNetconfTimer();
         return new NetconfClientSessionNegotiator(helloMessage, startExi, promise, channel, timer, sessionListener,
             timeout, 16384);
     }
@@ -145,34 +147,34 @@ public class NetconfClientSessionNegotiatorTest {
     }
 
     @Test
-    public void testNetconfClientSessionNegotiator() throws Exception {
+    void testNetconfClientSessionNegotiator() throws Exception {
         Promise<NetconfClientSession> promise = mock(Promise.class);
         doReturn(promise).when(promise).setSuccess(any());
         NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
 
         negotiator.channelActive(null);
         doReturn(null).when(future).cause();
-        negotiator.handleMessage(HelloMessage.createServerHello(Set.of("a", "b"), 10));
+        negotiator.handleMessage(HelloMessage.createServerHello(Set.of("a", "b"), new SessionIdType(Uint32.TEN)));
         verify(promise).setSuccess(any());
     }
 
     @Test
-    public void testNegotiatorWhenChannelActiveHappenAfterHandleMessage() throws Exception {
+    void testNegotiatorWhenChannelActiveHappenAfterHandleMessage() throws Exception {
         Promise<NetconfClientSession> promise = mock(Promise.class);
         doReturn(false).when(promise).isDone();
         doReturn(promise).when(promise).setSuccess(any());
         NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
 
         doReturn(null).when(future).cause();
-        negotiator.handleMessage(HelloMessage.createServerHello(Set.of("a", "b"), 10));
+        negotiator.handleMessage(HelloMessage.createServerHello(Set.of("a", "b"), new SessionIdType(Uint32.TEN)));
         negotiator.channelActive(null);
         verify(promise).setSuccess(any());
     }
 
     @Test
-    public void testNetconfClientSessionNegotiatorWithEXI() throws Exception {
+    void testNetconfClientSessionNegotiatorWithEXI() throws Exception {
         Promise<NetconfClientSession> promise = mock(Promise.class);
-        NetconfStartExiMessage exiMessage = NetconfStartExiMessage.create(EXIParameters.empty(), "msg-id");
+        RpcMessage exiMessage = NetconfStartExiMessageProvider.create(EXIParameters.empty(), "msg-id");
         doReturn(promise).when(promise).setSuccess(any());
         NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, exiMessage);
 
@@ -186,7 +188,7 @@ public class NetconfClientSessionNegotiatorTest {
 
         ChannelHandlerContext handlerContext = mock(ChannelHandlerContext.class);
         doReturn(pipeline).when(handlerContext).pipeline();
-        negotiator.handleMessage(HelloMessage.createServerHello(Set.of("exi:1.0"), 10));
+        negotiator.handleMessage(HelloMessage.createServerHello(Set.of("exi:1.0"), new SessionIdType(Uint32.TEN)));
         Document expectedResult = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml");
         channelInboundHandlerAdapter.channelRead(handlerContext, new NetconfMessage(expectedResult));
 
@@ -197,7 +199,7 @@ public class NetconfClientSessionNegotiatorTest {
     }
 
     @Test
-    public void testNetconfClientSessionNegotiatorGetCached() throws Exception {
+    void testNetconfClientSessionNegotiatorGetCached() throws Exception {
         Promise<NetconfClientSession> promise = mock(Promise.class);
         doReturn(promise).when(promise).setSuccess(any());
         NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class);