diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java index 913cf8b194..7782c969a8 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/FileInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2009 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. @@ -43,6 +43,10 @@ public class FileInboundChannelAdapterParser extends AbstractPollingInboundChann protected String parseSource(Element element, ParserContext parserContext) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition( PACKAGE_NAME + ".FileReadingMessageSource"); + String comparator = element.getAttribute("comparator"); + if (StringUtils.hasText(comparator)) { + builder.addConstructorArgReference(comparator); + } String directory = element.getAttribute("directory"); if (StringUtils.hasText(directory)) { if (directory.indexOf(':') == -1) { diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd index 074d38b10b..0df1483d47 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/config/spring-integration-file-1.0.xsd @@ -21,7 +21,8 @@ - Configures an inbound Channel Adapter that polls a directory. + Configures an inbound Channel Adapter that polls a directory and sends + Messages whose payloads are instances of java.io.File. @@ -39,6 +40,14 @@ + + + + + diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml index fbb64ade63..58af32caec 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests-context.xml @@ -13,6 +13,7 @@ @@ -27,4 +28,7 @@ + + \ No newline at end of file diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java index eabbfa0827..5dd72c685f 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/config/FileInboundChannelAdapterParserTests.java @@ -17,13 +17,17 @@ package org.springframework.integration.file.config; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.Comparator; +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.context.ApplicationContext; @@ -42,15 +46,16 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; public class FileInboundChannelAdapterParserTests { @Autowired(required=true) - ApplicationContext context; + private ApplicationContext context; @Autowired(required=true) - FileReadingMessageSource source; + private FileReadingMessageSource source; - DirectFieldAccessor accessor; + private DirectFieldAccessor accessor; - @Before public void init() { + @Before + public void init() { accessor = new DirectFieldAccessor(source); } @@ -67,10 +72,28 @@ public class FileInboundChannelAdapterParserTests { File actual = (File) accessor.getPropertyValue("inputDirectory"); assertEquals("'inputDirectory' should be set", expected, actual); } - + @Test public void filter() throws Exception { assertTrue("'filter' should be set", accessor.getPropertyValue("filter") instanceof CompositeFileListFilter); } + @Test + public void comparator() throws Exception { + Object priorityQueue = accessor.getPropertyValue("toBeReceived"); + assertEquals(PriorityBlockingQueue.class, priorityQueue.getClass()); + Object expected = context.getBean("testComparator"); + Object innerQueue = new DirectFieldAccessor(priorityQueue).getPropertyValue("q"); + Object actual = new DirectFieldAccessor(innerQueue).getPropertyValue("comparator"); + assertSame("comparator reference not set, ", expected, actual); + } + + + static class TestComparator implements Comparator { + + public int compare(File f1, File f2) { + return 0; + } + } + }