I have a StandardIntegrationFlow which runs each day and deletes files that are older than 10 days.
@Bean
public StandardIntegrationFlow oldReceiptsCleaner(
@Qualifier("receiptSftpRemoteFileTemplate")
RecursiveSftpRemoteFileTemplate receiptSftpRemoteFileTemplate,
RemoteSftpFileRemover remoteSftpFileRemover) {
return IntegrationFlows.from(
Sftp.inboundStreamingAdapter(receiptSftpRemoteFileTemplate)
.remoteDirectory(properties.getSftpPath()),
e ->
e.poller(
Pollers.cron(properties.getCronExpression())
.maxMessagesPerPoll(-1)).id("oldReceiptsCleanerPoller"))
.handle(remoteSftpFileRemover::removeFile)
.get();
}
I want to create a functional test to verify that it works. I have tested the code manually, by setting the cron expression to run each 2 minutes and remove files that are older than 5 mins and but of course I need some automated tests.
I have thought to create 2 files, one which is older than 10 days and one that is not. Fetch those 2 files and verify that they exist. Then manually trigger the StandardIntegrationFlow using an object of SourcePollingChannelAdapter and calling the .start() function, and then try to fetch them again and verify that the one is deleted.
The first question will be if that is a proper way to test an IntegrationFlow. Also, I can't find a simple way to create the files inside the test, and change their modifiedTime.
I am using spring-integration 5.5.15 and Spock framework for testing. Also using Minio Containers to store files on server for the functional tests
You can have a
PollerSpecas a bean and reference it from youroldReceiptsCleanerflow definition. Then you override this bean in your test configuration. Then you have yourLastModifiedFileListFilterwhich can be based on some property forageand specify desired in the test.I'm not familiar with Minio, but probably there is API how to create files with required
lastModified.Then yes. You can use
@SpringIntegrationTestwithnoAutoStartupfor a bean name of yourSftp.inboundStreamingAdapter. After you have created files, you can start thatSourcePollingChannelAdaptermanually in the test method.