Home >Java >How to create functional tests for IntegrationFlows

How to create functional tests for IntegrationFlows

WBOY
WBOYforward
2024-02-08 21:11:03922browse

php editor Xinyi will introduce you how to create functional tests for IntegrationFlows. IntegrationFlows is an important component in the Spring Integration framework, used to define and manage the logic of message flow. Functional testing is one of the key links to ensure the correct operation of IntegrationFlows. In this article, we will introduce the steps and considerations for creating functional tests for IntegrationFlows to help developers better perform integration testing work.

Question content

I have a standardintegrationflow that runs every day and deletes files 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've tested the code manually, setting the cron expression to run every 2 minutes and delete files older than 5 minutes, but of course I need some automated testing.

I thought about creating 2 files, one older than 10 days and the other not. Get both files and verify they exist. Then use the object of sourcepollingchanneladapter to manually trigger the standardintegrationflow and call the .start() function, then try to get it again and verify that it has been deleted.

The first question is whether this is the correct way to test integrationflow. Also, I can't find an easy way to create a file and change its modification time in a test.

I am using spring-integration 5.5.15 and spock framework for testing. Also use minio container to store files on server for functional testing

Workaround

You can use PollerSpec as bean and stream definition from oldReceiptsCleaner cite it in. You then override the bean in the test configuration. Then you have LastModifiedFileListFilter which can be based on some properties of age and specify the desired value in the test.

I'm not familiar with Minio, but there may be an API how to create a file with the required lastModified.

Then yes. You can use @SpringIntegrationTest with noAutoStartup as the bean name for Sftp.inboundStreamingAdapter. After creating the file, you can manually start the SourcePollingChannelAdapter in the test method.

The above is the detailed content of How to create functional tests for IntegrationFlows. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete