我需要测试 Apache camel SFTP 消费者。有没有办法运行嵌入式 SFTP 服务器来在开发环境中测试我的代码?感谢对此的任何帮助。
最佳答案
有一次我遇到了类似的问题,因此编写了一个在测试期间运行 SFTP 服务器的 JUnit 4 规则。它叫做Fake SFTP Server Rule并在内部使用 Apache Mina SSHD。以下是使用该规则的测试示例:
public class SomeTest {
@Rule
public final FakeSftpServerRule sftpServer = new FakeSftpServerRule();
@Test
public void testTextFile() {
//code that uploads the file
String fileContent = sftpServer.getFileContent("/directory/file.txt", UTF_8);
//verify content
}
}
关于java - java代码中的嵌入式SFTP服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40695899/