From 1ff69d4d2424879ff40be6284686897bcc579a0f Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 11 Feb 2020 12:57:26 -0500 Subject: [PATCH] GH-3175: Add .scanner() to inbound file sync spec Resolves https://github.com/spring-projects/spring-integration/issues/3175 * Fix `@since` for backport **Cherry-pick to `5.2.x`** --- .../dsl/RemoteFileInboundChannelAdapterSpec.java | 14 +++++++++++++- .../integration/ftp/dsl/FtpTests.java | 13 ++++++++++++- 2 files changed, 25 insertions(+), 2 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 9c7e4d3701..fcc5d910c3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.expression.Expression; import org.springframework.integration.dsl.ComponentsRegistration; import org.springframework.integration.dsl.MessageSourceSpec; import org.springframework.integration.expression.FunctionExpression; +import org.springframework.integration.file.DirectoryScanner; import org.springframework.integration.file.filters.ExpressionFileListFilter; import org.springframework.integration.file.filters.FileListFilter; import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer; @@ -270,6 +271,17 @@ public abstract class RemoteFileInboundChannelAdapterSpec getComponentsToRegister() { Map componentsToRegister = new LinkedHashMap<>(); diff --git a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java index 860d61b078..3fbfc067a7 100644 --- a/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java +++ b/spring-integration-ftp/src/test/java/org/springframework/integration/ftp/dsl/FtpTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,9 @@ import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.regex.Matcher; import org.apache.commons.net.ftp.FTPFile; @@ -47,6 +49,8 @@ import org.springframework.integration.dsl.Pollers; import org.springframework.integration.dsl.StandardIntegrationFlow; import org.springframework.integration.dsl.context.IntegrationFlowContext; import org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration; +import org.springframework.integration.file.DefaultDirectoryScanner; +import org.springframework.integration.file.DirectoryScanner; import org.springframework.integration.file.FileHeaders; import org.springframework.integration.file.remote.RemoteFileTemplate; import org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway; @@ -86,10 +90,12 @@ public class FtpTests extends FtpTestSupport { @Test public void testFtpInboundFlow() throws IOException { QueueChannel out = new QueueChannel(); + DirectoryScanner scanner = new DefaultDirectoryScanner(); IntegrationFlow flow = IntegrationFlows.from(Ftp.inboundAdapter(sessionFactory()) .preserveTimestamp(true) .remoteDirectory("ftpSource") .maxFetchSize(10) + .scanner(scanner) .regexFilter(".*\\.txt$") .localFilename(f -> f.toUpperCase() + ".a") .localDirectory(getTargetLocalDirectory()), @@ -97,6 +103,11 @@ public class FtpTests extends FtpTestSupport { .channel(out) .get(); IntegrationFlowRegistration registration = this.flowContext.registration(flow).register(); + Map components = TestUtils.getPropertyValue(registration, "integrationFlow.integrationComponents", Map.class); + Iterator iterator = components.keySet().iterator(); + iterator.next(); + Object spcafb = iterator.next(); + assertThat(TestUtils.getPropertyValue(spcafb, "source.fileSource.scanner")).isSameAs(scanner); Message message = out.receive(10_000); assertThat(message).isNotNull(); assertThat(message.getHeaders())