*/
package org.opendaylight.netconf.nettyutil;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.opendaylight.netconf.nettyutil.AbstractChannelInitializer.NETCONF_MESSAGE_AGGREGATOR;
import static org.opendaylight.netconf.nettyutil.AbstractChannelInitializer.NETCONF_MESSAGE_FRAME_ENCODER;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.HashedWheelTimer;
import io.netty.util.concurrent.Promise;
-import java.util.Collections;
import java.util.Optional;
-import org.junit.Assert;
+import java.util.Set;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.netconf.api.NetconfSessionListener;
-import org.opendaylight.netconf.api.NetconfSessionPreferences;
-import org.opendaylight.netconf.api.messages.NetconfHelloMessage;
+import org.opendaylight.netconf.api.messages.FramingMechanism;
+import org.opendaylight.netconf.api.messages.HelloMessage;
import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder;
import org.opendaylight.netconf.nettyutil.handler.FramingMechanismHandlerFactory;
import org.opendaylight.netconf.nettyutil.handler.NetconfChunkAggregator;
import org.opendaylight.netconf.nettyutil.handler.NetconfEOMAggregator;
import org.opendaylight.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder;
-import org.opendaylight.netconf.util.messages.FramingMechanism;
-import org.opendaylight.netconf.util.test.XmlFileLoader;
+import org.opendaylight.netconf.test.util.XmlFileLoader;
import org.w3c.dom.Document;
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
public class Netconf539Test {
@Mock
private NetconfSessionListener<TestingNetconfSession> listener;
private Promise<TestingNetconfSession> promise;
private EmbeddedChannel channel;
- private AbstractNetconfSessionNegotiator negotiator;
- private NetconfSessionPreferences prefs;
+ private TestSessionNegotiator negotiator;
@Before
public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
channel = new EmbeddedChannel();
channel.pipeline().addLast(AbstractChannelInitializer.NETCONF_MESSAGE_ENCODER,
new ChannelInboundHandlerAdapter());
channel.pipeline().addLast(NETCONF_MESSAGE_FRAME_ENCODER,
FramingMechanismHandlerFactory.createHandler(FramingMechanism.EOM));
channel.pipeline().addLast(NETCONF_MESSAGE_AGGREGATOR, new NetconfEOMAggregator());
- final NetconfHelloMessage serverHello = NetconfHelloMessage.createClientHello(Collections
- .singleton(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1), Optional.empty());
- doReturn(promise).when(promise).setFailure(any());
- doReturn(promise).when(promise).setSuccess(any());
- negotiator = new TestSessionNegotiator(new NetconfSessionPreferences(serverHello), promise, channel,
- new HashedWheelTimer(), listener, 100L);
+ final HelloMessage serverHello = HelloMessage.createClientHello(
+ Set.of(XmlNetconfConstants.URN_IETF_PARAMS_NETCONF_BASE_1_1), Optional.empty());
+ negotiator = new TestSessionNegotiator(serverHello, promise, channel, new HashedWheelTimer(), listener, 100L);
}
@Test
private void testGetSessionForHelloMessage(final String fileName) throws Exception {
final Document helloDocument = XmlFileLoader.xmlFileToDocument(fileName);
negotiator.startNegotiation();
- final NetconfHelloMessage helloMessage = new NetconfHelloMessage(helloDocument);
- final AbstractNetconfSession session = negotiator.getSessionForHelloMessage(helloMessage);
- Assert.assertNotNull(session);
- Assert.assertTrue("NetconfChunkAggregator was not installed in the Netconf pipeline",
+ final HelloMessage helloMessage = new HelloMessage(helloDocument);
+ final TestingNetconfSession session = negotiator.getSessionForHelloMessage(helloMessage);
+ assertNotNull(session);
+ assertTrue("NetconfChunkAggregator was not installed in the Netconf pipeline",
channel.pipeline().get(NETCONF_MESSAGE_AGGREGATOR) instanceof NetconfChunkAggregator);
- Assert.assertTrue("ChunkedFramingMechanismEncoder was not installed in the Netconf pipeline",
+ assertTrue("ChunkedFramingMechanismEncoder was not installed in the Netconf pipeline",
channel.pipeline().get(NETCONF_MESSAGE_FRAME_ENCODER) instanceof ChunkedFramingMechanismEncoder);
}
-}
\ No newline at end of file
+}