*/
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;
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.opendaylight.netconf.api.messages.NetconfHelloMessage;
+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.util.test.XmlFileLoader;
+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 {
- private NetconfHelloMessage helloMessage;
+class NetconfClientSessionNegotiatorTest {
+ private HelloMessage helloMessage;
private ChannelPipeline pipeline;
private ChannelPromise future;
private Channel channel;
private ChannelInboundHandlerAdapter channelInboundHandlerAdapter;
- @Before
- public void setUp() {
- helloMessage = NetconfHelloMessage.createClientHello(Set.of("exi:1.0"), Optional.empty());
+ @BeforeEach
+ void setUp() {
+ helloMessage = HelloMessage.createClientHello(Set.of("exi:1.0"), Optional.empty());
pipeline = mockChannelPipeline();
future = mockChannelFuture();
channel = mockChannel();
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);
}
- private static NetconfHelloMessage createHelloMsg(final String name) throws Exception {
+ private static HelloMessage createHelloMsg(final String name) throws Exception {
final InputStream stream = NetconfClientSessionNegotiatorTest.class.getResourceAsStream(name);
- final Document doc = XmlUtil.readXmlToDocument(stream);
-
- return new NetconfHelloMessage(doc);
+ return new HelloMessage(XmlUtil.readXmlToDocument(stream));
}
private static Set<String> createCapabilities(final String name) throws Exception {
- NetconfHelloMessage hello = createHelloMsg(name);
-
- return ImmutableSet.copyOf(NetconfMessageUtil.extractCapabilitiesFromHello(hello.getDocument()));
+ return ImmutableSet.copyOf(NetconfMessageUtil.extractCapabilitiesFromHello(createHelloMsg(name).getDocument()));
}
@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(NetconfHelloMessage.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(NetconfHelloMessage.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);
ChannelHandlerContext handlerContext = mock(ChannelHandlerContext.class);
doReturn(pipeline).when(handlerContext).pipeline();
- negotiator.handleMessage(NetconfHelloMessage.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));
}
@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);