diff --git a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java
index 0a6383ae3b..f4965cb4b4 100644
--- a/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java
+++ b/spring-integration-file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java
@@ -84,23 +84,26 @@ public class FileInboundChannelAdapterParser extends AbstractPollingInboundChann
String filenameRegex = element.getAttribute("filename-regex");
String preventDuplicates = element.getAttribute("prevent-duplicates");
String ignoreHidden = element.getAttribute("ignore-hidden");
- if (!StringUtils.hasText(filenamePattern) && !StringUtils.hasText(filenameRegex)
+ String filter = element.getAttribute("filter");
+ if (!StringUtils.hasText(filter) && !StringUtils.hasText(filenamePattern) && !StringUtils.hasText(filenameRegex)
&& !StringUtils.hasText(preventDuplicates) && !StringUtils.hasText(ignoreHidden)) {
return null;
}
BeanDefinitionBuilder factoryBeanBuilder =
BeanDefinitionBuilder.genericBeanDefinition(FileListFilterFactoryBean.class);
factoryBeanBuilder.setRole(BeanDefinition.ROLE_SUPPORT);
- IntegrationNamespaceUtils.setReferenceIfAttributeDefined(factoryBeanBuilder, element, "filter");
+ if (StringUtils.hasText(filter)) {
+ factoryBeanBuilder.addPropertyReference("filter", filter);
+ }
if (StringUtils.hasText(filenamePattern)) {
- if (element.hasAttribute("filter")) {
+ if (StringUtils.hasText(filter)) {
parserContext.getReaderContext().error(
"At most one of 'filter' and 'filename-pattern' may be provided.", element);
}
factoryBeanBuilder.addPropertyValue("filenamePattern", filenamePattern);
}
if (StringUtils.hasText(filenameRegex)) {
- if (element.hasAttribute("filter")) {
+ if (StringUtils.hasText(filter)) {
parserContext.getReaderContext().error(
"At most one of 'filter' and 'filename-regex' may be provided.", element);
}
diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml
index 6e6342374d..625c973903 100644
--- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml
+++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml
@@ -21,6 +21,13 @@
+
+
+
+
diff --git a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java
index 5218b7a682..7d5547dd3c 100644
--- a/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java
+++ b/spring-integration-file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java
@@ -16,24 +16,34 @@
package org.springframework.integration.file.config;
+import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.Comparator;
+import java.util.Iterator;
+import java.util.Set;
import java.util.concurrent.PriorityBlockingQueue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.file.DefaultDirectoryScanner;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
+import org.springframework.integration.file.filters.FileListFilter;
+import org.springframework.integration.file.filters.IgnoreHiddenFileListFilter;
+import org.springframework.integration.test.util.TestUtils;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -45,28 +55,44 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
+@DirtiesContext
public class FileInboundChannelAdapterParserTests {
@Autowired(required = true)
private ApplicationContext context;
@Autowired
- private FileReadingMessageSource source;
+ @Qualifier("inputDirPoller.adapter.source")
+ private FileReadingMessageSource inputDirPollerSource;
+
+ @Autowired
+ @Qualifier("inboundWithJustFilter.adapter.source")
+ private FileReadingMessageSource inboundWithJustFilterSource;
+
+ @Autowired
+ private FileListFilter filter;
private DirectFieldAccessor accessor;
@Before
public void init() {
- accessor = new DirectFieldAccessor(source);
+ accessor = new DirectFieldAccessor(inputDirPollerSource);
}
@Test
public void channelName() throws Exception {
- context.getBean("inputDirPoller");
AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class);
assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getComponentName());
}
+ @Test
+ public void justFilter() throws Exception {
+ Iterator> filterIterator = TestUtils
+ .getPropertyValue(this.inboundWithJustFilterSource, "scanner.filter.fileFilters", Set.class).iterator();
+ assertThat(filterIterator.next(), instanceOf(IgnoreHiddenFileListFilter.class));
+ assertSame(this.filter, filterIterator.next());
+ }
+
@Test
public void inputDirectory() {
File expected = new File(System.getProperty("java.io.tmpdir"));
@@ -103,6 +129,7 @@ public class FileInboundChannelAdapterParserTests {
static class TestComparator implements Comparator {
+ @Override
public int compare(File f1, File f2) {
return 0;
}