Reputation: 261
I have found a mock SFTP server implementation to be used as @Rule injection within JUnit tests. This lets you install a mock SFTP server. For that simply a dependency has to be added to the projects pom.xml with test scope:
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>fake-sftp-server-rule</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
My integration flow so far is (all the parameters are injected with the @ConfigurationProperties annotation):
@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();
}
Is it possible to combine my integration flow in a test case with this mocked SFTP server? How would I do this?
Upvotes: 1
Views: 4897
Reputation: 2133
Checkout the spring integration unit tests. The ftp unit tests are at...
FtpTestSupport shows how they setup an embedded FTP server used by the tests...
Upvotes: 1