(S)FTP Lambdas

AMQP Lambdas

Event Lambdas

Feed/File Lambdas

Gemfile/Groovy Lambdas

* Ensure that JavaDocs are checked via `	check.dependsOn javadoc`
* Add `@return` tag to the `MessageBuilder.readOnlyHeaders()`
This commit is contained in:
Gary Russell
2016-09-22 12:32:47 -04:00
committed by Artem Bilan
parent 3402a86fb5
commit e5ae7d886d
48 changed files with 569 additions and 1148 deletions

View File

@@ -23,7 +23,6 @@ import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.sftp.SftpSubsystem;
import org.junit.AfterClass;
@@ -59,14 +58,7 @@ public class SftpTestSupport extends RemoteFileTestSupport {
@BeforeClass
public static void createServer() throws Exception {
server = SshServer.setUpDefaultServer();
server.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password,
org.apache.sshd.server.session.ServerSession session) {
return true;
}
});
server.setPasswordAuthenticator((username, password, session) -> true);
server.setPort(0);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory()));

View File

@@ -122,16 +122,10 @@ public class SftpOutboundGatewayParserTests {
//INT-3129
assertNotNull(TestUtils.getPropertyValue(gateway, "localFilenameGeneratorExpression"));
final AtomicReference<Method> genMethod = new AtomicReference<Method>();
ReflectionUtils.doWithMethods(SftpOutboundGateway.class, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
if ("generateLocalFileName".equals(method.getName())) {
method.setAccessible(true);
genMethod.set(method);
}
}
});
ReflectionUtils.doWithMethods(SftpOutboundGateway.class, method -> {
method.setAccessible(true);
genMethod.set(method);
}, method -> "generateLocalFileName".equals(method.getName()));
assertEquals("FOO.afoo", genMethod.get().invoke(gateway, new GenericMessage<String>(""), "foo"));
assertThat(TestUtils.getPropertyValue(gateway, "mputFilter"), Matchers.instanceOf(SimplePatternFileListFilter.class));
}

View File

@@ -41,8 +41,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;
@@ -210,12 +208,9 @@ public class SftpOutboundTests {
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
final List<String> madeDirs = new ArrayList<String>();
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
madeDirs.add((String) invocation.getArguments()[0]);
return null;
}
doAnswer(invocation -> {
madeDirs.add((String) invocation.getArguments()[0]);
return null;
}).when(session).mkdir(anyString());
handler.handleMessage(new GenericMessage<String>("qux"));
assertEquals(3, madeDirs.size());
@@ -227,7 +222,8 @@ public class SftpOutboundTests {
@Test
public void testSharedSession() throws Exception {
JSch jsch = spy(new JSch());
Constructor<com.jcraft.jsch.Session> ctor = com.jcraft.jsch.Session.class.getDeclaredConstructor(JSch.class, String.class, String.class, int.class);
Constructor<com.jcraft.jsch.Session> ctor = com.jcraft.jsch.Session.class.getDeclaredConstructor(JSch.class,
String.class, String.class, int.class);
ctor.setAccessible(true);
com.jcraft.jsch.Session jschSession1 = spy(ctor.newInstance(jsch, "foo", "host", 22));
com.jcraft.jsch.Session jschSession2 = spy(ctor.newInstance(jsch, "foo", "host", 22));
@@ -242,13 +238,7 @@ public class SftpOutboundTests {
new DirectFieldAccessor(channel2).setPropertyValue("session", jschSession1);
// Can't use when(session.open()) with a spy
final AtomicInteger n = new AtomicInteger();
doAnswer(new Answer<ChannelSftp>() {
@Override
public ChannelSftp answer(InvocationOnMock invocation) throws Throwable {
return n.getAndIncrement() == 0 ? channel1 : channel2;
}
}).when(jschSession1).openChannel("sftp");
doAnswer(invocation -> n.getAndIncrement() == 0 ? channel1 : channel2).when(jschSession1).openChannel("sftp");
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(jsch, true);
factory.setHost("host");
factory.setUser("foo");
@@ -313,20 +303,8 @@ public class SftpOutboundTests {
new DirectFieldAccessor(channel2).setPropertyValue("session", jschSession1);
// Can't use when(session.open()) with a spy
final AtomicInteger n = new AtomicInteger();
doAnswer(new Answer<ChannelSftp>() {
@Override
public ChannelSftp answer(InvocationOnMock invocation) throws Throwable {
return n.getAndIncrement() == 0 ? channel1 : channel2;
}
}).when(jschSession1).openChannel("sftp");
doAnswer(new Answer<ChannelSftp>() {
@Override
public ChannelSftp answer(InvocationOnMock invocation) throws Throwable {
return n.getAndIncrement() < 3 ? channel3 : channel4;
}
}).when(jschSession2).openChannel("sftp");
doAnswer(invocation -> n.getAndIncrement() == 0 ? channel1 : channel2).when(jschSession1).openChannel("sftp");
doAnswer(invocation -> n.getAndIncrement() < 3 ? channel3 : channel4).when(jschSession2).openChannel("sftp");
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(jsch, true);
factory.setHost("host");
factory.setUser("foo");
@@ -367,13 +345,7 @@ public class SftpOutboundTests {
}
private void noopConnect(ChannelSftp channel1) throws JSchException {
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).when(channel1).connect();
doAnswer(invocation -> null).when(channel1).connect();
}
public static class TestSftpSessionFactory extends DefaultSftpSessionFactory {
@@ -383,29 +355,19 @@ public class SftpOutboundTests {
try {
ChannelSftp channel = mock(ChannelSftp.class);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation)
throws Throwable {
File file = new File((String) invocation.getArguments()[1]);
assertTrue(file.getName().endsWith(".writing"));
FileCopyUtils.copy((InputStream) invocation.getArguments()[0], new FileOutputStream(file));
return null;
}
doAnswer(invocation -> {
File file = new File((String) invocation.getArguments()[1]);
assertTrue(file.getName().endsWith(".writing"));
FileCopyUtils.copy((InputStream) invocation.getArguments()[0], new FileOutputStream(file));
return null;
}).when(channel).put(Mockito.any(InputStream.class), Mockito.anyString());
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation)
throws Throwable {
File file = new File((String) invocation.getArguments()[0]);
assertTrue(file.getName().endsWith(".writing"));
File renameToFile = new File((String) invocation.getArguments()[1]);
file.renameTo(renameToFile);
return null;
}
doAnswer(invocation -> {
File file = new File((String) invocation.getArguments()[0]);
assertTrue(file.getName().endsWith(".writing"));
File renameToFile = new File((String) invocation.getArguments()[1]);
file.renameTo(renameToFile);
return null;
}).when(channel).rename(Mockito.anyString(), Mockito.anyString());
String[] files = new File("remote-test-dir").list();

View File

@@ -50,7 +50,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.file.FileHeaders;
import org.springframework.integration.file.remote.MessageSessionCallback;
import org.springframework.integration.file.remote.SessionCallback;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.sftp.SftpTestSupport;
@@ -266,31 +265,23 @@ public class SftpServerOutboundTests extends SftpTestSupport {
PipedOutputStream out2 = new PipedOutputStream(pipe2);
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
try {
session1.write(pipe1, "foo.txt");
}
catch (IOException e) {
e.printStackTrace();
}
latch1.countDown();
Executors.newSingleThreadExecutor().execute(() -> {
try {
session1.write(pipe1, "foo.txt");
}
catch (IOException e) {
e.printStackTrace();
}
latch1.countDown();
});
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
try {
session2.write(pipe2, "bar.txt");
}
catch (IOException e) {
e.printStackTrace();
}
latch2.countDown();
Executors.newSingleThreadExecutor().execute(() -> {
try {
session2.write(pipe2, "bar.txt");
}
catch (IOException e) {
e.printStackTrace();
}
latch2.countDown();
});
out1.write('a');
@@ -444,13 +435,7 @@ public class SftpServerOutboundTests extends SftpTestSupport {
}
private void assertLength6(SftpRemoteFileTemplate template) {
LsEntry[] files = template.execute(new SessionCallback<LsEntry, LsEntry[]>() {
@Override
public LsEntry[] doInSession(Session<LsEntry> session) throws IOException {
return session.list("sftpTarget/appending.txt");
}
});
LsEntry[] files = template.execute(session -> session.list("sftpTarget/appending.txt"));
assertEquals(1, files.length);
assertEquals(6, files[0].getAttrs().getSize());
}

View File

@@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -31,10 +29,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.file.DefaultFileNameGenerator;
import org.springframework.integration.file.remote.ClientCallbackWithoutResult;
import org.springframework.integration.file.remote.SessionCallback;
import org.springframework.integration.file.remote.SessionCallbackWithoutResult;
import org.springframework.integration.file.remote.session.CachingSessionFactory;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.sftp.SftpTestSupport;
import org.springframework.messaging.support.GenericMessage;
@@ -68,41 +64,28 @@ public class SftpRemoteFileTemplateTests extends SftpTestSupport {
template.setFileNameGenerator(fileNameGenerator);
template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
template.setUseTemporaryFileName(false);
template.execute(new SessionCallback<LsEntry, Boolean>() {
@Override
public Boolean doInSession(Session<LsEntry> session) throws IOException {
session.mkdir("foo/");
return session.mkdir("foo/bar/");
}
template.execute(session -> {
session.mkdir("foo/");
return session.mkdir("foo/bar/");
});
template.append(new GenericMessage<String>("foo"));
template.append(new GenericMessage<String>("bar"));
assertTrue(template.exists("foo/foobar.txt"));
template.executeWithClient(new ClientCallbackWithoutResult<ChannelSftp>() {
@Override
public void doWithClientWithoutResult(ChannelSftp client) {
try {
SftpATTRS file = client.lstat("foo/foobar.txt");
assertEquals(6, file.getSize());
}
catch (SftpException e) {
throw new RuntimeException(e);
}
template.executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> {
try {
SftpATTRS file = client.lstat("foo/foobar.txt");
assertEquals(6, file.getSize());
}
catch (SftpException e) {
throw new RuntimeException(e);
}
});
template.execute(new SessionCallbackWithoutResult<LsEntry>() {
@Override
public void doInSessionWithoutResult(Session<LsEntry> session) throws IOException {
assertTrue(session.remove("foo/foobar.txt"));
assertTrue(session.rmdir("foo/bar/"));
LsEntry[] files = session.list("foo/");
assertEquals(0, files.length);
assertTrue(session.rmdir("foo/"));
}
template.execute((SessionCallbackWithoutResult<LsEntry>) session -> {
assertTrue(session.remove("foo/foobar.txt"));
assertTrue(session.rmdir("foo/bar/"));
LsEntry[] files = session.list("foo/");
assertEquals(0, files.length);
assertTrue(session.rmdir("foo/"));
});
assertFalse(template.exists("foo"));
}

View File

@@ -35,10 +35,7 @@ import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory;
import org.apache.sshd.common.util.Base64;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.PublickeyAuthenticator;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.sftp.SftpSubsystem;
import org.junit.Test;
@@ -63,13 +60,7 @@ public class SftpServerTests {
public void testUcPw() throws Exception {
SshServer server = SshServer.setUpDefaultServer();
try {
server.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String arg0, String arg1, ServerSession arg2) {
return true;
}
});
server.setPasswordAuthenticator((arg0, arg1, arg2) -> true);
server.setPort(0);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory()));
@@ -107,14 +98,7 @@ public class SftpServerTests {
SshServer server = SshServer.setUpDefaultServer();
final PublicKey allowedKey = decodePublicKey(pubKey);
try {
server.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return key.equals(allowedKey);
}
});
server.setPublickeyAuthenticator((username, key, session) -> key.equals(allowedKey));
server.setPort(0);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory()));

View File

@@ -30,16 +30,12 @@ import static org.mockito.Mockito.when;
import java.io.IOException;
import java.net.ConnectException;
import java.security.PublicKey;
import java.util.Collections;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.PublickeyAuthenticator;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.sftp.SftpSubsystem;
import org.junit.Test;
@@ -65,13 +61,7 @@ public class SftpSessionFactoryTests {
public void testConnectFailSocketOpen() throws Exception {
SshServer server = SshServer.setUpDefaultServer();
try {
server.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String arg0, String arg1, ServerSession arg2) {
return true;
}
});
server.setPasswordAuthenticator((arg0, arg1, arg2) -> true);
server.setPort(0);
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));
server.start();
@@ -219,15 +209,8 @@ public class SftpSessionFactoryTests {
}
}
@SuppressWarnings("unchecked")
private DefaultSftpSessionFactory createServerAndClient(SshServer server) throws IOException {
server.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
return true;
}
});
server.setPublickeyAuthenticator((username, key, session) -> true);
server.setPort(0);
server.setSubsystemFactories(Collections.<NamedFactory<Command>>singletonList(new SftpSubsystem.Factory()));
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider("hostkey.ser"));