From 76eae321c80a7108a846196de9a5179d4aa49a2c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Wed, 8 Feb 2023 17:44:34 +0100 Subject: [PATCH] Move unit tests to netconf.ssh package UTs should be co-located with the classes they are testing, clean that up. Change-Id: I59babf5ad47427a2bdb3e9145c2f0284d59a976c Signed-off-by: Robert Varga --- .../netconf/{netty => ssh}/EchoClient.java | 4 ++-- .../{netty => ssh}/EchoClientHandler.java | 23 ++++++++----------- .../netconf/{netty => ssh}/EchoServer.java | 4 ++-- .../{netty => ssh}/EchoServerHandler.java | 9 ++++---- .../{netty => ssh}/ProxyClientHandler.java | 2 +- .../netconf/{netty => ssh}/ProxyServer.java | 2 +- .../{netty => ssh}/ProxyServerHandler.java | 17 +++++++------- .../{authentication => }/SSHServerTest.java | 4 +--- .../netconf/{netty => ssh}/SSHTest.java | 6 ++--- 9 files changed, 31 insertions(+), 40 deletions(-) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/EchoClient.java (95%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/EchoClientHandler.java (81%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/EchoServer.java (98%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/EchoServerHandler.java (87%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/ProxyClientHandler.java (97%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/ProxyServer.java (98%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/ProxyServerHandler.java (79%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/{authentication => }/SSHServerTest.java (95%) rename netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/{netty => ssh}/SSHTest.java (95%) diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClient.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoClient.java similarity index 95% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClient.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoClient.java index 359f9dfbdc..25d855ae5e 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClient.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoClient.java @@ -5,7 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; @@ -32,7 +32,7 @@ public class EchoClient extends Thread { public EchoClient(final ChannelHandler clientHandler) { channelInitializer = new ChannelInitializer<>() { @Override - public void initChannel(final LocalChannel ch) throws Exception { + public void initChannel(final LocalChannel ch) { ch.pipeline().addLast(clientHandler); } }; diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClientHandler.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoClientHandler.java similarity index 81% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClientHandler.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoClientHandler.java index 8f990380a3..b9ce2e52ba 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoClientHandler.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoClientHandler.java @@ -5,8 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import static com.google.common.base.Preconditions.checkState; import static java.nio.charset.StandardCharsets.UTF_8; @@ -26,20 +25,18 @@ import org.slf4j.LoggerFactory; * the server. */ public class EchoClientHandler extends ChannelInboundHandlerAdapter implements ChannelFutureListener { - private static final Logger LOG = LoggerFactory.getLogger(EchoClientHandler.class); - - private ChannelHandlerContext context; - private final StringBuilder fromServer = new StringBuilder(); - public enum State { CONNECTING, CONNECTED, FAILED_TO_CONNECT, CONNECTION_CLOSED } + private static final Logger LOG = LoggerFactory.getLogger(EchoClientHandler.class); + private final StringBuilder fromServer = new StringBuilder(); + private ChannelHandlerContext context; private State state = State.CONNECTING; @Override - public synchronized void channelActive(ChannelHandlerContext ctx) { + public synchronized void channelActive(final ChannelHandlerContext ctx) { checkState(context == null); LOG.info("channelActive"); context = ctx; @@ -47,12 +44,12 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter implements C } @Override - public synchronized void channelInactive(ChannelHandlerContext ctx) throws Exception { + public synchronized void channelInactive(final ChannelHandlerContext ctx) throws Exception { state = State.CONNECTION_CLOSED; } @Override - public synchronized void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + public synchronized void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception { ByteBuf bb = (ByteBuf) msg; String string = bb.toString(UTF_8); fromServer.append(string); @@ -61,7 +58,7 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter implements C } @Override - public synchronized void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + public synchronized void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { // Close the connection when an exception is raised. LOG.warn("Unexpected exception from downstream.", cause); checkState(context.equals(ctx)); @@ -69,7 +66,7 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter implements C context = null; } - public synchronized void write(String message) { + public synchronized void write(final String message) { ByteBuf byteBuf = Unpooled.copiedBuffer(message.getBytes()); context.writeAndFlush(byteBuf); } @@ -83,7 +80,7 @@ public class EchoClientHandler extends ChannelInboundHandlerAdapter implements C } @Override - public synchronized void operationComplete(ChannelFuture future) throws Exception { + public synchronized void operationComplete(final ChannelFuture future) throws Exception { checkState(state == State.CONNECTING); if (future.isSuccess()) { LOG.trace("Successfully connected, state will be switched in channelActive"); diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServer.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoServer.java similarity index 98% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServer.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoServer.java index 18b83b5193..6013f77ec4 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServer.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoServer.java @@ -5,7 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; @@ -44,7 +44,7 @@ public class EchoServer implements Runnable { .handler(new LoggingHandler(LogLevel.INFO)) .childHandler(new ChannelInitializer() { @Override - public void initChannel(final LocalChannel ch) throws Exception { + public void initChannel(final LocalChannel ch) { ch.pipeline().addLast(new EchoServerHandler()); } }); diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServerHandler.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoServerHandler.java similarity index 87% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServerHandler.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoServerHandler.java index 632d207ea7..c5240e4943 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/EchoServerHandler.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/EchoServerHandler.java @@ -5,8 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import com.google.common.base.Splitter; import io.netty.buffer.ByteBuf; @@ -28,14 +27,14 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter { private final Splitter splitter = Splitter.onPattern("\r?\n"); @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { + public void channelActive(final ChannelHandlerContext ctx) throws Exception { LOG.debug("sleep start"); Thread.sleep(1000); LOG.debug("sleep done"); } @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + public void channelRead(final ChannelHandlerContext ctx, final Object msg) { ByteBuf byteBuf = (ByteBuf) msg; String message = byteBuf.toString(StandardCharsets.UTF_8); LOG.info("writing back '{}'", message); @@ -55,7 +54,7 @@ public class EchoServerHandler extends ChannelInboundHandlerAdapter { } @Override - public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { + public void channelReadComplete(final ChannelHandlerContext ctx) { LOG.debug("flushing"); ctx.flush(); } diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyClientHandler.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyClientHandler.java similarity index 97% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyClientHandler.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyClientHandler.java index dd1daedaa6..abfa7b8985 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyClientHandler.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyClientHandler.java @@ -5,7 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServer.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyServer.java similarity index 98% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServer.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyServer.java index 01a1261849..50bb8b29ee 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServer.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyServer.java @@ -5,7 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelFuture; diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServerHandler.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyServerHandler.java similarity index 79% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServerHandler.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyServerHandler.java index c70efcdb34..1b8995d54f 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/ProxyServerHandler.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/ProxyServerHandler.java @@ -5,8 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import io.netty.bootstrap.Bootstrap; import io.netty.buffer.Unpooled; @@ -29,18 +28,18 @@ public class ProxyServerHandler extends ChannelInboundHandlerAdapter { private Channel clientChannel; - public ProxyServerHandler(EventLoopGroup bossGroup, LocalAddress localAddress) { + public ProxyServerHandler(final EventLoopGroup bossGroup, final LocalAddress localAddress) { clientBootstrap = new Bootstrap(); clientBootstrap.group(bossGroup).channel(LocalChannel.class); this.localAddress = localAddress; } @Override - public void channelActive(ChannelHandlerContext remoteCtx) { + public void channelActive(final ChannelHandlerContext remoteCtx) { final ProxyClientHandler clientHandler = new ProxyClientHandler(remoteCtx); clientBootstrap.handler(new ChannelInitializer() { @Override - public void initChannel(LocalChannel ch) throws Exception { + public void initChannel(final LocalChannel ch) { ch.pipeline().addLast(clientHandler); } }); @@ -50,25 +49,25 @@ public class ProxyServerHandler extends ChannelInboundHandlerAdapter { } @Override - public void channelInactive(ChannelHandlerContext ctx) { + public void channelInactive(final ChannelHandlerContext ctx) { LOG.info("channelInactive - closing client connection"); clientChannel.close(); } @Override - public void channelRead(ChannelHandlerContext ctx, final Object msg) { + public void channelRead(final ChannelHandlerContext ctx, final Object msg) { LOG.debug("Writing to client {}", msg); clientChannel.write(msg); } @Override - public void channelReadComplete(ChannelHandlerContext ctx) { + public void channelReadComplete(final ChannelHandlerContext ctx) { LOG.debug("flushing"); clientChannel.flush(); } @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { // Close the connection when an exception is raised. LOG.warn("Unexpected exception from downstream.", cause); ctx.close(); diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/authentication/SSHServerTest.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/SSHServerTest.java similarity index 95% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/authentication/SSHServerTest.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/SSHServerTest.java index e040304b32..ff085de5c5 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/authentication/SSHServerTest.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/SSHServerTest.java @@ -5,7 +5,7 @@ * 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.netconf.ssh.authentication; +package org.opendaylight.netconf.ssh; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; @@ -23,8 +23,6 @@ import org.opendaylight.netconf.shaded.sshd.client.future.AuthFuture; import org.opendaylight.netconf.shaded.sshd.client.future.ConnectFuture; import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession; import org.opendaylight.netconf.shaded.sshd.common.util.security.SecurityUtils; -import org.opendaylight.netconf.ssh.SshProxyServer; -import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder; import org.opendaylight.netconf.util.NetconfConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/SSHTest.java b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/SSHTest.java similarity index 95% rename from netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/SSHTest.java rename to netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/SSHTest.java index eb757eb01e..5673c592db 100644 --- a/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/netty/SSHTest.java +++ b/netconf/mdsal-netconf-ssh/src/test/java/org/opendaylight/netconf/ssh/SSHTest.java @@ -5,7 +5,7 @@ * 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.netconf.netty; +package org.opendaylight.netconf.ssh; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -28,12 +28,10 @@ import java.util.concurrent.TimeUnit; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import org.opendaylight.netconf.netty.EchoClientHandler.State; import org.opendaylight.netconf.nettyutil.handler.ssh.authentication.LoginPasswordHandler; import org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler; import org.opendaylight.netconf.shaded.sshd.common.util.security.SecurityUtils; -import org.opendaylight.netconf.ssh.SshProxyServer; -import org.opendaylight.netconf.ssh.SshProxyServerConfigurationBuilder; +import org.opendaylight.netconf.ssh.EchoClientHandler.State; import org.opendaylight.netconf.util.NetconfConfiguration; public class SSHTest { -- 2.36.6