From 411e9945c34fbbd202426b71d480df2549166ada Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Mon, 14 Sep 2020 16:15:23 -0400 Subject: [PATCH] GH-3372: Expose (S)FTP remoteComparator for DSL Fixes https://github.com/spring-projects/spring-integration/issues/3372 **Cherry-pick to 5.3.x & 5.2.x** --- .../dsl/RemoteFileInboundChannelAdapterSpec.java | 13 +++++++++++++ .../integration/sftp/dsl/SftpTests.java | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/RemoteFileInboundChannelAdapterSpec.java b/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/RemoteFileInboundChannelAdapterSpec.java index fcc5d910c3..a5e315ff4e 100644 --- a/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/RemoteFileInboundChannelAdapterSpec.java +++ b/spring-integration-file/src/main/java/org/springframework/integration/file/dsl/RemoteFileInboundChannelAdapterSpec.java @@ -17,6 +17,7 @@ package org.springframework.integration.file.dsl; import java.io.File; +import java.util.Comparator; import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Function; @@ -282,6 +283,18 @@ public abstract class RemoteFileInboundChannelAdapterSpec remoteComparator) { + this.synchronizer.setComparator(remoteComparator); + return _this(); + } + @Override public Map getComponentsToRegister() { Map componentsToRegister = new LinkedHashMap<>(); diff --git a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java index ba26e4034b..c9fede24c1 100644 --- a/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java +++ b/spring-integration-sftp/src/test/java/org/springframework/integration/sftp/dsl/SftpTests.java @@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.InputStream; +import java.util.Comparator; import java.util.List; import java.util.regex.Matcher; @@ -76,7 +77,8 @@ public class SftpTests extends SftpTestSupport { .remoteDirectory("sftpSource") .regexFilter(".*\\.txt$") .localFilenameExpression("#this.toUpperCase() + '.a'") - .localDirectory(getTargetLocalDirectory()), + .localDirectory(getTargetLocalDirectory()) + .remoteComparator(Comparator.naturalOrder()), e -> e.id("sftpInboundAdapter").poller(Pollers.fixedDelay(100))) .channel(out) .get(); @@ -86,13 +88,13 @@ public class SftpTests extends SftpTestSupport { Object payload = message.getPayload(); assertThat(payload).isInstanceOf(File.class); File file = (File) payload; - assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"); + assertThat(file.getName()).isEqualTo(" SFTPSOURCE1.TXT.a"); assertThat(file.getAbsolutePath()).contains("localTarget"); message = out.receive(10_000); assertThat(message).isNotNull(); file = (File) message.getPayload(); - assertThat(file.getName()).isIn(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"); + assertThat(file.getName()).isIn("SFTPSOURCE2.TXT.a"); assertThat(file.getAbsolutePath()).contains("localTarget"); registration.destroy();