From: Filip Tehlar Date: Thu, 11 Sep 2014 13:07:26 +0000 (+0200) Subject: BUG-1521 netconf-client line coverage X-Git-Tag: release/helium~79^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=3c2b9f44d59d735907ef541d36542443221c5c68 BUG-1521 netconf-client line coverage Change-Id: I44c7d6a627e21aabe9c46ea678a90d81268ef438 Signed-off-by: Filip Tehlar --- diff --git a/opendaylight/netconf/netconf-client/pom.xml b/opendaylight/netconf/netconf-client/pom.xml index bf27ed6f4d..6bb67d0681 100644 --- a/opendaylight/netconf/netconf-client/pom.xml +++ b/opendaylight/netconf/netconf-client/pom.xml @@ -24,6 +24,12 @@ ${project.groupId} netconf-util + + ${project.groupId} + netconf-util + test-jar + test + com.google.guava guava @@ -36,6 +42,10 @@ org.slf4j slf4j-api + + org.opendaylight.yangtools + mockito-configuration + diff --git a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java index e2ac49c3ef..cbbee1f655 100644 --- a/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java +++ b/opendaylight/netconf/netconf-client/src/main/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiator.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.netconf.client; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import io.netty.channel.Channel; @@ -70,8 +71,8 @@ public class NetconfClientSessionNegotiator extends logger.debug("Netconf session {} should use exi.", session); NetconfStartExiMessage startExiMessage = (NetconfStartExiMessage) sessionPreferences.getStartExiMessage(); tryToInitiateExi(session, startExiMessage); - // Exi is not supported, release session immediately } else { + // Exi is not supported, release session immediately logger.debug("Netconf session {} isn't capable of using exi.", session); negotiationSuccessful(session); } @@ -117,6 +118,7 @@ public class NetconfClientSessionNegotiator extends private long extractSessionId(final Document doc) { final Node sessionIdNode = (Node) XmlUtil.evaluateXPath(sessionIdXPath, doc, XPathConstants.NODE); + Preconditions.checkState(sessionIdNode != null, ""); String textContent = sessionIdNode.getTextContent(); if (textContent == null || textContent.equals("")) { throw new IllegalStateException("Session id not received from server"); diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientConfigurationTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientConfigurationTest.java new file mode 100644 index 0000000000..592cdad4c1 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientConfigurationTest.java @@ -0,0 +1,51 @@ +/* + * 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.base.Optional; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; +import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; +import org.opendaylight.protocol.framework.ReconnectStrategy; + +import java.net.InetSocketAddress; + +public class NetconfClientConfigurationTest { + @Test + public void testNetconfClientConfiguration() throws Exception { + Long timeout = 200L; + NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id"); + NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener(); + InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830); + ReconnectStrategy strategy = Mockito.mock(ReconnectStrategy.class); + AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class); + NetconfClientConfiguration cfg = NetconfClientConfigurationBuilder.create(). + withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH). + withAddress(address). + withConnectionTimeoutMillis(timeout). + withReconnectStrategy(strategy). + withAdditionalHeader(header). + withSessionListener(listener). + withAuthHandler(handler).build(); + + Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis()); + Assert.assertEquals(Optional.fromNullable(header), cfg.getAdditionalHeader()); + Assert.assertEquals(listener, cfg.getSessionListener()); + Assert.assertEquals(handler, cfg.getAuthHandler()); + Assert.assertEquals(strategy, cfg.getReconnectStrategy()); + Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol()); + Assert.assertEquals(address, cfg.getAddress()); + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcherImplTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcherImplTest.java new file mode 100644 index 0000000000..5a2ec5656f --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientDispatcherImplTest.java @@ -0,0 +1,104 @@ +/* + * 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 io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelPromise; +import io.netty.channel.EventLoopGroup; +import io.netty.util.HashedWheelTimer; +import io.netty.util.Timer; +import io.netty.util.concurrent.GenericFutureListener; +import org.junit.Test; +import org.mockito.Mockito; +import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; +import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; +import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; +import org.opendaylight.protocol.framework.ReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategyFactory; + +import java.net.InetSocketAddress; +import java.util.concurrent.Future; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doReturn; + +public class NetconfClientDispatcherImplTest { + @Test + public void testNetconfClientDispatcherImpl() throws Exception { + EventLoopGroup bossGroup = Mockito.mock(EventLoopGroup.class); + EventLoopGroup workerGroup = Mockito.mock(EventLoopGroup.class); + Timer timer = new HashedWheelTimer(); + + ChannelFuture chf = Mockito.mock(ChannelFuture.class); + Channel ch = Mockito.mock(Channel.class); + doReturn(ch).when(chf).channel(); + Throwable thr = Mockito.mock(Throwable.class); + doReturn(chf).when(workerGroup).register(any(Channel.class)); + + ChannelPromise promise = Mockito.mock(ChannelPromise.class); + doReturn(promise).when(chf).addListener(any(GenericFutureListener.class)); + doReturn(thr).when(chf).cause(); + + Long timeout = 200L; + NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id"); + NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener(); + InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830); + ReconnectStrategyFactory reconnectStrategyFactory = Mockito.mock(ReconnectStrategyFactory.class); + AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class); + ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class); + + doReturn(5).when(reconnect).getConnectTimeout(); + doReturn("").when(reconnect).toString(); + doReturn("").when(handler).toString(); + doReturn("").when(reconnectStrategyFactory).toString(); + doReturn(reconnect).when(reconnectStrategyFactory).createReconnectStrategy(); + + NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create(). + withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH). + withAddress(address). + withConnectionTimeoutMillis(timeout). + withReconnectStrategy(reconnect). + withAdditionalHeader(header). + withSessionListener(listener). + withConnectStrategyFactory(reconnectStrategyFactory). + withAuthHandler(handler).build(); + + NetconfReconnectingClientConfiguration cfg2 = NetconfReconnectingClientConfigurationBuilder.create(). + withProtocol(NetconfClientConfiguration.NetconfClientProtocol.TCP). + withAddress(address). + withConnectionTimeoutMillis(timeout). + withReconnectStrategy(reconnect). + withAdditionalHeader(header). + withSessionListener(listener). + withConnectStrategyFactory(reconnectStrategyFactory). + withAuthHandler(handler).build(); + + NetconfClientDispatcherImpl dispatcher = new NetconfClientDispatcherImpl(bossGroup, workerGroup, timer); + Future sshSession = dispatcher.createClient(cfg); + Future tcpSession = dispatcher.createClient(cfg2); + + Future sshReconn = dispatcher.createReconnectingClient(cfg); + Future tcpReconn = dispatcher.createReconnectingClient(cfg2); + + assertNotNull(sshSession); + assertNotNull(tcpSession); + assertNotNull(sshReconn); + assertNotNull(tcpReconn); + + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactoryTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactoryTest.java new file mode 100644 index 0000000000..0557a0c268 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorFactoryTest.java @@ -0,0 +1,43 @@ +/* + * 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.base.Optional; +import io.netty.channel.Channel; +import io.netty.util.HashedWheelTimer; +import io.netty.util.Timer; +import io.netty.util.concurrent.Promise; +import org.apache.sshd.common.SessionListener; +import org.junit.Test; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; +import org.opendaylight.protocol.framework.SessionListenerFactory; +import org.opendaylight.protocol.framework.SessionNegotiator; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; + +public class NetconfClientSessionNegotiatorFactoryTest { + @Test + public void testGetSessionNegotiator() throws Exception { + NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); + Timer timer = new HashedWheelTimer(); + SessionListenerFactory listenerFactory = mock(SessionListenerFactory.class); + doReturn(sessionListener).when(listenerFactory).getSessionListener(); + + Channel channel = mock(Channel.class); + Promise promise = mock(Promise.class); + NetconfClientSessionNegotiatorFactory negotiatorFactory = new NetconfClientSessionNegotiatorFactory(timer, + Optional.absent(), 200L); + + SessionNegotiator sessionNegotiator = negotiatorFactory.getSessionNegotiator(listenerFactory, channel, promise); + assertNotNull(sessionNegotiator); + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorTest.java new file mode 100644 index 0000000000..333e9deae4 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfClientSessionNegotiatorTest.java @@ -0,0 +1,155 @@ +/* + * 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.base.Optional; +import io.netty.channel.*; +import io.netty.handler.ssl.SslHandler; +import io.netty.util.HashedWheelTimer; +import io.netty.util.concurrent.GenericFutureListener; +import io.netty.util.concurrent.Promise; +import org.apache.mina.handler.demux.ExceptionHandler; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.collections.Sets; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; +import org.opendaylight.controller.netconf.api.NetconfClientSessionPreferences; +import org.opendaylight.controller.netconf.api.NetconfMessage; +import io.netty.util.Timer; +import org.opendaylight.controller.netconf.nettyutil.handler.ChunkedFramingMechanismEncoder; +import org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToHelloMessageDecoder; +import org.opendaylight.controller.netconf.nettyutil.handler.NetconfXMLToMessageDecoder; +import org.opendaylight.controller.netconf.nettyutil.handler.exi.NetconfStartExiMessage; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; +import org.opendaylight.controller.netconf.util.test.XmlFileLoader; +import org.opendaylight.controller.netconf.util.xml.XmlUtil; +import org.openexi.proc.common.EXIOptions; +import org.w3c.dom.Document; +import java.util.Set; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.*; + +public class NetconfClientSessionNegotiatorTest { + + private NetconfHelloMessage helloMessage; + private ChannelPipeline pipeline; + private ChannelFuture future; + private Channel channel; + private ChannelInboundHandlerAdapter channelInboundHandlerAdapter; + + @Before + public void setUp() throws Exception { + helloMessage = NetconfHelloMessage.createClientHello(Sets.newSet("exi:1.0"), Optional.absent()); + pipeline = mockChannelPipeline(); + future = mockChannelFuture(); + channel = mockChannel(); + System.out.println("setup done"); + } + + private ChannelHandler mockChannelHandler() { + ChannelHandler handler = mock(ChannelHandler.class); + return handler; + } + + private Channel mockChannel() { + Channel channel = mock(Channel.class); + ChannelHandler channelHandler = mockChannelHandler(); + doReturn("").when(channel).toString(); + doReturn(future).when(channel).close(); + doReturn(future).when(channel).writeAndFlush(anyObject()); + doReturn(true).when(channel).isOpen(); + doReturn(pipeline).when(channel).pipeline(); + doReturn("").when(pipeline).toString(); + doReturn(pipeline).when(pipeline).remove(any(ChannelHandler.class)); + doReturn(channelHandler).when(pipeline).remove(anyString()); + return channel; + } + + private ChannelFuture mockChannelFuture() { + ChannelFuture future = mock(ChannelFuture.class); + doReturn(future).when(future).addListener(any(GenericFutureListener.class)); + return future; + } + + private ChannelPipeline mockChannelPipeline() { + ChannelPipeline pipeline = mock(ChannelPipeline.class); + ChannelHandler handler = mock(ChannelHandler.class); + doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class)); + doReturn(null).when(pipeline).get(SslHandler.class); + doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class)); + doReturn(handler).when(pipeline).replace(anyString(), anyString(), any(ChunkedFramingMechanismEncoder.class)); + + NetconfXMLToHelloMessageDecoder messageDecoder = new NetconfXMLToHelloMessageDecoder(); + doReturn(messageDecoder).when(pipeline).replace(anyString(), anyString(), any(NetconfXMLToMessageDecoder.class)); + doReturn(pipeline).when(pipeline).replace(any(ChannelHandler.class), anyString(), any(NetconfClientSession.class)); + return pipeline; + } + + private NetconfClientSessionNegotiator createNetconfClientSessionNegotiator(Promise promise, + NetconfMessage startExi) { + ChannelProgressivePromise progressivePromise = mock(ChannelProgressivePromise.class); + NetconfClientSessionPreferences preferences = new NetconfClientSessionPreferences(helloMessage, startExi); + doReturn(progressivePromise).when(promise).setFailure(any(Throwable.class)); + + long timeout = 10L; + NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); + Timer timer = new HashedWheelTimer(); + return new NetconfClientSessionNegotiator(preferences, promise, channel, timer, sessionListener, timeout); + } + + @Test + public void testNetconfClientSessionNegotiator() throws Exception { + Promise promise = mock(Promise.class); + doReturn(promise).when(promise).setSuccess(anyObject()); + NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null); + + negotiator.channelActive(null); + Set caps = Sets.newSet("a", "b"); + NetconfHelloMessage helloServerMessage = NetconfHelloMessage.createServerHello(caps, 10); + negotiator.handleMessage(helloServerMessage); + verify(promise).setSuccess(anyObject()); + } + + @Test + public void testNetconfClientSessionNegotiatorWithEXI() throws Exception { + Promise promise = mock(Promise.class); + EXIOptions exiOptions = new EXIOptions(); + NetconfStartExiMessage exiMessage = NetconfStartExiMessage.create(exiOptions, "msg-id"); + doReturn(promise).when(promise).setSuccess(anyObject()); + NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, exiMessage); + + negotiator.channelActive(null); + Set caps = Sets.newSet("exi:1.0"); + NetconfHelloMessage helloMessage = NetconfHelloMessage.createServerHello(caps, 10); + + doAnswer(new Answer() { + @Override + public Object answer(InvocationOnMock invocationOnMock) throws Throwable { + channelInboundHandlerAdapter = ((ChannelInboundHandlerAdapter) invocationOnMock.getArguments()[2]); + return null; + } + }).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class)); + + ChannelHandlerContext handlerContext = mock(ChannelHandlerContext.class); + doReturn(pipeline).when(handlerContext).pipeline(); + negotiator.handleMessage(helloMessage); + Document expectedResult = XmlFileLoader.xmlFileToDocument("netconfMessages/rpc-reply_ok.xml"); + channelInboundHandlerAdapter.channelRead(handlerContext, new NetconfMessage(expectedResult)); + + verify(promise).setSuccess(anyObject()); + + // two calls for exiMessage, 2 for hello message + verify(pipeline, times(4)).replace(anyString(), anyString(), any(ChannelHandler.class)); + } +} 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)); + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfReconnectingClientConfigurationTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfReconnectingClientConfigurationTest.java new file mode 100644 index 0000000000..e79a370ec7 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/NetconfReconnectingClientConfigurationTest.java @@ -0,0 +1,58 @@ +/* + * 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.base.Optional; +import org.junit.Assert; +import org.junit.Test; +import org.mockito.Mockito; +import org.opendaylight.controller.config.yang.protocol.framework.NeverReconnectStrategyFactoryModule; +import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; +import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfiguration; +import org.opendaylight.controller.netconf.client.conf.NetconfReconnectingClientConfigurationBuilder; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader; +import org.opendaylight.protocol.framework.ReconnectStrategy; +import org.opendaylight.protocol.framework.ReconnectStrategyFactory; + +import java.net.InetSocketAddress; + +public class NetconfReconnectingClientConfigurationTest { + @Test + public void testNetconfReconnectingClientConfiguration() throws Exception { + Long timeout = 200L; + NetconfHelloMessageAdditionalHeader header = new NetconfHelloMessageAdditionalHeader("a", "host", "port", "trans", "id"); + NetconfClientSessionListener listener = new SimpleNetconfClientSessionListener(); + InetSocketAddress address = InetSocketAddress.createUnresolved("host", 830); + ReconnectStrategyFactory strategy = Mockito.mock(ReconnectStrategyFactory.class); + AuthenticationHandler handler = Mockito.mock(AuthenticationHandler.class); + ReconnectStrategy reconnect = Mockito.mock(ReconnectStrategy.class); + + NetconfReconnectingClientConfiguration cfg = NetconfReconnectingClientConfigurationBuilder.create(). + withProtocol(NetconfClientConfiguration.NetconfClientProtocol.SSH). + withAddress(address). + withConnectionTimeoutMillis(timeout). + withReconnectStrategy(reconnect). + withAdditionalHeader(header). + withSessionListener(listener). + withConnectStrategyFactory(strategy). + withAuthHandler(handler).build(); + + Assert.assertEquals(timeout, cfg.getConnectionTimeoutMillis()); + Assert.assertEquals(Optional.fromNullable(header), cfg.getAdditionalHeader()); + Assert.assertEquals(listener, cfg.getSessionListener()); + Assert.assertEquals(handler, cfg.getAuthHandler()); + Assert.assertEquals(strategy, cfg.getConnectStrategyFactory()); + Assert.assertEquals(NetconfClientConfiguration.NetconfClientProtocol.SSH, cfg.getProtocol()); + Assert.assertEquals(address, cfg.getAddress()); + Assert.assertEquals(reconnect, cfg.getReconnectStrategy()); + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListenerTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListenerTest.java new file mode 100644 index 0000000000..e067cc225f --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SimpleNetconfClientSessionListenerTest.java @@ -0,0 +1,79 @@ +/* + * 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 io.netty.channel.*; +import io.netty.util.concurrent.Future; +import io.netty.util.concurrent.Promise; +import org.junit.Before; +import org.junit.Test; +import org.mockito.internal.util.collections.Sets; +import org.opendaylight.controller.netconf.api.NetconfMessage; +import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessage; + +import java.util.Set; + +import static org.junit.Assert.*; +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.*; + +public class SimpleNetconfClientSessionListenerTest { + + private Channel channel; + private ChannelFuture channelFuture; + Set caps; + private NetconfHelloMessage helloMessage; + private NetconfMessage message; + private NetconfClientSessionListener sessionListener; + private NetconfClientSession clientSession; + + @Before + public void setUp() throws Exception { + channel = mock(Channel.class); + channelFuture = mock(ChannelFuture.class); + doReturn(channelFuture).when(channel).writeAndFlush(anyObject()); + caps = Sets.newSet("a", "b"); + helloMessage = NetconfHelloMessage.createServerHello(caps, 10); + message = new NetconfMessage(helloMessage.getDocument()); + sessionListener = mock(NetconfClientSessionListener.class); + clientSession = new NetconfClientSession(sessionListener, channel, 20L, caps); + } + + @Test + public void testSessionDown() throws Exception { + SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener(); + Future promise = simpleListener.sendRequest(message); + simpleListener.onSessionUp(clientSession); + verify(channel, times(1)).writeAndFlush(anyObject()); + + simpleListener.onSessionDown(clientSession, new Exception()); + assertFalse(promise.isSuccess()); + } + + @Test + public void testSendRequest() throws Exception { + SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener(); + Future promise = simpleListener.sendRequest(message); + simpleListener.onSessionUp(clientSession); + verify(channel, times(1)).writeAndFlush(anyObject()); + + simpleListener.sendRequest(message); + assertFalse(promise.isSuccess()); + } + + @Test + public void testOnMessage() throws Exception { + SimpleNetconfClientSessionListener simpleListener = new SimpleNetconfClientSessionListener(); + Future promise = simpleListener.sendRequest(message); + simpleListener.onSessionUp(clientSession); + verify(channel, times(1)).writeAndFlush(anyObject()); + + simpleListener.onMessage(clientSession, message); + assertTrue(promise.isSuccess()); + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializerTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializerTest.java new file mode 100644 index 0000000000..0830c2967b --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/SshClientChannelInitializerTest.java @@ -0,0 +1,51 @@ +/* + * 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 io.netty.channel.Channel; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelPipeline; +import io.netty.util.concurrent.Promise; +import org.junit.Test; +import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; +import org.opendaylight.protocol.framework.SessionListenerFactory; +import org.opendaylight.protocol.framework.SessionNegotiator; + +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.*; + +public class SshClientChannelInitializerTest { + @Test + public void test() throws Exception { + + AuthenticationHandler authenticationHandler = mock(AuthenticationHandler.class); + NetconfClientSessionNegotiatorFactory negotiatorFactory = mock(NetconfClientSessionNegotiatorFactory.class); + NetconfClientSessionListener sessionListener = mock(NetconfClientSessionListener.class); + + SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class); + doReturn("").when(sessionNegotiator).toString(); + doReturn(sessionNegotiator).when(negotiatorFactory).getSessionNegotiator(any(SessionListenerFactory.class), any(Channel.class), any(Promise.class)); + ChannelPipeline pipeline = mock(ChannelPipeline.class); + doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class)); + Channel channel = mock(Channel.class); + doReturn(pipeline).when(channel).pipeline(); + doReturn("").when(channel).toString(); + doReturn(pipeline).when(pipeline).addFirst(any(ChannelHandler.class)); + doReturn(pipeline).when(pipeline).addLast(anyString(), any(ChannelHandler.class)); + + Promise promise = mock(Promise.class); + doReturn("").when(promise).toString(); + + SshClientChannelInitializer initializer = new SshClientChannelInitializer(authenticationHandler, negotiatorFactory, + sessionListener); + initializer.initialize(channel, promise); + verify(pipeline, times(1)).addFirst(any(ChannelHandler.class)); + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/TcpClientChannelInitializerTest.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/TcpClientChannelInitializerTest.java new file mode 100644 index 0000000000..e355cf45e7 --- /dev/null +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/TcpClientChannelInitializerTest.java @@ -0,0 +1,43 @@ +/* + * 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 io.netty.channel.Channel; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelPipeline; +import io.netty.util.concurrent.Promise; +import org.junit.Test; +import org.opendaylight.controller.netconf.nettyutil.AbstractChannelInitializer; +import org.opendaylight.protocol.framework.SessionListenerFactory; +import org.opendaylight.protocol.framework.SessionNegotiator; + +import static org.mockito.Mockito.*; + +public class TcpClientChannelInitializerTest { + @Test + public void testInitializeSessionNegotiator() throws Exception { + NetconfClientSessionNegotiatorFactory factory = mock(NetconfClientSessionNegotiatorFactory.class); + SessionNegotiator sessionNegotiator = mock(SessionNegotiator.class); + doReturn("").when(sessionNegotiator).toString(); + doReturn(sessionNegotiator).when(factory).getSessionNegotiator(any(SessionListenerFactory.class), any(Channel.class), any(Promise.class)); + NetconfClientSessionListener listener = mock(NetconfClientSessionListener.class); + TcpClientChannelInitializer initializer = new TcpClientChannelInitializer(factory, listener); + ChannelPipeline pipeline = mock(ChannelPipeline.class); + doReturn(pipeline).when(pipeline).addAfter(anyString(), anyString(), any(ChannelHandler.class)); + Channel channel = mock(Channel.class); + doReturn(pipeline).when(channel).pipeline(); + doReturn("").when(channel).toString(); + + Promise promise = mock(Promise.class); + doReturn("").when(promise).toString(); + + initializer.initializeSessionNegotiator(channel, promise); + verify(pipeline, times(1)).addAfter(anyString(), anyString(), any(ChannelHandler.class)); + } +} diff --git a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/TestingNetconfClient.java similarity index 92% rename from opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java rename to opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/TestingNetconfClient.java index 18ed18e4ae..d7209d9295 100644 --- a/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/test/TestingNetconfClient.java +++ b/opendaylight/netconf/netconf-client/src/test/java/org/opendaylight/controller/netconf/client/TestingNetconfClient.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.controller.netconf.client.test; +package org.opendaylight.controller.netconf.client; import com.google.common.base.Optional; import com.google.common.base.Preconditions; @@ -26,11 +26,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.opendaylight.controller.netconf.api.NetconfMessage; -import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; -import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; -import org.opendaylight.controller.netconf.client.NetconfClientSession; -import org.opendaylight.controller.netconf.client.NetconfClientSessionListener; -import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration.NetconfClientProtocol; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; diff --git a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java index c5281d01f8..5f8bc06e10 100644 --- a/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java +++ b/opendaylight/netconf/netconf-impl/src/test/java/org/opendaylight/controller/netconf/impl/ConcurrentClientsTest.java @@ -59,7 +59,7 @@ import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; -import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; +import org.opendaylight.controller.netconf.client.TestingNetconfClient; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceFactoryListenerImpl; import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; import org.opendaylight.controller.netconf.mapping.api.Capability; diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java index 4b49c0928b..d8eb841a79 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfConfigPersisterITTest.java @@ -36,7 +36,7 @@ import org.opendaylight.controller.config.persist.api.ConfigSnapshotHolder; import org.opendaylight.controller.config.persist.api.Persister; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.jmx.CommitJMXNotification; -import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; +import org.opendaylight.controller.netconf.client.TestingNetconfClient; import org.opendaylight.controller.netconf.impl.DefaultCommitNotificationProducer; import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl; diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java index 72a2f8f7ac..a9558c06cd 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITMonitoringTest.java @@ -28,7 +28,7 @@ import java.util.Set; import org.junit.Test; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.api.monitoring.NetconfManagementSession; -import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; +import org.opendaylight.controller.netconf.client.TestingNetconfClient; import org.opendaylight.controller.netconf.impl.osgi.NetconfMonitoringServiceImpl; import org.opendaylight.controller.netconf.impl.osgi.NetconfOperationServiceSnapshotImpl; import org.opendaylight.controller.netconf.impl.osgi.SessionMonitoringService; diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java index 67ccf0c02c..4fe5f2a950 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITSecureTest.java @@ -34,7 +34,7 @@ import org.opendaylight.controller.netconf.client.NetconfClientDispatcherImpl; import org.opendaylight.controller.netconf.client.SimpleNetconfClientSessionListener; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfiguration; import org.opendaylight.controller.netconf.client.conf.NetconfClientConfigurationBuilder; -import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; +import org.opendaylight.controller.netconf.client.TestingNetconfClient; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.AuthenticationHandler; import org.opendaylight.controller.netconf.nettyutil.handler.ssh.authentication.LoginPassword; import org.opendaylight.controller.netconf.ssh.NetconfSSHServer; diff --git a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java index a7a9d7494a..4c0730863f 100644 --- a/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java +++ b/opendaylight/netconf/netconf-it/src/test/java/org/opendaylight/controller/netconf/it/NetconfITTest.java @@ -41,7 +41,7 @@ import org.opendaylight.controller.config.yang.test.impl.NetconfTestImplModuleMX import org.opendaylight.controller.netconf.api.NetconfDocumentedException; import org.opendaylight.controller.netconf.api.NetconfMessage; import org.opendaylight.controller.netconf.client.NetconfClientDispatcher; -import org.opendaylight.controller.netconf.client.test.TestingNetconfClient; +import org.opendaylight.controller.netconf.client.TestingNetconfClient; import org.opendaylight.controller.netconf.util.test.XmlFileLoader; import org.opendaylight.controller.netconf.util.xml.XmlElement; import org.opendaylight.controller.netconf.util.xml.XmlUtil; diff --git a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java index d0d587fb84..08441b4ce5 100644 --- a/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java +++ b/opendaylight/netconf/netconf-monitoring/src/test/java/org/opendaylight/controller/netconf/monitoring/xml/JaxBSerializerTest.java @@ -38,7 +38,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types. public class JaxBSerializerTest { @Test - public void testName() throws Exception { + public void testSerialization() throws Exception { final NetconfMonitoringService service = new NetconfMonitoringService() { @@ -53,29 +53,29 @@ public class JaxBSerializerTest { } }; final NetconfState model = new NetconfState(service); - final String xml = XmlUtil.toString(new JaxBSerializer().toXml(model)); + final String xml = XmlUtil.toString(new JaxBSerializer().toXml(model)).replaceAll("\\s", ""); assertThat(xml, CoreMatchers.containsString( - "\n" + - "yang\n" + - "id\n" + - "NETCONF\n" + - "localhost\n" + - "v1\n" + - "\n")); + "" + + "yang" + + "id" + + "NETCONF" + + "localhost" + + "v1" + + "")); assertThat(xml, CoreMatchers.containsString( - "\n" + - "1\n" + - "0\n" + - "0\n" + - "loginTime\n" + - "0\n" + - "0\n" + - "client\n" + - "address/port\n" + - "ncme:netconf-tcp\n" + - "username\n" + + "" + + "1" + + "0" + + "0" + + "loginTime" + + "0" + + "0" + + "client" + + "address/port" + + "ncme:netconf-tcp" + + "username" + "")); } diff --git a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoderTest.java b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoderTest.java index f0c0d6341b..ac6370685a 100644 --- a/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoderTest.java +++ b/opendaylight/netconf/netconf-netty-util/src/test/java/org/opendaylight/controller/netconf/nettyutil/handler/NetconfXMLToHelloMessageDecoderTest.java @@ -36,7 +36,7 @@ public class NetconfXMLToHelloMessageDecoderTest { assertThat(out.get(0), CoreMatchers.instanceOf(NetconfHelloMessage.class)); final NetconfHelloMessage hello = (NetconfHelloMessage) out.get(0); assertTrue(hello.getAdditionalHeader().isPresent()); - assertEquals("[tomas;10.0.0.0:10000;tcp;client;]\n", hello.getAdditionalHeader().get().toFormattedString()); + assertEquals("[tomas;10.0.0.0:10000;tcp;client;]" + System.lineSeparator(), hello.getAdditionalHeader().get().toFormattedString()); assertThat(XmlUtil.toString(hello.getDocument()), CoreMatchers.containsString(" capabilities, long sessionId) throws NetconfDocumentedException { Document doc = createHelloMessageDoc(capabilities); - Element sessionIdElement = doc.createElement(XmlNetconfConstants.SESSION_ID); + Element sessionIdElement = doc.createElementNS(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0, + XmlNetconfConstants.SESSION_ID); sessionIdElement.setTextContent(Long.toString(sessionId)); doc.getDocumentElement().appendChild(sessionIdElement); return new NetconfHelloMessage(doc);