【发布时间】:2021-08-15 16:42:38
【问题描述】:
我发现了一个模拟 SFTP 服务器实现,可用作 @Rule 注入 JUnit 测试。这使您可以安装模拟 SFTP 服务器。为此,只需将依赖项添加到项目 pom.xml 中并具有测试范围:
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>fake-sftp-server-rule</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
到目前为止,我的集成流程是(所有参数都使用@ConfigurationProperties 注解注入):
@Bean
public SessionFactory<LsEntry> sftpTest1SessionFactory() {
DefaultSftpSessionFactory sf = new DefaultSftpSessionFactory();
sf.setHost(hostname);
sf.setPort(port);
sf.setUser(username);
sf.setPassword(password);
return new CachingSessionFactory<LsEntry>(sf);
}
@Bean
public FireOnceTrigger fireOnceTrigger() {
return new FireOnceTrigger();
}
@Bean
public IntegrationFlow test1SftpInboundFlow() {
return IntegrationFlows
.from(Sftp.inboundAdapter(sftpTest1SessionFactory)
.preserveTimestamp(true)
.remoteDirectory(remoteDir)
.regexFilter(remoteFilePattern)
.localFilenameExpression(localFile)
.localDirectory(new File(localDir)),
e -> e.id("sftpTest1InboundAdapter")
.autoStartup(true)
.poller(Pollers.trigger(fireOnceTrigger()))
)
.transform(e -> e)
.handle(m -> System.out.println(m.getPayload()))
.get();
}
是否可以将我在测试用例中的集成流程与这个模拟的 SFTP 服务器结合起来?我该怎么做?
【问题讨论】:
-
如果你能展示你如何使用那个假的 sftp 规则会很棒。然后我们可以考虑将其混入 Spring 配置中
标签: java unit-testing spring-integration sftp spring-integration-dsl