diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/AbstractFileListFilter.java b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/AbstractFileListFilter.java index 132bc38204..351fe20227 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/AbstractFileListFilter.java +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/AbstractFileListFilter.java @@ -23,23 +23,25 @@ import java.util.List; import org.springframework.util.Assert; /** - * A convenience base class for any {@link FileListFilter} whose criteria can - * be evaluated against each File in isolation. If the entire List of files is + * A convenience base class for any {@link FileListFilter} whose criteria can be + * evaluated against each File in isolation. If the entire List of files is * required for evaluation, implement the FileListFilter interface directly. * * @author Mark Fisher + * @author Iwein Fuld */ public abstract class AbstractFileListFilter implements FileListFilter { /** - * Returns the list of files that are accepted by this filter. + * {@inheritDoc} */ public final List filterFiles(File[] files) { - Assert.notNull(files,"'files' should not be null."); List accepted = new ArrayList(); - for (File file : files) { - if (this.accept(file)) { - accepted.add(file); + if (files != null) { + for (File file : files) { + if (this.accept(file)) { + accepted.add(file); + } } } return accepted; diff --git a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileListFilter.java b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileListFilter.java index 8f2dfc1e22..615f57b129 100644 --- a/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileListFilter.java +++ b/org.springframework.integration.file/src/main/java/org/springframework/integration/file/FileListFilter.java @@ -27,7 +27,8 @@ import java.util.List; public interface FileListFilter { /** - * Filters out files and returns the files that are left in a list. + * Filters out files and returns the files that are left in a list, or an + * empty list when a null is passed in. */ List filterFiles(File[] files); diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java index fc69d276c2..d0e8fbc8fe 100644 --- a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileReadingMessageSourceIntegrationTests.java @@ -110,6 +110,14 @@ public class FileReadingMessageSourceIntegrationTests { assertNotSame(received1 + " == " + received3, received1, received3); assertNotSame(received2 + " == " + received3, received2, received3); } + + @Test + public void inputDirExhausted() throws Exception { + assertNotNull(pollableFileSource.receive()); + assertNotNull(pollableFileSource.receive()); + assertNotNull(pollableFileSource.receive()); + assertNull(pollableFileSource.receive()); + } @Test(timeout = 6000) @Repeat(10) diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml new file mode 100644 index 0000000000..7d8deff850 --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests-context.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java new file mode 100644 index 0000000000..14d1543a48 --- /dev/null +++ b/org.springframework.integration.file/src/test/java/org/springframework/integration/file/FileToChannelIntegrationTests.java @@ -0,0 +1,75 @@ +package org.springframework.integration.file; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.File; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.integration.channel.PollableChannel; +import org.springframework.integration.core.Message; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@ContextConfiguration +@RunWith(SpringJUnit4ClassRunner.class) +public class FileToChannelIntegrationTests { + private static File inputDir; + + @Autowired + PollableChannel fileMessages; + + @BeforeClass + public static void setupInputDir() { + inputDir = new File(System.getProperty("java.io.tmpdir") + "/" + + FileToChannelIntegrationTests.class.getSimpleName()); + inputDir.mkdir(); + } + + @After + public void cleanoutInputDir() throws Exception { + File[] listFiles = inputDir.listFiles(); + for (int i = 0; i < listFiles.length; i++) { + listFiles[i].delete(); + } + } + + @AfterClass + public static void removeInputDir() throws Exception { + inputDir.delete(); + } + + @Test(timeout = 2000) + public void fileMessageToChannel() throws Exception { + File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); + Message received = receiveFileMessage(); + while (received == null) { + Thread.sleep(50); + received = receiveFileMessage(); + } + assertNotNull(received.getPayload()); + } + + @SuppressWarnings("unchecked") + private Message receiveFileMessage() { + return (Message) fileMessages.receive(); + } + + @Test(timeout = 2000) + public void directoryExhaustion() throws Exception { + File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000); + Message received = receiveFileMessage(); + while (received == null) { + Thread.sleep(5); + received = receiveFileMessage(); + } + assertNotNull(received.getPayload()); + assertNull(fileMessages.receive(200)); + } +}