You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2015/05/18 12:38:05 UTC
[3/3] mina-sshd git commit: [SSHD-464] Make BaseTest extend
org.junit.Assert instead of TestWatcher
[SSHD-464] Make BaseTest extend org.junit.Assert instead of TestWatcher
Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/bd1d975a
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/bd1d975a
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/bd1d975a
Branch: refs/heads/master
Commit: bd1d975ad3b6fd35113855a30e2d54dbdf7e29d2
Parents: 3689f72
Author: Lyor Goldstein <lg...@vmware.com>
Authored: Mon May 18 13:37:49 2015 +0300
Committer: Lyor Goldstein <lg...@vmware.com>
Committed: Mon May 18 13:37:49 2015 +0300
----------------------------------------------------------------------
.../sshd/common/channel/AbstractChannel.java | 4 +-
.../org/apache/sshd/AbstractSessionTest.java | 18 +-
.../test/java/org/apache/sshd/AgentTest.java | 6 +-
.../org/apache/sshd/AuthenticationTest.java | 13 +-
.../test/java/org/apache/sshd/CipherTest.java | 8 +-
.../test/java/org/apache/sshd/ClientTest.java | 10 +-
.../test/java/org/apache/sshd/EcdsaTest.java | 4 +-
.../java/org/apache/sshd/KeepAliveTest.java | 187 +++++++------
.../java/org/apache/sshd/KeyReExchangeTest.java | 208 ++++++++-------
.../src/test/java/org/apache/sshd/LoadTest.java | 6 +-
.../src/test/java/org/apache/sshd/MacTest.java | 29 +-
.../org/apache/sshd/PortForwardingLoadTest.java | 16 +-
.../org/apache/sshd/PortForwardingTest.java | 13 +-
.../test/java/org/apache/sshd/ProxyTest.java | 7 +-
.../test/java/org/apache/sshd/RandomTest.java | 4 +-
.../src/test/java/org/apache/sshd/ScpTest.java | 9 +-
.../test/java/org/apache/sshd/ServerTest.java | 16 +-
.../org/apache/sshd/SftpFileSystemTest.java | 11 +-
.../src/test/java/org/apache/sshd/SftpTest.java | 13 +-
.../apache/sshd/SinglePublicKeyAuthTest.java | 14 +-
.../java/org/apache/sshd/SpringConfigTest.java | 4 +-
.../java/org/apache/sshd/SshBuilderTest.java | 19 +-
.../java/org/apache/sshd/SshServerTest.java | 64 ++---
.../java/org/apache/sshd/WelcomeBannerTest.java | 11 +-
.../java/org/apache/sshd/WindowAdjustTest.java | 49 +++-
.../test/java/org/apache/sshd/WindowTest.java | 7 +-
.../org/apache/sshd/client/kex/KexTest.java | 7 +-
.../channel/ChannelPipedInputStreamTest.java | 34 ++-
.../sshd/common/cipher/BaseCipherTest.java | 7 +-
.../sshd/common/cipher/BuiltinCiphersTest.java | 39 ++-
.../compression/BuiltinCompressionsTest.java | 33 ++-
.../common/compression/CompressionTest.java | 6 +-
.../common/config/SshConfigFileReaderTest.java | 41 ++-
.../sshd/common/config/TimeValueConfigTest.java | 7 +-
.../sshd/common/file/util/BasePathTest.java | 14 +-
.../apache/sshd/common/future/FutureTest.java | 6 +-
.../sshd/common/kex/BuiltinDHFactoriesTest.java | 27 +-
.../apache/sshd/common/mac/BuiltinMacsTest.java | 33 ++-
.../common/signature/BuiltinSignaturesTest.java | 27 +-
.../org/apache/sshd/common/util/BufferTest.java | 6 +-
.../sshd/common/util/CloseableUtilsTest.java | 25 +-
.../common/util/EventListenerUtilsTest.java | 11 +-
.../sshd/common/util/GenericUtilsTest.java | 9 +-
.../sshd/common/util/SttySupportTest.java | 4 +-
.../sshd/common/util/ThreadUtilsTest.java | 21 +-
.../sshd/common/util/ValidateUtilsTest.java | 4 +-
.../deprecated/ClientUserAuthServiceOld.java | 5 +
.../deprecated/UserAuthKeyboardInteractive.java | 13 +-
.../sshd/deprecated/UserAuthPassword.java | 1 +
.../sshd/server/channel/ChannelSessionTest.java | 29 +-
.../server/command/ScpCommandFactoryTest.java | 31 ++-
.../jaas/JaasPasswordAuthenticatorTest.java | 17 +-
.../AbstractGeneratorHostKeyProviderTest.java | 6 +-
.../PEMGeneratorHostKeyProviderTest.java | 7 +-
.../SimpleGeneratorHostKeyProviderTest.java | 7 +-
.../server/sftp/SftpSubsystemFactoryTest.java | 23 +-
.../server/shell/InvertedShellWrapperTest.java | 6 +-
.../apache/sshd/util/AsyncEchoShellFactory.java | 6 +
.../java/org/apache/sshd/util/BaseTest.java | 267 -------------------
.../org/apache/sshd/util/BaseTestSupport.java | 264 ++++++++++++++++++
.../java/org/apache/sshd/util/BogusChannel.java | 9 +-
.../org/apache/sshd/util/BogusEnvironment.java | 6 +
.../org/apache/sshd/util/BogusExitCallback.java | 2 +
.../apache/sshd/util/BogusForwardingFilter.java | 4 +
.../apache/sshd/util/BogusInvertedShell.java | 7 +
.../sshd/util/BogusPublickeyAuthenticator.java | 1 +
.../org/apache/sshd/util/EchoShellFactory.java | 8 +
.../java/org/apache/sshd/util/JSchLogger.java | 7 +-
.../org/apache/sshd/util/SimpleUserInfo.java | 8 +
69 files changed, 960 insertions(+), 885 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
index 88ff823..51a8a08 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/channel/AbstractChannel.java
@@ -219,7 +219,9 @@ public abstract class AbstractChannel extends CloseableUtils.AbstractInnerClosea
@Override
protected void doCloseImmediately() {
- service.unregisterChannel(AbstractChannel.this);
+ if (service != null) {
+ service.unregisterChannel(AbstractChannel.this);
+ }
super.doCloseImmediately();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
index 5f9428d..15ff2a3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AbstractSessionTest.java
@@ -18,15 +18,12 @@
*/
package org.apache.sshd;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
import java.io.IOException;
import org.apache.sshd.common.session.AbstractSession;
import org.apache.sshd.common.util.buffer.Buffer;
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.junit.Before;
import org.junit.Test;
@@ -35,7 +32,7 @@ import org.junit.Test;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class AbstractSessionTest extends BaseTest {
+public class AbstractSessionTest extends BaseTestSupport {
private MySession session;
@@ -79,6 +76,7 @@ public class AbstractSessionTest extends BaseTest {
public void testReadIdentBadLineEnding() {
Buffer buf = new ByteArrayBuffer(("SSH-2.0-software\ra").getBytes());
String ident = session.doReadIdentification(buf);
+ fail("Unexpected success: " + ident);
}
@Test(expected = IllegalStateException.class)
@@ -91,6 +89,7 @@ public class AbstractSessionTest extends BaseTest {
"01234567890123456789012345678901234567890123456789" +
"01234567890123456789012345678901234567890123456789").getBytes());
String ident = session.doReadIdentification(buf);
+ fail("Unexpected success: " + ident);
}
@Test(expected = IllegalStateException.class)
@@ -102,14 +101,18 @@ public class AbstractSessionTest extends BaseTest {
sb.append("SSH-2.0-software\r\n");
Buffer buf = new ByteArrayBuffer(sb.toString().getBytes());
String ident = session.doReadIdentification(buf);
+ fail("Unexpected success: " + ident);
}
public static class MySession extends AbstractSession {
public MySession() {
super(true, SshServer.setUpDefaultServer(), null);
}
+ @Override
protected void handleMessage(Buffer buffer) throws Exception {
+ // ignored
}
+ @Override
protected boolean readIdentification(Buffer buffer) {
return false;
}
@@ -118,18 +121,23 @@ public class AbstractSessionTest extends BaseTest {
}
@Override
protected void sendKexInit() throws IOException {
+ // ignored
}
@Override
protected void checkKeys() {
+ // ignored
}
@Override
protected void receiveKexInit(Buffer buffer) throws IOException {
+ // ignored
}
@Override
public void startService(String name) throws Exception {
+ // ignored
}
@Override
public void resetIdleTimeout() {
+ // ignored
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AgentTest.java b/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
index d4549aa..041ac15 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AgentTest.java
@@ -20,8 +20,6 @@ package org.apache.sshd;
import static org.apache.sshd.util.Utils.createTestKeyPairProvider;
import static org.hamcrest.CoreMatchers.notNullValue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeThat;
import java.io.ByteArrayOutputStream;
@@ -41,14 +39,14 @@ import org.apache.sshd.common.KeyPairProvider;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.BogusPublickeyAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.Test;
-public class AgentTest extends BaseTest {
+public class AgentTest extends BaseTestSupport {
@Test
public void testAgent() throws Exception {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
index 4a86365..5a3752e 100644
--- a/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/AuthenticationTest.java
@@ -36,7 +36,7 @@ import org.apache.sshd.deprecated.UserAuthPublicKey;
import org.apache.sshd.server.ServerFactoryManager;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.session.SessionFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.BogusPublickeyAuthenticator;
import org.apache.sshd.util.Utils;
@@ -44,11 +44,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class AuthenticationTest extends BaseTest {
+public class AuthenticationTest extends BaseTestSupport {
private static final String WELCOME = "Welcome to SSHD";
@@ -61,8 +57,8 @@ public class AuthenticationTest extends BaseTest {
sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new BogusPublickeyAuthenticator());
- sshd.getProperties().put(SshServer.WELCOME_BANNER, WELCOME);
- sshd.getProperties().put(SshServer.AUTH_METHODS, "publickey,password publickey,keyboard-interactive");
+ sshd.getProperties().put(ServerFactoryManager.WELCOME_BANNER, WELCOME);
+ sshd.getProperties().put(ServerFactoryManager.AUTH_METHODS, "publickey,password publickey,keyboard-interactive");
sshd.setSessionFactory(new SessionFactory() {
@Override
protected AbstractSession doCreateSession(IoSession ioSession) throws Exception {
@@ -179,6 +175,7 @@ public class AuthenticationTest extends BaseTest {
public TestSession(ServerFactoryManager server, IoSession ioSession) throws Exception {
super(server, ioSession);
}
+ @Override
public void handleMessage(Buffer buffer) throws Exception {
super.handleMessage(buffer);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java b/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
index faa2c1f..eb200a9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/CipherTest.java
@@ -28,7 +28,7 @@ import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.Random;
import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.random.BouncyCastleRandom;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
@@ -37,14 +37,12 @@ import org.apache.sshd.util.Utils;
import org.junit.After;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
/**
* Test Cipher algorithms.
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class CipherTest extends BaseTest {
+public class CipherTest extends BaseTestSupport {
private SshServer sshd;
private int port;
@@ -164,7 +162,7 @@ public class CipherTest extends BaseTest {
static boolean checkCipher(String cipher){
try{
- Class c=Class.forName(cipher);
+ Class<?> c=Class.forName(cipher);
com.jcraft.jsch.Cipher _c = (com.jcraft.jsch.Cipher)(c.newInstance());
_c.init(com.jcraft.jsch.Cipher.ENCRYPT_MODE,
new byte[_c.getBlockSize()],
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
index 5c75dc5..872ae6c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ClientTest.java
@@ -18,12 +18,6 @@
*/
package org.apache.sshd;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -86,7 +80,7 @@ import org.apache.sshd.server.session.ServerConnectionService;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.session.ServerUserAuthService;
import org.apache.sshd.util.AsyncEchoShellFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.BogusPublickeyAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
@@ -101,7 +95,7 @@ import org.junit.Test;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ClientTest extends BaseTest {
+public class ClientTest extends BaseTestSupport {
private SshServer sshd;
private SshClient client;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java b/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
index e5d5b1a..9e59b7a 100644
--- a/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/EcdsaTest.java
@@ -35,7 +35,7 @@ import org.apache.sshd.common.signature.BuiltinSignatures;
import org.apache.sshd.common.util.SecurityUtils;
import org.apache.sshd.server.PublickeyAuthenticator;
import org.apache.sshd.server.session.ServerSession;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.Utils;
import org.junit.After;
@@ -48,7 +48,7 @@ import org.junit.Test;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class EcdsaTest extends BaseTest {
+public class EcdsaTest extends BaseTestSupport {
private SshServer sshd;
private SshClient client;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
index 0b51c33..6f9c81c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeepAliveTest.java
@@ -20,11 +20,13 @@ package org.apache.sshd;
import java.io.ByteArrayOutputStream;
import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.apache.sshd.client.ClientFactoryManager;
+import org.apache.sshd.common.FactoryManager;
+import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.server.Command;
-import org.apache.sshd.server.ServerFactoryManager;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.BogusPublickeyAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
@@ -33,14 +35,12 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
/**
* TODO Add javadoc
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class KeepAliveTest extends BaseTest {
+public class KeepAliveTest extends BaseTestSupport {
private SshServer sshd;
private int port;
@@ -52,7 +52,7 @@ public class KeepAliveTest extends BaseTest {
@Before
public void setUp() throws Exception {
sshd = SshServer.setUpDefaultServer();
- sshd.getProperties().put(ServerFactoryManager.IDLE_TIMEOUT, Integer.toString(timeout));
+ sshd.getProperties().put(FactoryManager.IDLE_TIMEOUT, Integer.toString(timeout));
sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
sshd.setShellFactory(new TestEchoShellFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
@@ -72,66 +72,82 @@ public class KeepAliveTest extends BaseTest {
public void testClient() throws Exception {
SshClient client = SshClient.setUpDefaultClient();
client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
-
- int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF, state);
-
- channel.close(false);
- client.stop();
+
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) {
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF, state);
+
+ channel.close(false);
+ }
+ } finally {
+ client.stop();
+ }
}
@Test
public void testClientNew() throws Exception {
SshClient client = SshClient.setUpDefaultClient();
client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
-
- int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF, state);
-
- channel.close(false);
- client.stop();
+
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) {
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF, state);
+
+ channel.close(false);
+ }
+ } finally {
+ client.stop();
+ }
}
@Test
public void testClientWithHeartBeat() throws Exception {
SshClient client = SshClient.setUpDefaultClient();
- client.getProperties().put(ClientFactoryManager.HEARTBEAT_INTERVAL, Integer.toString(heartbeat));
+ FactoryManagerUtils.updateProperty(client, ClientFactoryManager.HEARTBEAT_INTERVAL, heartbeat);
client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
- int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertEquals("Wrong channel state", ClientChannel.TIMEOUT, state);
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
- channel.close(false);
- client.stop();
+ try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) {
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.TIMEOUT, state);
+
+ channel.close(false);
+ }
+ } finally {
+ client.stop();
+ }
}
@Test
public void testClientWithHeartBeatNew() throws Exception {
SshClient client = SshClient.setUpDefaultClient();
- client.getProperties().put(ClientFactoryManager.HEARTBEAT_INTERVAL, Integer.toString(heartbeat));
+ FactoryManagerUtils.updateProperty(client, ClientFactoryManager.HEARTBEAT_INTERVAL, heartbeat);
client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
- int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertEquals("Wrong channel state", ClientChannel.TIMEOUT, state);
-
- channel.close(false);
- client.stop();
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) {
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.TIMEOUT, state);
+
+ channel.close(false);
+ }
+ } finally {
+ client.stop();
+ }
}
@Test
@@ -140,23 +156,28 @@ public class KeepAliveTest extends BaseTest {
SshClient client = SshClient.setUpDefaultClient();
client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ByteArrayOutputStream err = new ByteArrayOutputStream();
- channel.setOut(out);
- channel.setErr(err);
- channel.open().await();
-
-
- TestEchoShellFactory.TestEchoShell.latch.await();
- int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF | ClientChannel.OPENED, state);
-
- channel.close(false);
- client.stop();
+
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream()) {
+
+ channel.setOut(out);
+ channel.setErr(err);
+ channel.open().await();
+
+ assertTrue("Latch time out", TestEchoShellFactory.TestEchoShell.latch.await(10L, TimeUnit.SECONDS));
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF | ClientChannel.OPENED, state);
+
+ channel.close(false);
+ }
+ } finally {
+ client.stop();
+ }
}
@Test
@@ -165,31 +186,36 @@ public class KeepAliveTest extends BaseTest {
SshClient client = SshClient.setUpDefaultClient();
client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ByteArrayOutputStream err = new ByteArrayOutputStream();
- channel.setOut(out);
- channel.setErr(err);
- channel.open().await();
-
-
- TestEchoShellFactory.TestEchoShell.latch.await();
- int state = channel.waitFor(ClientChannel.CLOSED, wait);
- assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF | ClientChannel.OPENED, state);
-
- channel.close(false);
- client.stop();
- }
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ try(ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream()) {
+
+ channel.setOut(out);
+ channel.setErr(err);
+ channel.open().await();
+
+ assertTrue("Latch time out", TestEchoShellFactory.TestEchoShell.latch.await(10L, TimeUnit.SECONDS));
+ int state = channel.waitFor(ClientChannel.CLOSED, wait);
+ assertEquals("Wrong channel state", ClientChannel.CLOSED | ClientChannel.EOF | ClientChannel.OPENED, state);
+
+ channel.close(false);
+ }
+ } finally {
+ client.stop();
+ }
+ }
public static class TestEchoShellFactory extends EchoShellFactory {
@Override
public Command create() {
return new TestEchoShell();
}
+
public static class TestEchoShell extends EchoShell {
public static CountDownLatch latch;
@@ -203,5 +229,4 @@ public class KeepAliveTest extends BaseTest {
}
}
}
-
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
index 34e1560..5acf117 100644
--- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java
@@ -23,14 +23,16 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import com.jcraft.jsch.JSch;
+
import org.apache.sshd.client.channel.ChannelShell;
import org.apache.sshd.common.Session;
import org.apache.sshd.common.SessionListener;
import org.apache.sshd.server.ServerFactoryManager;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
@@ -40,16 +42,12 @@ import org.apache.sshd.util.Utils;
import org.junit.After;
import org.junit.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
/**
* Test key exchange algorithms.
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class KeyReExchangeTest extends BaseTest {
+public class KeyReExchangeTest extends BaseTestSupport {
private SshServer sshd;
private int port;
@@ -105,104 +103,124 @@ public class KeyReExchangeTest extends BaseTest {
public void testReExchangeFromNativeClient() throws Exception {
setUp(0, 0);
- SshClient client = SshClient.setUpDefaultClient();
- client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ChannelShell channel = session.createShellChannel();
-
- ByteArrayOutputStream sent = new ByteArrayOutputStream();
- PipedOutputStream pipedIn = new PipedOutputStream();
- channel.setIn(new PipedInputStream(pipedIn));
- OutputStream teeOut = new TeeOutputStream(sent, pipedIn);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ByteArrayOutputStream err = new ByteArrayOutputStream();
- channel.setOut(out);
- channel.setErr(err);
- channel.open();
-
- teeOut.write("this is my command\n".getBytes());
- teeOut.flush();
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 10; i++) {
- sb.append("0123456789");
- }
- sb.append("\n");
-
- for (int i = 0; i < 10; i++) {
- teeOut.write(sb.toString().getBytes());
- teeOut.flush();
- session.reExchangeKeys();
+ try(SshClient client = SshClient.setUpDefaultClient()) {
+ client.start();
+
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ try(ChannelShell channel = session.createShellChannel();
+ ByteArrayOutputStream sent = new ByteArrayOutputStream();
+ PipedOutputStream pipedIn = new PipedOutputStream();
+ InputStream inPipe = new PipedInputStream(pipedIn);
+ OutputStream teeOut = new TeeOutputStream(sent, pipedIn);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream()) {
+
+ channel.setIn(inPipe);
+ channel.setOut(out);
+ channel.setErr(err);
+ channel.open();
+
+ teeOut.write("this is my command\n".getBytes());
+ teeOut.flush();
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 10; i++) {
+ sb.append("0123456789");
+ }
+ sb.append("\n");
+
+ byte[] data=sb.toString().getBytes();
+ for (int i = 0; i < 10; i++) {
+ teeOut.write(data);
+ teeOut.flush();
+ session.reExchangeKeys();
+ }
+ teeOut.write("exit\n".getBytes());
+ teeOut.flush();
+
+ channel.waitFor(ClientChannel.CLOSED, 0);
+
+ channel.close(false);
+
+ assertArrayEquals("Mismatched sent data content", sent.toByteArray(), out.toByteArray());
+ }
+ } finally {
+ client.stop();
+ }
}
- teeOut.write("exit\n".getBytes());
- teeOut.flush();
-
- channel.waitFor(ClientChannel.CLOSED, 0);
-
- channel.close(false);
- client.stop();
-
- assertArrayEquals(sent.toByteArray(), out.toByteArray());
}
@Test
public void testReExchangeFromServer() throws Exception {
setUp(8192, 0);
- SshClient client = SshClient.setUpDefaultClient();
- client.start();
- ClientSession session = client.connect("smx", "localhost", port).await().getSession();
- session.addPasswordIdentity("smx");
- session.auth().verify();
- ChannelShell channel = session.createShellChannel();
-
- ByteArrayOutputStream sent = new ByteArrayOutputStream();
- PipedOutputStream pipedIn = new PipedOutputStream();
- channel.setIn(new PipedInputStream(pipedIn));
- OutputStream teeOut = new TeeOutputStream(sent, pipedIn);
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- ByteArrayOutputStream err = new ByteArrayOutputStream();
- channel.setOut(out);
- channel.setErr(err);
- channel.open();
-
- teeOut.write("this is my command\n".getBytes());
- teeOut.flush();
-
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < 100; i++) {
- sb.append("0123456789");
- }
- sb.append("\n");
-
- final AtomicInteger exchanges = new AtomicInteger();
- session.addListener(new SessionListener() {
- public void sessionCreated(Session session) {
- }
- public void sessionEvent(Session session, Event event) {
- if (event == Event.KeyEstablished) {
- exchanges.incrementAndGet();
+ try(SshClient client = SshClient.setUpDefaultClient()) {
+ client.start();
+
+ try(ClientSession session = client.connect("smx", "localhost", port).await().getSession()) {
+ session.addPasswordIdentity("smx");
+ session.auth().verify(5L, TimeUnit.SECONDS);
+
+ try(ChannelShell channel = session.createShellChannel();
+ ByteArrayOutputStream sent = new ByteArrayOutputStream();
+ PipedOutputStream pipedIn = new PipedOutputStream();
+ OutputStream teeOut = new TeeOutputStream(sent, pipedIn);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ ByteArrayOutputStream err = new ByteArrayOutputStream();
+ InputStream inPipe = new PipedInputStream(pipedIn)) {
+
+ channel.setIn(inPipe);
+ channel.setOut(out);
+ channel.setErr(err);
+ channel.open();
+
+ teeOut.write("this is my command\n".getBytes());
+ teeOut.flush();
+
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < 100; i++) {
+ sb.append("0123456789");
+ }
+ sb.append("\n");
+
+ final AtomicInteger exchanges = new AtomicInteger();
+ session.addListener(new SessionListener() {
+ @Override
+ public void sessionCreated(Session session) {
+ // ignored
+ }
+ @Override
+ public void sessionEvent(Session session, Event event) {
+ if (event == Event.KeyEstablished) {
+ exchanges.incrementAndGet();
+ }
+ }
+ @Override
+ public void sessionClosed(Session session) {
+ // ignored
+ }
+ });
+ for (int i = 0; i < 100; i++) {
+ teeOut.write(sb.toString().getBytes());
+ teeOut.flush();
+ }
+ teeOut.write("exit\n".getBytes());
+ teeOut.flush();
+
+ channel.waitFor(ClientChannel.CLOSED, 0);
+
+ channel.close(false);
+
+ assertTrue("Expected rekeying", exchanges.get() > 0);
+ assertEquals("Mismatched sent data length", sent.toByteArray().length, out.toByteArray().length);
+ assertArrayEquals("Mismatched sent data content", sent.toByteArray(), out.toByteArray());
}
+ } finally {
+ client.stop();
}
- public void sessionClosed(Session session) {
- }
- });
- for (int i = 0; i < 100; i++) {
- teeOut.write(sb.toString().getBytes());
- teeOut.flush();
}
- teeOut.write("exit\n".getBytes());
- teeOut.flush();
-
- channel.waitFor(ClientChannel.CLOSED, 0);
-
- channel.close(false);
- client.stop();
-
- assertTrue("Expected rekeying", exchanges.get() > 0);
- assertEquals(sent.toByteArray().length, out.toByteArray().length);
- assertArrayEquals(sent.toByteArray(), out.toByteArray());
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
index cc156b7..4a4e2ca 100644
--- a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java
@@ -32,7 +32,7 @@ import org.apache.sshd.common.FactoryManagerUtils;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.kex.BuiltinDHFactories;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
@@ -40,9 +40,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertArrayEquals;
-
-public class LoadTest extends BaseTest {
+public class LoadTest extends BaseTestSupport {
private SshServer sshd;
private int port;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/MacTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/MacTest.java b/sshd-core/src/test/java/org/apache/sshd/MacTest.java
index c8d97d3..bba527a 100644
--- a/sshd-core/src/test/java/org/apache/sshd/MacTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/MacTest.java
@@ -30,7 +30,7 @@ import org.apache.sshd.common.Random;
import org.apache.sshd.common.cipher.BuiltinCiphers;
import org.apache.sshd.common.mac.BuiltinMacs;
import org.apache.sshd.common.random.BouncyCastleRandom;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
@@ -40,14 +40,12 @@ import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-
/**
* Test Cipher algorithms.
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class MacTest extends BaseTest {
+public class MacTest extends BaseTestSupport {
private SshServer sshd;
private int port;
@@ -147,17 +145,20 @@ public class MacTest extends BaseTest {
s.connect();
com.jcraft.jsch.Channel c = s.openChannel("shell");
c.connect();
- OutputStream os = c.getOutputStream();
- InputStream is = c.getInputStream();
- for (int i = 0; i < 10; i++) {
- os.write("this is my command\n".getBytes());
- os.flush();
+ try(OutputStream os = c.getOutputStream();
+ InputStream is = c.getInputStream()) {
+
byte[] data = new byte[512];
- int len = is.read(data);
- String str = new String(data, 0, len);
- assertEquals("this is my command\n", str);
+ for (int i = 0; i < 10; i++) {
+ os.write("this is my command\n".getBytes());
+ os.flush();
+ int len = is.read(data);
+ String str = new String(data, 0, len);
+ assertEquals("this is my command\n", str);
+ }
+ } finally {
+ c.disconnect();
}
- c.disconnect();
} finally {
s.disconnect();
}
@@ -165,7 +166,7 @@ public class MacTest extends BaseTest {
static boolean checkCipher(String cipher){
try{
- Class c=Class.forName(cipher);
+ Class<?> c=Class.forName(cipher);
com.jcraft.jsch.Cipher _c = (com.jcraft.jsch.Cipher)(c.newInstance());
_c.init(com.jcraft.jsch.Cipher.ENCRYPT_MODE,
new byte[_c.getBlockSize()],
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java b/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
index af63b0c..e6d6b41 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingLoadTest.java
@@ -46,7 +46,7 @@ import org.apache.mina.core.service.IoAcceptor;
import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusForwardingFilter;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
@@ -54,19 +54,16 @@ import org.apache.sshd.util.JSchLogger;
import org.apache.sshd.util.SimpleUserInfo;
import org.apache.sshd.util.Utils;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
import static org.apache.sshd.util.Utils.getFreePort;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
/**
* Port forwarding tests
*/
-public class PortForwardingLoadTest extends BaseTest {
+public class PortForwardingLoadTest extends BaseTestSupport {
private final org.slf4j.Logger log = LoggerFactory.getLogger(getClass());
@@ -136,6 +133,7 @@ public class PortForwardingLoadTest extends BaseTest {
final AtomicInteger conCount = new AtomicInteger(0);
new Thread() {
+ @Override
public void run() {
try {
for (int i = 0; i < NUM_ITERATIONS; ++i) {
@@ -212,6 +210,7 @@ public class PortForwardingLoadTest extends BaseTest {
final AtomicInteger conCount = new AtomicInteger(0);
new Thread() {
+ @Override
public void run() {
started[0] = true;
try {
@@ -228,7 +227,7 @@ public class PortForwardingLoadTest extends BaseTest {
}
}.start();
Thread.sleep(50);
- Assert.assertTrue("Server not started", started[0]);
+ assertTrue("Server not started", started[0]);
final boolean lenOK[] = new boolean[NUM_ITERATIONS];
final boolean dataOK[] = new boolean[NUM_ITERATIONS];
@@ -261,8 +260,8 @@ public class PortForwardingLoadTest extends BaseTest {
}
Thread.sleep(50);
for (int i = 0; i < NUM_ITERATIONS; i++) {
- Assert.assertTrue(lenOK[i]);
- Assert.assertTrue(dataOK[i]);
+ assertTrue(lenOK[i]);
+ assertTrue(dataOK[i]);
}
session.delPortForwardingR(forwardedPort);
ss.close();
@@ -317,6 +316,7 @@ public class PortForwardingLoadTest extends BaseTest {
final List<Throwable> errors = new CopyOnWriteArrayList<Throwable>();
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {
+ @Override
public void run() {
for (int j = 0; j < nbLoops; j++) {
final MultiThreadedHttpConnectionManager mgr = new MultiThreadedHttpConnectionManager();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
index 5905340..7f85d08 100644
--- a/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/PortForwardingTest.java
@@ -19,8 +19,6 @@
package org.apache.sshd;
import static org.apache.sshd.util.Utils.getFreePort;
-import static org.junit.Assert.assertEquals;
-
import java.lang.reflect.Field;
import java.net.InetSocketAddress;
import java.net.Socket;
@@ -35,7 +33,7 @@ import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.sshd.client.channel.ChannelDirectTcpip;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.SshdSocketAddress;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusForwardingFilter;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
@@ -43,7 +41,6 @@ import org.apache.sshd.util.JSchLogger;
import org.apache.sshd.util.SimpleUserInfo;
import org.apache.sshd.util.Utils;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.LoggerFactory;
@@ -55,7 +52,7 @@ import com.jcraft.jsch.Session;
/**
* Port forwarding tests
*/
-public class PortForwardingTest extends BaseTest {
+public class PortForwardingTest extends BaseTestSupport {
private final org.slf4j.Logger log = LoggerFactory.getLogger(getClass());
@@ -331,10 +328,10 @@ public class PortForwardingTest extends BaseTest {
fSocket.setAccessible(true);
try(Socket socket = (Socket) fSocket.get(session)) {
- Assert.assertTrue("socket is not connected", socket.isConnected());
- Assert.assertFalse("socket should not be closed", socket.isClosed());
+ assertTrue("socket is not connected", socket.isConnected());
+ assertFalse("socket should not be closed", socket.isClosed());
socket.close();
- Assert.assertTrue("socket has not closed", socket.isClosed());
+ assertTrue("socket has not closed", socket.isClosed());
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
index f597b09..ad073ec 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ProxyTest.java
@@ -18,9 +18,6 @@
*/
package org.apache.sshd;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
@@ -33,7 +30,7 @@ import org.apache.mina.core.session.IoSession;
import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
import org.apache.sshd.common.FactoryManager;
import org.apache.sshd.common.SshdSocketAddress;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusForwardingFilter;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
@@ -45,7 +42,7 @@ import org.junit.Test;
/**
* Port forwarding tests
*/
-public class ProxyTest extends BaseTest {
+public class ProxyTest extends BaseTestSupport {
private SshServer sshd;
private int sshPort;
private int echoPort;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/RandomTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/RandomTest.java b/sshd-core/src/test/java/org/apache/sshd/RandomTest.java
index 2d82ef1..77d5190 100644
--- a/sshd-core/src/test/java/org/apache/sshd/RandomTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/RandomTest.java
@@ -21,7 +21,7 @@ package org.apache.sshd;
import org.apache.sshd.common.Random;
import org.apache.sshd.common.random.BouncyCastleRandom;
import org.apache.sshd.common.random.JceRandom;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.junit.Test;
/**
@@ -29,7 +29,7 @@ import org.junit.Test;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class RandomTest extends BaseTest {
+public class RandomTest extends BaseTestSupport {
@Test
public void testJce() {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
index 3efc51d..b059aef 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ScpTest.java
@@ -41,7 +41,7 @@ import org.apache.sshd.client.ScpClient;
import org.apache.sshd.common.scp.ScpTransferEventListener;
import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.server.command.ScpCommandFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
@@ -55,17 +55,12 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
/**
* Test for SCP support.
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ScpTest extends BaseTest {
+public class ScpTest extends BaseTestSupport {
private SshServer sshd;
private int port;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
index 9190800..6abbccc 100644
--- a/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/ServerTest.java
@@ -18,11 +18,6 @@
*/
package org.apache.sshd;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -64,12 +59,11 @@ import org.apache.sshd.server.ExitCallback;
import org.apache.sshd.server.ServerFactoryManager;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.sftp.SftpSubsystemFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
@@ -80,7 +74,7 @@ import org.slf4j.LoggerFactory;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ServerTest extends BaseTest {
+public class ServerTest extends BaseTestSupport {
private SshServer sshd;
private SshClient client;
@@ -358,8 +352,8 @@ public class ServerTest extends BaseTest {
try(ClientSession s = client.connect("test", "localhost", port).await().getSession()) {
s.addPasswordIdentity("test");
s.auth().verify(5L, TimeUnit.SECONDS);
- Assert.assertEquals("Mismatched client events count", 1, clientEventCount.get());
- Assert.assertEquals("Mismatched server events count", 1, serverEventCount.get());
+ assertEquals("Mismatched client events count", 1, clientEventCount.get());
+ assertEquals("Mismatched server events count", 1, serverEventCount.get());
s.close(false);
}
}
@@ -428,7 +422,7 @@ public class ServerTest extends BaseTest {
}
}
- Assert.fail("No success to authenticate");
+ fail("No success to authenticate");
}
public static class TestEchoShellFactory extends EchoShellFactory {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
index 1e0dd98..1ad515b 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SftpFileSystemTest.java
@@ -18,10 +18,6 @@
*/
package org.apache.sshd;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.File;
import java.io.IOException;
import java.net.URI;
@@ -51,16 +47,15 @@ import org.apache.sshd.common.util.OsUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.sftp.SftpSubsystemFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.After;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
-public class SftpFileSystemTest extends BaseTest {
+public class SftpFileSystemTest extends BaseTestSupport {
private SshServer sshd;
private int port;
@@ -187,7 +182,7 @@ public class SftpFileSystemTest extends BaseTest {
Files.write(file, "Hello world\n".getBytes());
Map<String, Object> attrs = Files.readAttributes(file, "posix:*");
- Assert.assertNotNull("NO attributes read for " + file, attrs);
+ assertNotNull("NO attributes read for " + file, attrs);
Files.setAttribute(file, "basic:size", Long.valueOf(2l));
Files.setAttribute(file, "posix:permissions", PosixFilePermissions.fromString("rwxr-----"));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
index cec1d11..7de6da4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SftpTest.java
@@ -22,13 +22,6 @@ import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_FILE_ALREADY_EXIS
import static org.apache.sshd.common.sftp.SftpConstants.SSH_FX_NO_SUCH_FILE;
import static org.apache.sshd.common.sftp.SftpConstants.S_IRUSR;
import static org.apache.sshd.common.sftp.SftpConstants.S_IWUSR;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -47,7 +40,7 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.sftp.SftpSubsystemFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.JSchLogger;
@@ -62,7 +55,7 @@ import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.SftpException;
-public class SftpTest extends BaseTest {
+public class SftpTest extends BaseTestSupport {
private SshServer sshd;
private int port;
@@ -435,7 +428,7 @@ public class SftpTest extends BaseTest {
URI base = new File(System.getProperty("user.dir")).getAbsoluteFile().toURI();
String path = new File(base.relativize(url).getPath()).getParent() + "/";
path = path.replace('\\', '/');
- Vector res = c.ls(path);
+ Vector<?> res = c.ls(path);
for (Object f : res) {
System.out.println(f.toString());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
index 240ba1f..aa288a9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SinglePublicKeyAuthTest.java
@@ -29,25 +29,23 @@ import org.apache.sshd.common.util.KeyUtils;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.PublickeyAuthenticator;
+import org.apache.sshd.server.ServerFactoryManager;
import org.apache.sshd.server.auth.CachingPublicKeyAuthenticator;
import org.apache.sshd.server.command.UnknownCommand;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.Utils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
/**
* TODO Add javadoc
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SinglePublicKeyAuthTest extends BaseTest {
+public class SinglePublicKeyAuthTest extends BaseTestSupport {
private SshServer sshd;
private int port = 0;
@@ -60,12 +58,14 @@ public class SinglePublicKeyAuthTest extends BaseTest {
sshd = SshServer.setUpDefaultServer();
sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
sshd.setCommandFactory(new CommandFactory() {
+ @Override
public Command createCommand(String command) {
return new UnknownCommand(command);
}
});
- sshd.getProperties().put(SshServer.AUTH_METHODS, "publickey");
+ sshd.getProperties().put(ServerFactoryManager.AUTH_METHODS, "publickey");
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
+ @Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return delegate.authenticate(username, key, session);
}
@@ -85,6 +85,7 @@ public class SinglePublicKeyAuthTest extends BaseTest {
public void testPublicKeyAuthWithCache() throws Exception {
final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<String, AtomicInteger>();
TestCachingPublicKeyAuthenticator auth = new TestCachingPublicKeyAuthenticator(new PublickeyAuthenticator() {
+ @Override
public boolean authenticate(String username, PublicKey key,
ServerSession session) {
count.putIfAbsent(KeyUtils.getFingerPrint(key), new AtomicInteger());
@@ -113,6 +114,7 @@ public class SinglePublicKeyAuthTest extends BaseTest {
public void testPublicKeyAuthWithoutCache() throws Exception {
final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<String, AtomicInteger>();
delegate = new PublickeyAuthenticator() {
+ @Override
public boolean authenticate(String username, PublicKey key,
ServerSession session) {
count.putIfAbsent(KeyUtils.getFingerPrint(key), new AtomicInteger());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/SpringConfigTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SpringConfigTest.java b/sshd-core/src/test/java/org/apache/sshd/SpringConfigTest.java
index f5b493b..0c197db 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SpringConfigTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SpringConfigTest.java
@@ -22,7 +22,7 @@ import java.io.OutputStream;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.JSchLogger;
import org.apache.sshd.util.SimpleUserInfo;
import org.junit.After;
@@ -35,7 +35,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SpringConfigTest extends BaseTest {
+public class SpringConfigTest extends BaseTestSupport {
private ClassPathXmlApplicationContext context;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/SshBuilderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SshBuilderTest.java b/sshd-core/src/test/java/org/apache/sshd/SshBuilderTest.java
index d7204de..9307def 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SshBuilderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SshBuilderTest.java
@@ -33,14 +33,13 @@ import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.common.mac.BuiltinMacs;
import org.apache.sshd.common.signature.BuiltinSignatures;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.util.BaseTest;
-import org.junit.Assert;
+import org.apache.sshd.util.BaseTestSupport;
import org.junit.Test;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SshBuilderTest extends BaseTest {
+public class SshBuilderTest extends BaseTestSupport {
public SshBuilderTest() {
super();
}
@@ -53,7 +52,7 @@ public class SshBuilderTest extends BaseTest {
public void testAllBuiltinCiphersListed() {
Set<BuiltinCiphers> all=EnumSet.allOf(BuiltinCiphers.class);
// The 'none' cipher is not listed as preferred - it is implied
- Assert.assertTrue("Missing " + BuiltinCiphers.Constants.NONE + " cipher in all values", all.remove(BuiltinCiphers.none));
+ assertTrue("Missing " + BuiltinCiphers.Constants.NONE + " cipher in all values", all.remove(BuiltinCiphers.none));
testAllInstancesListed(all, BaseBuilder.DEFAULT_CIPHERS_PREFERENCE);
}
@@ -85,9 +84,9 @@ public class SshBuilderTest extends BaseTest {
}
private static <E extends Enum<E>> void testAllInstancesListed(Set<? extends E> expValues, Collection<? extends E> actValues) {
- Assert.assertEquals("Mismatched actual values size", expValues.size(), actValues.size());
+ assertEquals("Mismatched actual values size", expValues.size(), actValues.size());
for (E expected : expValues) {
- Assert.assertTrue(expected.name() + " not found in actual values", actValues.contains(expected));
+ assertTrue(expected.name() + " not found in actual values", actValues.contains(expected));
}
}
@@ -103,7 +102,7 @@ public class SshBuilderTest extends BaseTest {
int numCiphers=GenericUtils.size(ciphers);
// make sure returned list size matches expected count
if (ignoreUnsupported) {
- Assert.assertEquals("Incomplete full ciphers size", BaseBuilder.DEFAULT_CIPHERS_PREFERENCE.size(), numCiphers);
+ assertEquals("Incomplete full ciphers size", BaseBuilder.DEFAULT_CIPHERS_PREFERENCE.size(), numCiphers);
} else {
int expectedCount=0;
for (BuiltinCiphers c : BaseBuilder.DEFAULT_CIPHERS_PREFERENCE) {
@@ -111,7 +110,7 @@ public class SshBuilderTest extends BaseTest {
expectedCount++;
}
}
- Assert.assertEquals("Incomplete supported ciphers size", expectedCount, numCiphers);
+ assertEquals("Incomplete supported ciphers size", expectedCount, numCiphers);
}
// make sure order is according to the default preference list
@@ -123,10 +122,10 @@ public class SshBuilderTest extends BaseTest {
}
String expectedName=c.getName();
- Assert.assertTrue("Out of actual ciphers for expected=" + expectedName, nameIndex < numCiphers);
+ assertTrue("Out of actual ciphers for expected=" + expectedName, nameIndex < numCiphers);
String actualName=cipherNames.get(nameIndex);
- Assert.assertEquals("Mismatched cipher at position " + nameIndex + " for ignoreUnsupported=" + ignoreUnsupported, expectedName, actualName);
+ assertEquals("Mismatched cipher at position " + nameIndex + " for ignoreUnsupported=" + ignoreUnsupported, expectedName, actualName);
nameIndex++;
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java b/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java
index 71a9e43..dbc3614 100644
--- a/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/SshServerTest.java
@@ -21,66 +21,66 @@ package org.apache.sshd;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.Utils;
import org.junit.Test;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-
/**
* @author Kohsuke Kawaguchi
* @author Michael Heemskerk
*/
-public class SshServerTest extends BaseTest {
+public class SshServerTest extends BaseTestSupport {
@Test
public void stopMethodShouldBeIdempotent() throws Exception {
- SshServer sshd = new SshServer();
- sshd.stop();
- sshd.stop();
- sshd.stop();
+ try(SshServer sshd = new SshServer()) {
+ sshd.stop();
+ sshd.stop();
+ sshd.stop();
+ }
}
@Test
public void testExecutorShutdownFalse() throws Exception {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
- SshServer sshd = createTestServer();
- sshd.setScheduledExecutorService(executorService);
-
- sshd.start();
- sshd.stop();
-
- assertFalse(executorService.isShutdown());
- executorService.shutdownNow();
+ try(SshServer sshd = createTestServer()) {
+ sshd.setScheduledExecutorService(executorService);
+
+ sshd.start();
+ sshd.stop();
+
+ assertFalse(executorService.isShutdown());
+ executorService.shutdownNow();
+ }
}
@Test
public void testExecutorShutdownTrue() throws Exception {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
- SshServer sshd = createTestServer();
- sshd.setScheduledExecutorService(executorService, true);
-
- sshd.start();
- sshd.stop();
-
- assertTrue(executorService.isShutdown());
+ try(SshServer sshd = createTestServer()) {
+ sshd.setScheduledExecutorService(executorService, true);
+
+ sshd.start();
+ sshd.stop();
+
+ assertTrue(executorService.isShutdown());
+ }
}
@Test
public void testDynamicPort() throws Exception {
- SshServer sshd = createTestServer();
- sshd.setHost("localhost");
- sshd.start();
-
- assertNotEquals(0, sshd.getPort());
-
- sshd.stop();
+ try(SshServer sshd = createTestServer()) {
+ sshd.setHost("localhost");
+ sshd.start();
+
+ assertNotEquals(0, sshd.getPort());
+
+ sshd.stop();
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java b/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
index 9fae759..eccd879 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WelcomeBannerTest.java
@@ -21,7 +21,8 @@ package org.apache.sshd;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.sshd.client.UserInteraction;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.server.ServerFactoryManager;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.BogusPublickeyAuthenticator;
import org.apache.sshd.util.Utils;
@@ -29,9 +30,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static junit.framework.Assert.assertEquals;
-
-public class WelcomeBannerTest extends BaseTest {
+public class WelcomeBannerTest extends BaseTestSupport {
private static final String WELCOME = "Welcome to SSHD";
@@ -44,7 +43,7 @@ public class WelcomeBannerTest extends BaseTest {
sshd.setKeyPairProvider(Utils.createTestHostKeyProvider());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.setPublickeyAuthenticator(new BogusPublickeyAuthenticator());
- sshd.getProperties().put(SshServer.WELCOME_BANNER, WELCOME);
+ sshd.getProperties().put(ServerFactoryManager.WELCOME_BANNER, WELCOME);
sshd.start();
port = sshd.getPort();
}
@@ -61,9 +60,11 @@ public class WelcomeBannerTest extends BaseTest {
final AtomicReference<String> welcome = new AtomicReference<String>();
SshClient client = SshClient.setUpDefaultClient();
client.setUserInteraction(new UserInteraction() {
+ @Override
public void welcome(String banner) {
welcome.set(banner);
}
+ @Override
public String[] interactive(String destination, String name, String instruction, String[] prompt, boolean[] echo) {
return null;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
index cf56589..1b33f48 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java
@@ -65,6 +65,7 @@ public class WindowAdjustTest {
Paths.get(getClass().getResource("/big-msg.txt").toURI()));
sshServer.setShellFactory(new Factory<Command>() {
+ @Override
public Command create() {
return new FloodingAsyncCommand(msg, 10000, END_FILE);
}
@@ -134,12 +135,18 @@ public class WindowAdjustTest {
this.lastMsg = lastMsg;
}
- public void setIoInputStream(IoInputStream in) {}
+ @Override
+ public void setIoInputStream(IoInputStream in) {
+ // ignored
+ }
+ @Override
public void setIoOutputStream(IoOutputStream out) {
final AsyncInPendingWrapper a = new AsyncInPendingWrapper(out);
new Thread(new Runnable() {
+ @SuppressWarnings("synthetic-access")
+ @Override
public void run() {
for (int i = 0; i < sendCount; i++) {
a.write(new ByteArrayBuffer(msg));
@@ -149,19 +156,40 @@ public class WindowAdjustTest {
}).start();
}
- public void setIoErrorStream(IoOutputStream err) {}
+ @Override
+ public void setIoErrorStream(IoOutputStream err) {
+ // ignored
+ }
- public void setInputStream(InputStream in) {}
+ @Override
+ public void setInputStream(InputStream in) {
+ // ignored
+ }
- public void setOutputStream(OutputStream out) {}
+ @Override
+ public void setOutputStream(OutputStream out) {
+ // ignored
+ }
- public void setErrorStream(OutputStream err) {}
+ @Override
+ public void setErrorStream(OutputStream err) {
+ // ignored
+ }
- public void setExitCallback(ExitCallback callback) {}
+ @Override
+ public void setExitCallback(ExitCallback callback) {
+ // ignored
+ }
- public void start(Environment env) throws IOException {}
+ @Override
+ public void start(Environment env) throws IOException {
+ // ignored
+ }
- public void destroy() {}
+ @Override
+ public void destroy() {
+ // ignored
+ }
}
/**
@@ -172,6 +200,9 @@ public class WindowAdjustTest {
// Order has to be preserved for queued writes
private final Deque<Buffer> pending = new LinkedList<Buffer>() {
+ // we don't expect to serialize it
+ private static final long serialVersionUID = 1L;
+
@Override
public boolean add(Buffer o) {
return super.add(o);
@@ -198,6 +229,8 @@ public class WindowAdjustTest {
private void writeWithPendingDetection(final Buffer msg, final boolean wasPending) {
try {
asyncIn.write(msg).addListener(new SshFutureListener<IoWriteFuture>() {
+ @SuppressWarnings("synthetic-access")
+ @Override
public void operationComplete(final IoWriteFuture future) {
if(wasPending) {
pending.remove();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
index 762caa0..f964208 100644
--- a/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/WindowTest.java
@@ -18,9 +18,6 @@
*/
package org.apache.sshd;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
@@ -51,7 +48,7 @@ import org.apache.sshd.server.command.UnknownCommand;
import org.apache.sshd.server.session.ServerConnectionService;
import org.apache.sshd.server.session.ServerUserAuthService;
import org.apache.sshd.util.AsyncEchoShellFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.BogusPublickeyAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
@@ -65,7 +62,7 @@ import org.junit.Test;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class WindowTest extends BaseTest {
+public class WindowTest extends BaseTestSupport {
private SshServer sshd;
private SshClient client;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
index e9ab522..51d6371 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
@@ -18,9 +18,6 @@
*/
package org.apache.sshd.client.kex;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertTrue;
-
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PipedInputStream;
@@ -36,7 +33,7 @@ import org.apache.sshd.common.KeyExchange;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.kex.BuiltinDHFactories;
import org.apache.sshd.common.kex.DHFactory;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusPasswordAuthenticator;
import org.apache.sshd.util.EchoShellFactory;
import org.apache.sshd.util.TeeOutputStream;
@@ -49,7 +46,7 @@ import org.junit.Test;
* Test client key exchange algorithms.
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class KexTest extends BaseTest {
+public class KexTest extends BaseTestSupport {
private SshServer sshd;
private int port;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
index d1138a9..a91bcb0 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java
@@ -20,32 +20,28 @@ package org.apache.sshd.common.channel;
import java.util.Arrays;
-import org.apache.sshd.util.BaseTest;
+import org.apache.sshd.util.BaseTestSupport;
import org.apache.sshd.util.BogusChannel;
import org.junit.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-public class ChannelPipedInputStreamTest extends BaseTest {
+public class ChannelPipedInputStreamTest extends BaseTestSupport {
@Test
public void testAvailable() throws Exception {
Window window = new Window(new BogusChannel(), null, true, true);
- ChannelPipedInputStream stream = new ChannelPipedInputStream(window);
-
- byte[] b = "test".getBytes();
- stream.receive(b, 0, b.length);
- assertEquals(b.length, stream.available());
-
- stream.eof();
- assertEquals(b.length, stream.available());
-
- final byte[] readBytes = new byte[50];
- assertEquals(b.length, stream.read(readBytes));
- assertStreamEquals(b, readBytes);
- assertEquals(-1, stream.available());
+ try(ChannelPipedInputStream stream = new ChannelPipedInputStream(window)) {
+ byte[] b = "test".getBytes();
+ stream.receive(b, 0, b.length);
+ assertEquals(b.length, stream.available());
+
+ stream.eof();
+ assertEquals(b.length, stream.available());
+
+ final byte[] readBytes = new byte[50];
+ assertEquals(b.length, stream.read(readBytes));
+ assertStreamEquals(b, readBytes);
+ assertEquals(-1, stream.available());
+ }
}
private void assertStreamEquals(byte[] expected, byte[] read) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/bd1d975a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
index b0814fb..5ca20dd 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
@@ -29,15 +29,14 @@ import org.apache.sshd.common.Cipher;
import org.apache.sshd.common.Cipher.Mode;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.util.SecurityUtils;
-import org.apache.sshd.util.BaseTest;
-import org.junit.Assert;
+import org.apache.sshd.util.BaseTestSupport;
import org.junit.Assume;
import org.junit.internal.AssumptionViolatedException;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public abstract class BaseCipherTest extends BaseTest {
+public abstract class BaseCipherTest extends BaseTestSupport {
protected BaseCipherTest() {
super();
}
@@ -88,6 +87,6 @@ public abstract class BaseCipherTest extends BaseTest {
byte[] actual=workBuf.clone();
dec.update(actual, 0, actual.length);
- Assert.assertArrayEquals(facName, expected, actual);
+ assertArrayEquals(facName, expected, actual);
}
}