【问题标题】:Sprint Integration flow testing with mocked SFTP server?使用模拟 SFTP 服务器进行 Sprint 集成流测试?
【发布时间】: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


【解决方案1】:

【讨论】:

  • 是的,我们使用 Apache Mina 项目将假 (s)ftp 服务器添加到我们的测试中。在大多数情况下,它实际上是关于测试类级别的规则,并使用 Spring 配置中的这些静态属性作为来自会话工厂的假主机/端口的引用。
  • 谢谢!我是否必须复制那些 TestSupport 类,或者它们是我可以通过 maven 依赖项加载到我的项目中的任何包 org.springframework.integration 的一部分?
  • 对于 apache-sshd 和 apache-ftp-server,我需要哪些 maven 依赖版本?
猜你喜欢
  • 2021-03-15
  • 1970-01-01
  • 2015-06-15
  • 2018-06-11
  • 1970-01-01
  • 2013-04-01
  • 2023-03-09
  • 2011-03-12
  • 2017-01-23
相关资源
最近更新 更多