Cleaning up stray references, fixing tests

This commit is contained in:
Josh Long
2010-08-20 17:23:07 +00:00
parent 25b5afa528
commit 1562d53118
26 changed files with 739 additions and 739 deletions

View File

@@ -17,34 +17,31 @@ package org.springframework.integration.file;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.Message;
import org.springframework.integration.MessagingException;
import org.springframework.integration.aggregator.ResequencingMessageGroupProcessor;
import org.springframework.integration.core.MessageBuilder;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.util.Assert;
import java.io.File;
import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;
/**
* {@link MessageSource} that creates messages from a file system directory. To prevent messages for certain files, you
* may supply a {@link org.springframework.integration.file.filters.FileListFilter}. By default, an {@link org.springframework.integration.file.filters.AcceptOnceFileListFilter} is used. It ensures files are
* may supply a {@link org.springframework.integration.file.entries.EntryListFilter}. By default,
* an {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter} is used. It ensures files are
* picked up only once from the directory.
* <p/>
* A common problem with reading files is that a file may be detected before it is ready. The default {@link
* org.springframework.integration.file.filters.AcceptOnceFileListFilter} does not prevent this. In most cases, this can be prevented if the file-writing process
* org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter} does not prevent this. In most cases, this can be prevented if the file-writing process
* renames each file as soon as it is ready for reading. A pattern-matching filter that accepts only files that are
* ready (e.g. based on a known suffix), composed with the default {@link org.springframework.integration.file.filters.AcceptOnceFileListFilter} would allow for
* this. See {@link org.springframework.integration.file.filters.CompositeFileListFilter} for a way to do this.
* ready (e.g. based on a known suffix), composed with the default {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter} would allow for
* this. See {@link org.springframework.integration.file.entries.CompositeEntryListFilter} for a way to do this.
* <p/>
* A {@link Comparator} can be used to ensure internal ordering of the Files in a {@link PriorityBlockingQueue}. This
* does not provide the same guarantees as a {@link ResequencingMessageGroupProcessor}, but in cases where writing files and failure
@@ -110,6 +107,8 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
/**
* Specify the input directory.
*
* @param directory to monitor
*/
public void setDirectory(File directory) {
Assert.notNull(directory, "directory must not be null");
@@ -118,6 +117,8 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
/**
* Optionally specify a custom scanner, for example the {@link org.springframework.integration.file.RecursiveLeafOnlyDirectoryScanner}
*
* @param scanner scanner impl
*/
public void setScanner(DirectoryScanner scanner) {
this.scanner = scanner;
@@ -127,17 +128,21 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
* Specify whether to create the source directory automatically if it does not yet exist upon initialization. By
* default, this value is <emphasis>true</emphasis>. If set to <emphasis>false</emphasis> and the source directory
* does not exist, an Exception will be thrown upon initialization.
*
* @param autoCreateDirectory should the directory to be monitored be created when this component starts up?
*/
public void setAutoCreateDirectory(boolean autoCreateDirectory) {
this.autoCreateDirectory = autoCreateDirectory;
}
/**
* Sets a {@link org.springframework.integration.file.filters.FileListFilter}. By default a {@link org.springframework.integration.file.filters.AcceptOnceFileListFilter} with no bounds is used. In most
* cases a customized {@link org.springframework.integration.file.filters.FileListFilter} will be needed to deal with modification and duplication concerns. If
* multiple filters are required a {@link org.springframework.integration.file.filters.CompositeFileListFilter} can be used to group them together.
* Sets a {@link org.springframework.integration.file.entries.EntryListFilter}. By default a {@link org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter} with no bounds is used. In most
* cases a customized {@link org.springframework.integration.file.entries.EntryListFilter} will be needed to deal with modification and duplication concerns. If
* multiple filters are required a {@link org.springframework.integration.file.entries.CompositeEntryListFilter} can be used to group them together.
* <p/>
* <b>The supplied filter must be thread safe.</b>.
*
* @param filter a filter
*/
public void setFilter(EntryListFilter<File> filter) {
Assert.notNull(filter, "'filter' must not be null");
@@ -149,6 +154,8 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
* against duplicate processing.
* <p/>
* <b>The supplied FileLocker must be thread safe</b>
*
* @param locker a locker
*/
public void setLocker(FileLocker locker) {
Assert.notNull(locker, "'fileLocker' must not be null.");
@@ -164,11 +171,14 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
* java.util.concurrent.BlockingQueue} that this class is keeping will more likely be out of sync with the file
* system if this flag is set to <code>false</code>, but it will change more often (causing expensive reordering) if
* it is set to <code>true</code>.
*
* @param scanEachPoll whether or not the component should re-scan (as opposed to not rescanning until the entire backlog has been delivered)
*/
public void setScanEachPoll(boolean scanEachPoll) {
this.scanEachPoll = scanEachPoll;
}
@SuppressWarnings({"ResultOfMethodCallIgnored"})
public final void afterPropertiesSet() {
Assert.notNull(directory, "'directory' must not be set before initialization");
@@ -223,8 +233,10 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
/**
* Adds the failed message back to the 'toBeReceived' queue if there is room.
*
* @param failedMessage the {@link org.springframework.integration.Message} that blew up
*/
public void onFailure(Message<File> failedMessage, Throwable t) {
public void onFailure(Message<File> failedMessage) {
if (logger.isWarnEnabled()) {
logger.warn("Failed to send: " + failedMessage);
}
@@ -234,6 +246,8 @@ public class FileReadingMessageSource implements MessageSource<File>, Initializi
/**
* The message is just logged. It was already removed from the queue during the call to <code>receive()</code>
*
* @param sentMessage the message that was successfully delivered
*/
public void onSend(Message<File> sentMessage) {
if (logger.isDebugEnabled()) {

View File

@@ -24,30 +24,31 @@ import java.util.List;
* 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
*/
@Deprecated
public abstract class AbstractFileListFilter implements FileListFilter {
/**
* {@inheritDoc}
*/
public final List<File> filterFiles(File[] files) {
List<File> accepted = new ArrayList<File>();
if (files != null) {
for (File file : files) {
if (this.accept(file)) {
accepted.add(file);
}
}
}
return accepted;
}
/**
* {@inheritDoc}
*/
public final List<File> filterFiles(File[] files) {
List<File> accepted = new ArrayList<File>();
if (files != null) {
for (File file : files) {
if (this.accept(file)) {
accepted.add(file);
}
}
}
return accepted;
}
/**
* Subclasses must implement this method.
*/
protected abstract boolean accept(File file);
/**
* Subclasses must implement this method.
*/
protected abstract boolean accept(File file);
}

View File

@@ -13,61 +13,59 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.file.filters;
import java.io.File;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
/**
* {@link FileListFilter} that passes files only one time. This can
* conveniently be used to prevent duplication of files, as is done in
* {@link org.springframework.integration.file.FileReadingMessageSource}.
* <p/>
* This implementation is thread safe.
*
*
* @author Iwein Fuld
* @since 1.0.0
*/ @Deprecated
*/
@Deprecated
public class AcceptOnceFileListFilter extends AbstractFileListFilter {
private final Queue<File> seen;
private final Object monitor = new Object();
private final Queue<File> seen;
/**
* Creates an AcceptOnceFileFilter that is based on a bounded queue. If the
* queue overflows, files that fall out will be passed through this filter
* again if passed to the {@link #filterFiles(File[])} method.
*
* @param maxCapacity the maximum number of Files to maintain in the 'seen'
* queue.
*/
public AcceptOnceFileListFilter(int maxCapacity) {
this.seen = new LinkedBlockingQueue<File>(maxCapacity);
}
private final Object monitor = new Object();
/**
* Creates an AcceptOnceFileFilter based on an unbounded queue.
*/
public AcceptOnceFileListFilter() {
this.seen = new LinkedBlockingQueue<File>();
}
protected boolean accept(File pathname) {
synchronized (this.monitor) {
if (seen.contains(pathname)) {
return false;
}
/**
* Creates an AcceptOnceFileFilter that is based on a bounded queue. If the
* queue overflows, files that fall out will be passed through this filter
* again if passed to the {@link #filterFiles(File[])} method.
*
* @param maxCapacity the maximum number of Files to maintain in the 'seen'
* queue.
*/
public AcceptOnceFileListFilter(int maxCapacity) {
this.seen = new LinkedBlockingQueue<File>(maxCapacity);
}
/**
* Creates an AcceptOnceFileFilter based on an unbounded queue.
*/
public AcceptOnceFileListFilter() {
this.seen = new LinkedBlockingQueue<File>();
}
protected boolean accept(File pathname) {
synchronized (this.monitor) {
if (seen.contains(pathname)) {
return false;
}
if (!seen.offer(pathname)) {
seen.poll();
seen.add(pathname);
}
return true;
}
}
if (!seen.offer(pathname)) {
seen.poll();
seen.add(pathname);
}
return true;
}
}
}

View File

@@ -15,9 +15,6 @@
*/
package org.springframework.integration.file.filters;
import java.util.Set;
import org.springframework.util.Assert;
import java.io.File;
@@ -31,12 +28,11 @@ import java.util.*;
*
* @author Iwein Fuld
* @author Mark Fisher
*/ @Deprecated
*/
@Deprecated
public class CompositeFileListFilter implements FileListFilter {
private final Set<FileListFilter> fileFilters;
public CompositeFileListFilter(FileListFilter... fileFilters) {
this.fileFilters = new LinkedHashSet<FileListFilter>(Arrays.asList(fileFilters));
}
@@ -45,7 +41,6 @@ public class CompositeFileListFilter implements FileListFilter {
this.fileFilters = new LinkedHashSet<FileListFilter>(fileFilters);
}
/**
* {@inheritDoc}
* <p/>
@@ -53,33 +48,35 @@ public class CompositeFileListFilter implements FileListFilter {
*/
public List<File> filterFiles(File[] files) {
Assert.notNull(files, "'files' should not be null");
List<File> leftOver = Arrays.asList(files);
for (FileListFilter fileFilter : this.fileFilters) {
leftOver = fileFilter.filterFiles(leftOver.toArray(new File[]{}));
}
return leftOver;
}
/**
* @param filters one or more new filters to add
* @return this CompositeFileFilter instance with the added filters
* @see #addFilters(Collection)
*/
public CompositeFileListFilter addFilter(FileListFilter... filters) {
/* public CompositeFileListFilter addFilter(FileListFilter... filters) {
return addFilters(Arrays.asList(filters));
}
}*/
/**
* Not thread safe. Only a single thread may add filters at a time.
*
* <p/>
* Add the new filters to this CompositeFileFilter while maintaining the existing filters.
*
* @param filtersToAdd a list of filters to add
* @return this CompositeFileFilter instance with the added filters
*/
public CompositeFileListFilter addFilters(Collection<FileListFilter> filtersToAdd) {
/* public CompositeFileListFilter addFilters(Collection<FileListFilter> filtersToAdd) {
this.fileFilters.addAll(filtersToAdd);
return this;
}
return this;
}*/
}

View File

@@ -21,15 +21,16 @@ import java.util.List;
/**
* Strategy interface for filtering a group of files.
*
*
* @author Iwein Fuld
*/ @Deprecated
*/
@Deprecated
public interface FileListFilter {
/**
* Filters out files and returns the files that are left in a list, or an
* empty list when a null is passed in.
*/
List<File> filterFiles(File[] files);
/**
* Filters out files and returns the files that are left in a list, or an
* empty list when a null is passed in.
*/
List<File> filterFiles(File[] files);
}

View File

@@ -4,7 +4,10 @@ import java.io.File;
/**
* simply takes a hint and publishes an event as appropriate
* simply takes a cue / hint (something <emphasis>tells</emphasis> it outright that something has
* been added to a directory, and it and publishes an event as appropriate). This is useful for adapters
* that know when the file's been downloaded and want to deliver data as soon as its downloaded, but to poll the
* remote system only at a certain interval.
*
* @author Josh Long
*/

View File

@@ -16,60 +16,58 @@
package org.springframework.integration.file;
import static org.mockito.Mockito.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.entries.EntryListFilter;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.springframework.integration.file.filters.CompositeFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.*;
/**
* @author Iwein Fuld
*/
public class CompositeFileListFilterTests {
private FileListFilter fileFilterMock1 = mock( FileListFilter.class);
private EntryListFilter<File> fileFilterMock1 = mock(EntryListFilter.class);
private FileListFilter fileFilterMock2 = mock(FileListFilter.class);
private EntryListFilter<File> fileFilterMock2 = mock(EntryListFilter.class);
private File fileMock = mock(File.class);
private File fileMock = mock(File.class);
@Test
public void forwardedToFilters() throws Exception {
CompositeFileListFilter compositeFileFilter = new CompositeFileListFilter(fileFilterMock1, fileFilterMock2);
List<File> returnedFiles = Arrays.asList(new File[] { fileMock });
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[]{fileMock}));
verify(fileFilterMock1).filterFiles(isA(File[].class));
verify(fileFilterMock2).filterFiles(isA(File[].class));
}
@Test
public void forwardedToFilters() throws Exception {
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>(fileFilterMock1, fileFilterMock2);
List<File> returnedFiles = Arrays.asList(new File[]{fileMock});
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
assertEquals(returnedFiles, compositeFileFilter.filterEntries(new File[]{fileMock}));
verify(fileFilterMock1).filterEntries(isA(File[].class));
verify(fileFilterMock2).filterEntries(isA(File[].class));
}
@Test
public void forwardedToAddedFilters() throws Exception {
CompositeFileListFilter compositeFileFilter = new CompositeFileListFilter();
@Test
public void forwardedToAddedFilters() throws Exception {
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>();
compositeFileFilter.addFilter(fileFilterMock1, fileFilterMock2);
List<File> returnedFiles = Arrays.asList(new File[] { fileMock });
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(returnedFiles);
assertEquals(returnedFiles, compositeFileFilter.filterFiles(new File[]{fileMock}));
verify(fileFilterMock1).filterFiles(isA(File[].class));
verify(fileFilterMock2).filterFiles(isA(File[].class));
}
List<File> returnedFiles = Arrays.asList(fileMock);
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(returnedFiles);
assertEquals(returnedFiles, compositeFileFilter.filterEntries(new File[]{fileMock}));
verify(fileFilterMock1).filterEntries(isA(File[].class));
verify(fileFilterMock2).filterEntries(isA(File[].class));
}
@Test
public void negative() throws Exception {
CompositeFileListFilter compositeFileFilter = new CompositeFileListFilter(fileFilterMock1, fileFilterMock2);
when(fileFilterMock2.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
when(fileFilterMock1.filterFiles(isA(File[].class))).thenReturn(new ArrayList<File>());
assertTrue(compositeFileFilter.filterFiles(new File[]{fileMock}).isEmpty());
verify(fileFilterMock1).filterFiles(isA(File[].class));
verify(fileFilterMock2).filterFiles(isA(File[].class));
}
@Test
public void negative() throws Exception {
CompositeEntryListFilter<File> compositeFileFilter = new CompositeEntryListFilter<File>(fileFilterMock1, fileFilterMock2);
when(fileFilterMock2.filterEntries(isA(File[].class))).thenReturn(new ArrayList<File>());
when(fileFilterMock1.filterEntries(isA(File[].class))).thenReturn(new ArrayList<File>());
assertTrue(compositeFileFilter.filterEntries(new File[]{fileMock}).isEmpty());
}
}

View File

@@ -37,150 +37,150 @@ import static org.junit.Assert.*;
@ContextConfiguration
public class FileReadingMessageSourceIntegrationTests {
@Autowired
FileReadingMessageSource pollableFileSource;
@Autowired
FileReadingMessageSource pollableFileSource;
private static File inputDir;
private static File inputDir;
@BeforeClass
public static void setupInputDir() {
inputDir = new File(System.getProperty("java.io.tmpdir") + "/"
+ FileReadingMessageSourceIntegrationTests.class.getSimpleName());
inputDir.mkdir();
}
@BeforeClass
public static void setupInputDir() {
inputDir = new File(System.getProperty("java.io.tmpdir") + "/"
+ FileReadingMessageSourceIntegrationTests.class.getSimpleName());
inputDir.mkdir();
}
@Before
public void generateTestFiles() throws Exception {
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
}
@Before
public void generateTestFiles() throws Exception {
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
File.createTempFile("test", null, inputDir).setLastModified(System.currentTimeMillis() - 1000);
}
@After
public void cleanoutInputDir() throws Exception {
File[] listFiles = inputDir.listFiles();
for (int i = 0; i < listFiles.length; i++) {
listFiles[i].delete();
}
}
@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();
}
@AfterClass
public static void removeInputDir() throws Exception {
inputDir.delete();
}
@Test
public void configured() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(pollableFileSource);
assertEquals(inputDir, accessor.getPropertyValue("directory"));
}
@Test
public void configured() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(pollableFileSource);
assertEquals(inputDir, accessor.getPropertyValue("directory"));
}
@Test
public void getFiles() throws Exception {
Message<File> received1 = pollableFileSource.receive();
System.out.println( "getfiels() round 1");
@Test
public void getFiles() throws Exception {
Message<File> received1 = pollableFileSource.receive();
System.out.println("getfiels() round 1");
assertNotNull("This should return the first message", received1);
pollableFileSource.onSend(received1);
Message<File> received2 = pollableFileSource.receive();
assertNotNull(received2);
pollableFileSource.onSend(received2);
Message<File> received3 = pollableFileSource.receive();
assertNotNull(received3);
pollableFileSource.onSend(received3);
assertNotSame(received1 + " == " + received2, received1.getPayload(), received2.getPayload());
assertNotSame(received1 + " == " + received3, received1.getPayload(), received3.getPayload());
assertNotSame(received2 + " == " + received3, received2.getPayload(), received3.getPayload());
}
pollableFileSource.onSend(received1);
Message<File> received2 = pollableFileSource.receive();
assertNotNull(received2);
pollableFileSource.onSend(received2);
Message<File> received3 = pollableFileSource.receive();
assertNotNull(received3);
pollableFileSource.onSend(received3);
assertNotSame(received1 + " == " + received2, received1.getPayload(), received2.getPayload());
assertNotSame(received1 + " == " + received3, received1.getPayload(), received3.getPayload());
assertNotSame(received2 + " == " + received3, received2.getPayload(), received3.getPayload());
}
@Test
public void parallelRetrieval() throws Exception {
Message<File> received1 = pollableFileSource.receive();
Message<File> received2 = pollableFileSource.receive();
Message<File> received3 = pollableFileSource.receive();
assertNotSame(received1 + " == " + received2, received1, received2);
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
public void parallelRetrieval() throws Exception {
Message<File> received1 = pollableFileSource.receive();
Message<File> received2 = pollableFileSource.receive();
Message<File> received3 = pollableFileSource.receive();
assertNotSame(received1 + " == " + received2, received1, received2);
assertNotSame(received1 + " == " + received3, received1, received3);
assertNotSame(received2 + " == " + received3, received2, received3);
}
@Test(timeout = 6000)
@Repeat(10)
public void concurrentProcessing() throws Exception {
CountDownLatch go = new CountDownLatch(1);
Runnable succesfulConsumer = new Runnable() {
public void run() {
Message<File> received = pollableFileSource.receive();
while (received == null) {
Thread.yield();
received = pollableFileSource.receive();
}
pollableFileSource.onSend(received);
}
};
Runnable failingConsumer = new Runnable() {
public void run() {
Message<File> received = pollableFileSource.receive();
if (received != null) {
pollableFileSource.onFailure(received, new RuntimeException("nothing"));
}
}
};
CountDownLatch succesfulDone = doConcurrently(3, succesfulConsumer, go);
CountDownLatch failingDone = doConcurrently(10, failingConsumer, go);
go.countDown();
try {
succesfulDone.await();
failingDone.await();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// make sure three different files were taken
Message<File> received = pollableFileSource.receive();
if (received != null) {
pollableFileSource.onSend(received);
}
assertNull(received);
}
@Test
public void inputDirExhausted() throws Exception {
assertNotNull(pollableFileSource.receive());
assertNotNull(pollableFileSource.receive());
assertNotNull(pollableFileSource.receive());
assertNull(pollableFileSource.receive());
}
/**
* Convenience method to run part of a test concurrently in multiple threads
*
* @param numberOfThreads how many threads to spawn
* @param runnable the runnable that should be run by all the threads
* @param start the {@link java.util.concurrent.CountDownLatch} instance telling it when to assume everything works
* @return a latch that will be counted down once all threads have run their
* runnable.
*/
private CountDownLatch doConcurrently(int numberOfThreads, final Runnable runnable, final CountDownLatch start) {
final CountDownLatch started = new CountDownLatch(numberOfThreads);
final CountDownLatch done = new CountDownLatch(numberOfThreads);
for (int i = 0; i < numberOfThreads; i++) {
new Thread(new Runnable() {
@Test(timeout = 6000)
@Repeat(10)
public void concurrentProcessing() throws Exception {
CountDownLatch go = new CountDownLatch(1);
Runnable succesfulConsumer = new Runnable() {
public void run() {
Message<File> received = pollableFileSource.receive();
while (received == null) {
Thread.yield();
received = pollableFileSource.receive();
}
pollableFileSource.onSend(received);
}
};
Runnable failingConsumer = new Runnable() {
public void run() {
Message<File> received = pollableFileSource.receive();
if (received != null) {
pollableFileSource.onFailure(received);
}
}
};
CountDownLatch succesfulDone = doConcurrently(3, succesfulConsumer, go);
CountDownLatch failingDone = doConcurrently(10, failingConsumer, go);
go.countDown();
try {
succesfulDone.await();
failingDone.await();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
// make sure three different files were taken
Message<File> received = pollableFileSource.receive();
if (received != null) {
pollableFileSource.onSend(received);
}
assertNull(received);
}
public void run() {
started.countDown();
try {
started.await();
start.await();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
runnable.run();
done.countDown();
}
}).start();
}
return done;
}
/**
* Convenience method to run part of a test concurrently in multiple threads
*
* @param numberOfThreads how many threads to spawn
* @param runnable the runnable that should be run by all the threads
* @param start the {@link java.util.concurrent.CountDownLatch} instance telling it when to assume everything works
* @return a latch that will be counted down once all threads have run their
* runnable.
*/
private CountDownLatch doConcurrently(int numberOfThreads, final Runnable runnable, final CountDownLatch start) {
final CountDownLatch started = new CountDownLatch(numberOfThreads);
final CountDownLatch done = new CountDownLatch(numberOfThreads);
for (int i = 0; i < numberOfThreads; i++) {
new Thread(new Runnable() {
public void run() {
started.countDown();
try {
started.await();
start.await();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
runnable.run();
done.countDown();
}
}).start();
}
return done;
}
}

View File

@@ -78,7 +78,7 @@ public class FileReadingMessageSourceTests {
when(inputDirectoryMock.listFiles()).thenReturn(new File[]{fileMock});
Message received = source.receive();
assertNotNull(received);
source.onFailure(received, new RuntimeException("failed"));
source.onFailure(received);
assertEquals(received.getPayload(), source.receive().getPayload());
verify(inputDirectoryMock, times(1)).listFiles();
}

View File

@@ -16,77 +16,75 @@
package org.springframework.integration.file;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.integration.file.entries.FileEntryNamer;
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
import java.io.File;
import java.util.List;
import java.util.regex.Pattern;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
*/
public class PatternMatchingFileListFilterTests {
@Test
public void matchSingleFile() {
File[] files = new File[] { new File("/some/path/test.txt") };
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
PatternMatchingFileListFilter filter = new PatternMatchingFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(1, accepted.size());
}
private FileEntryNamer fileEntryNamer = new FileEntryNamer();
@Test
public void noMatchWithSingleFile() {
File[] files = new File[] { new File("/some/path/Test.txt") };
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
PatternMatchingFileListFilter filter = new PatternMatchingFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(0, accepted.size());
}
@Test
public void matchSingleFile() {
File[] files = new File[]{new File("/some/path/test.txt")};
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNamer, pattern);
List<File> accepted = filter.filterEntries(files);
assertEquals(1, accepted.size());
}
@Test
public void matchSubset() {
File[] files = new File[] {
new File("/some/path/foo.txt"),
new File("/some/path/foo.not"),
new File("/some/path/bar.txt"),
new File("/some/path/bar.not")
};
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
PatternMatchingFileListFilter filter = new PatternMatchingFileListFilter(pattern);
List<File> accepted = filter.filterFiles(files);
assertEquals(2, accepted.size());
assertTrue(accepted.contains(new File("/some/path/foo.txt")));
assertTrue(accepted.contains(new File("/some/path/bar.txt")));
}
@Test
public void noMatchWithSingleFile() {
File[] files = new File[]{new File("/some/path/Test.txt")};
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
PatternMatchingEntryListFilter<File> filter = new PatternMatchingEntryListFilter<File>(fileEntryNamer, pattern);
List<File> accepted = filter.filterEntries(files);
assertEquals(0, accepted.size());
}
@Test(expected = IllegalArgumentException.class)
public void nullPattern() {
new PatternMatchingFileListFilter(null);
}
@Test
public void matchSubset() {
File[] files = new File[]{
new File("/some/path/foo.txt"),
new File("/some/path/foo.not"),
new File("/some/path/bar.txt"),
new File("/some/path/bar.not")
};
Pattern pattern = Pattern.compile("[a-z]+\\.txt");
PatternMatchingEntryListFilter filter = new PatternMatchingEntryListFilter(this.fileEntryNamer, pattern);
List<File> accepted = filter.filterEntries(files);
assertEquals(2, accepted.size());
assertTrue(accepted.contains(new File("/some/path/foo.txt")));
assertTrue(accepted.contains(new File("/some/path/bar.txt")));
}
@Test
public void patternEditorInContext() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"patternMatchingFileListFilterTests.xml", this.getClass());
FileListFilter filter = (FileListFilter) context.getBean("filter");
File[] files = new File[] { new File("/some/path/foo.txt") };
List<File> accepted = filter.filterFiles(files);
assertEquals(1, accepted.size());
}
@Test(expected = BeanCreationException.class)
public void invalidPatternSyntax() throws Throwable {
new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass());
}
@Test
public void patternEditorInContext() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"patternMatchingFileListFilterTests.xml", this.getClass());
EntryListFilter<File> filter = (EntryListFilter<File>) context.getBean("filter");
File[] files = new File[]{new File("/some/path/foo.txt")};
List<File> accepted = filter.filterEntries(files);
assertEquals(1, accepted.size());
}
@Test(expected = BeanCreationException.class)
public void invalidPatternSyntax() throws Throwable {
new ClassPathXmlApplicationContext("invalidPatternMatchingFileListFilterTests.xml", this.getClass());
}
}

View File

@@ -16,16 +16,10 @@
package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.File;
import org.junit.AfterClass;
import org.junit.BeforeClass;
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;
@@ -34,6 +28,11 @@ import org.springframework.integration.file.FileWritingMessageHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
*/
@@ -41,92 +40,92 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class AutoCreateDirectoryIntegrationTests {
private static final String BASE_PATH =
System.getProperty("java.io.tmpdir") + File.separator + AutoCreateDirectoryIntegrationTests.class.getSimpleName();
private static final String BASE_PATH =
System.getProperty("java.io.tmpdir") + File.separator + AutoCreateDirectoryIntegrationTests.class.getSimpleName();
@Autowired
private ApplicationContext context;
@Autowired
private ApplicationContext context;
@BeforeClass
public static void setupNonAutoCreatedDirectories() {
new File(BASE_PATH).delete();
new File(BASE_PATH + File.separator + "customInbound").mkdirs();
new File(BASE_PATH + File.separator + "customOutbound").mkdirs();
new File(BASE_PATH + File.separator + "customOutboundGateway").mkdirs();
}
@BeforeClass
public static void setupNonAutoCreatedDirectories() {
new File(BASE_PATH).delete();
new File(BASE_PATH + File.separator + "customInbound").mkdirs();
new File(BASE_PATH + File.separator + "customOutbound").mkdirs();
new File(BASE_PATH + File.separator + "customOutboundGateway").mkdirs();
}
@AfterClass
public static void deleteBaseDirectory() {
new File(BASE_PATH).delete();
}
@AfterClass
public static void deleteBaseDirectory() {
new File(BASE_PATH).delete();
}
@Test
public void defaultInbound() throws Exception {
Object adapter = context.getBean("defaultInbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileReadingMessageSource source = (FileReadingMessageSource)
adapterAccessor.getPropertyValue("source");
assertEquals(Boolean.TRUE,
new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory"));
assertTrue(new File(BASE_PATH + File.separator + "defaultInbound").exists());
}
@Test
public void defaultInbound() throws Exception {
Object adapter = context.getBean("defaultInbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileReadingMessageSource source = (FileReadingMessageSource)
adapterAccessor.getPropertyValue("source");
assertEquals(Boolean.TRUE,
new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory"));
assertTrue(new File(BASE_PATH + File.separator + "defaultInbound").exists());
}
@Test
public void customInbound() throws Exception {
Object adapter = context.getBean("customInbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileReadingMessageSource source = (FileReadingMessageSource)
adapterAccessor.getPropertyValue("source");
assertTrue(new File(BASE_PATH + File.separator + "customInbound").exists());
assertEquals(Boolean.FALSE,
new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory"));
}
@Test
public void customInbound() throws Exception {
Object adapter = context.getBean("customInbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileReadingMessageSource source = (FileReadingMessageSource)
adapterAccessor.getPropertyValue("source");
assertTrue(new File(BASE_PATH + File.separator + "customInbound").exists());
assertEquals(Boolean.FALSE,
new DirectFieldAccessor(source).getPropertyValue("autoCreateDirectory"));
}
@Test
public void defaultOutbound() throws Exception {
Object adapter = context.getBean("defaultOutbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
adapterAccessor.getPropertyValue("handler");
assertEquals(Boolean.TRUE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
assertTrue(new File(BASE_PATH + File.separator + "defaultOutbound").exists());
}
@Test
public void defaultOutbound() throws Exception {
Object adapter = context.getBean("defaultOutbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
adapterAccessor.getPropertyValue("handler");
assertEquals(Boolean.TRUE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
assertTrue(new File(BASE_PATH + File.separator + "defaultOutbound").exists());
}
@Test
public void customOutbound() throws Exception {
Object adapter = context.getBean("customOutbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
adapterAccessor.getPropertyValue("handler");
assertTrue(new File(BASE_PATH + File.separator + "customOutbound").exists());
assertEquals(Boolean.FALSE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
}
@Test
public void customOutbound() throws Exception {
Object adapter = context.getBean("customOutbound");
DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
adapterAccessor.getPropertyValue("handler");
assertTrue(new File(BASE_PATH + File.separator + "customOutbound").exists());
assertEquals(Boolean.FALSE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
}
@Test
public void defaultOutboundGateway() throws Exception {
Object gateway = context.getBean("defaultOutboundGateway");
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
gatewayAccessor.getPropertyValue("handler");
assertEquals(Boolean.TRUE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
assertTrue(new File(BASE_PATH + File.separator + "defaultOutboundGateway").exists());
}
@Test
public void defaultOutboundGateway() throws Exception {
Object gateway = context.getBean("defaultOutboundGateway");
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
gatewayAccessor.getPropertyValue("handler");
assertEquals(Boolean.TRUE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
assertTrue(new File(BASE_PATH + File.separator + "defaultOutboundGateway").exists());
}
@Test
public void customOutboundGateway() throws Exception {
Object gateway = context.getBean("customOutboundGateway");
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
gatewayAccessor.getPropertyValue("handler");
assertTrue(new File(BASE_PATH + File.separator + "customOutboundGateway").exists());
assertEquals(Boolean.FALSE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
}
@Test
public void customOutboundGateway() throws Exception {
Object gateway = context.getBean("customOutboundGateway");
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
gatewayAccessor.getPropertyValue("handler");
assertTrue(new File(BASE_PATH + File.separator + "customOutboundGateway").exists());
assertEquals(Boolean.FALSE,
new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
}
}

View File

@@ -16,18 +16,18 @@
package org.springframework.integration.file.config;
import java.util.Date;
import org.springframework.integration.Message;
import org.springframework.integration.file.FileNameGenerator;
import java.util.Date;
/**
* @author Marius Bogoevici
*/
public class CustomFileNameGenerator implements FileNameGenerator {
public String generateFileName(Message<?> message) {
return "file" + new Date().getTime();
}
public String generateFileName(Message<?> message) {
return "file" + new Date().getTime();
}
}

View File

@@ -16,12 +16,8 @@
package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
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;
@@ -33,6 +29,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Mark Fisher
* @since 1.0.3
@@ -41,32 +40,32 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ContextConfiguration
public class DefaultConfigurationTests {
@Autowired
private ApplicationContext context;
@Autowired
private ApplicationContext context;
@Test
public void verifyErrorChannel() {
Object errorChannel = context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
assertNotNull(errorChannel);
assertEquals(PublishSubscribeChannel.class, errorChannel.getClass());
}
@Test
public void verifyErrorChannel() {
Object errorChannel = context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
assertNotNull(errorChannel);
assertEquals(PublishSubscribeChannel.class, errorChannel.getClass());
}
@Test
public void verifyNullChannel() {
Object nullChannel = context.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
assertNotNull(nullChannel);
assertEquals(NullChannel.class, nullChannel.getClass());
}
@Test
public void verifyNullChannel() {
Object nullChannel = context.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
assertNotNull(nullChannel);
assertEquals(NullChannel.class, nullChannel.getClass());
}
@Test
public void verifyTaskScheduler() {
Object taskScheduler = context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
Object errorHandler = new DirectFieldAccessor(taskScheduler).getPropertyValue("errorHandler");
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
Object defaultErrorChannel = new DirectFieldAccessor(errorHandler).getPropertyValue("defaultErrorChannel");
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
}
@Test
public void verifyTaskScheduler() {
Object taskScheduler = context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
Object errorHandler = new DirectFieldAccessor(taskScheduler).getPropertyValue("errorHandler");
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
Object defaultErrorChannel = new DirectFieldAccessor(errorHandler).getPropertyValue("defaultErrorChannel");
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
}
}

View File

@@ -16,29 +16,24 @@
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 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;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.file.DefaultDirectoryScanner;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
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;
import org.springframework.integration.channel.AbstractMessageChannel;
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.filters.CompositeFileListFilter;
import org.springframework.integration.file.DefaultDirectoryScanner;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.*;
/**
* @author Iwein Fuld
@@ -48,58 +43,58 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class FileInboundChannelAdapterParserTests {
@Autowired(required=true)
private ApplicationContext context;
@Autowired(required = true)
private ApplicationContext context;
@Autowired
private FileReadingMessageSource source;
@Autowired
private FileReadingMessageSource source;
private DirectFieldAccessor accessor;
private DirectFieldAccessor accessor;
@Before
public void init() {
accessor = new DirectFieldAccessor(source);
}
@Before
public void init() {
accessor = new DirectFieldAccessor(source);
}
@Test
public void channelName() throws Exception {
AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class);
assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getComponentName());
}
@Test
public void channelName() throws Exception {
AbstractMessageChannel channel = context.getBean("inputDirPoller", AbstractMessageChannel.class);
assertEquals("Channel should be available under specified id", "inputDirPoller", channel.getComponentName());
}
@Test
public void inputDirectory() {
File expected = new File(System.getProperty("java.io.tmpdir"));
File actual = (File) accessor.getPropertyValue("directory");
assertEquals("'directory' should be set", expected, actual);
}
@Test
public void inputDirectory() {
File expected = new File(System.getProperty("java.io.tmpdir"));
File actual = (File) accessor.getPropertyValue("directory");
assertEquals("'directory' should be set", expected, actual);
}
@Test
public void filter() throws Exception {
DefaultDirectoryScanner scanner = (DefaultDirectoryScanner) accessor.getPropertyValue("scanner");
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner);
Object filter = scannerAccessor.getPropertyValue("filter");
@Test
public void filter() throws Exception {
DefaultDirectoryScanner scanner = (DefaultDirectoryScanner) accessor.getPropertyValue("scanner");
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(scanner);
Object filter = scannerAccessor.getPropertyValue("filter");
assertTrue("'filter' should be set",
filter instanceof AcceptOnceEntryFileListFilter);
}
filter instanceof AcceptOnceEntryFileListFilter);
}
@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);
}
@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<File> {
static class TestComparator implements Comparator<File> {
public int compare(File f1, File f2) {
return 0;
}
}
public int compare(File f1, File f2) {
return 0;
}
}
}

View File

@@ -16,36 +16,28 @@
package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.Set;
import java.util.regex.Pattern;
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.endpoint.AbstractEndpoint;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
import org.springframework.integration.file.filters.*;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import java.util.Set;
import java.util.regex.Pattern;
import static org.junit.Assert.*;
/**
* @author Mark Fisher
* @author Iwein Fuld
@@ -54,90 +46,90 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class FileInboundChannelAdapterWithPatternParserTests {
@Autowired(required=true)
private ApplicationContext context;
@Autowired(required = true)
private ApplicationContext context;
@Autowired(required=true)
@Qualifier("adapterWithPattern.adapter")
private AbstractEndpoint endpoint;
@Autowired(required = true)
@Qualifier("adapterWithPattern.adapter")
private AbstractEndpoint endpoint;
private DirectFieldAccessor accessor;
private DirectFieldAccessor accessor;
@Autowired(required=true)
public void setSource(FileReadingMessageSource source) {
this.accessor = new DirectFieldAccessor(source);
}
@Autowired(required = true)
public void setSource(FileReadingMessageSource source) {
this.accessor = new DirectFieldAccessor(source);
}
@Test
public void channelName() {
AbstractMessageChannel channel = context.getBean("adapterWithPattern", AbstractMessageChannel.class);
assertEquals("adapterWithPattern", channel.getComponentName());
}
@Test
public void channelName() {
AbstractMessageChannel channel = context.getBean("adapterWithPattern", AbstractMessageChannel.class);
assertEquals("adapterWithPattern", channel.getComponentName());
}
@Test
public void autoStartupDisabled() {
assertFalse(this.endpoint.isRunning());
assertEquals(Boolean.FALSE, new DirectFieldAccessor(endpoint).getPropertyValue("autoStartup"));
}
@Test
public void autoStartupDisabled() {
assertFalse(this.endpoint.isRunning());
assertEquals(Boolean.FALSE, new DirectFieldAccessor(endpoint).getPropertyValue("autoStartup"));
}
@Test
public void inputDirectory() {
File expected = new File(System.getProperty("java.io.tmpdir"));
File actual = (File) accessor.getPropertyValue("directory");
assertEquals(expected, actual);
}
@Test
public void inputDirectory() {
File expected = new File(System.getProperty("java.io.tmpdir"));
File actual = (File) accessor.getPropertyValue("directory");
assertEquals(expected, actual);
}
@Test
public void compositeFilterType() {
@Test
public void compositeFilterType() {
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
assertTrue(scannerAccessor.getPropertyValue("filter") instanceof CompositeEntryListFilter);
}
assertTrue(scannerAccessor.getPropertyValue("filter") instanceof CompositeEntryListFilter);
}
@Test
@SuppressWarnings("unchecked")
public void compositeFilterSetSize() {
@Test
@SuppressWarnings("unchecked")
public void compositeFilterSetSize() {
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
Set<FileListFilter> filters = (Set<FileListFilter>) new DirectFieldAccessor(
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
assertEquals(2, filters.size());
}
Set<EntryListFilter<File>> filters = (Set<EntryListFilter<File>>) new DirectFieldAccessor(
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
assertEquals(2, filters.size());
}
@Test
@SuppressWarnings("unchecked")
public void acceptOnceFilter() {
@Test
@SuppressWarnings("unchecked")
public void acceptOnceFilter() {
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
Set<EntryListFilter<File>> filters = (Set<EntryListFilter<File>>) new DirectFieldAccessor(
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
boolean hasAcceptOnceFilter = false;
for (EntryListFilter<File> filter : filters) {
if (filter instanceof AcceptOnceEntryFileListFilter) {
hasAcceptOnceFilter = true;
}
}
assertTrue("expected AcceptOnceFileListFilter", hasAcceptOnceFilter);
}
Set<EntryListFilter<File>> filters = (Set<EntryListFilter<File>>) new DirectFieldAccessor(
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
boolean hasAcceptOnceFilter = false;
for (EntryListFilter<File> filter : filters) {
if (filter instanceof AcceptOnceEntryFileListFilter) {
hasAcceptOnceFilter = true;
}
}
assertTrue("expected AcceptOnceFileListFilter", hasAcceptOnceFilter);
}
@Test
@SuppressWarnings("unchecked")
public void patternFilter() {
@Test
@SuppressWarnings("unchecked")
public void patternFilter() {
DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
Set<EntryListFilter> filters = (Set<EntryListFilter>) new DirectFieldAccessor(
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
Pattern pattern = null;
for (EntryListFilter filter : filters) {
if (filter instanceof PatternMatchingEntryListFilter) {
pattern = (Pattern) new DirectFieldAccessor(filter).getPropertyValue("pattern");
}
}
assertNotNull("expected PatternMatchingFileListFilter", pattern);
assertEquals(".*\\.txt", pattern.toString());
assertFalse(pattern.matcher("foo").matches());
assertTrue(pattern.matcher("foo.txt").matches());
}
Set<EntryListFilter> filters = (Set<EntryListFilter>) new DirectFieldAccessor(
scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
Pattern pattern = null;
for (EntryListFilter filter : filters) {
if (filter instanceof PatternMatchingEntryListFilter) {
pattern = (Pattern) new DirectFieldAccessor(filter).getPropertyValue("pattern");
}
}
assertNotNull("expected PatternMatchingFileListFilter", pattern);
assertEquals(".*\\.txt", pattern.toString());
assertFalse(pattern.matcher("foo").matches());
assertTrue(pattern.matcher("foo.txt").matches());
}
}

View File

@@ -22,15 +22,11 @@ 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.file.*;
import org.springframework.integration.file.TestFileListFilter;
import org.springframework.integration.file.entries.AcceptOnceEntryFileListFilter;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.entries.EntryListFilter;
import org.springframework.integration.file.entries.PatternMatchingEntryListFilter;
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
import org.springframework.integration.file.filters.CompositeFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.filters.PatternMatchingFileListFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -86,7 +82,7 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests {
EntryListFilter filter = this.extractFilter("patternAndNull");
assertTrue(filter instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
Iterator<FileListFilter> iterator = filters.iterator();
Iterator<EntryListFilter<File>> iterator = filters.iterator();
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(iterator.next() instanceof PatternMatchingEntryListFilter);
}
@@ -97,28 +93,28 @@ public class FileInboundChannelAdapterWithPreventDuplicatesFlagTests {
EntryListFilter filter = this.extractFilter("patternAndTrue");
assertTrue(filter instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(filter).getPropertyValue("fileFilters");
Iterator<FileListFilter> iterator = filters.iterator();
Iterator<EntryListFilter> iterator = filters.iterator();
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(iterator.next() instanceof PatternMatchingEntryListFilter);
}
@Test
public void patternAndFalse() throws Exception {
EntryListFilter <File> filter = this.extractFilter("patternAndFalse");
EntryListFilter<File> filter = this.extractFilter("patternAndFalse");
assertFalse(filter instanceof CompositeEntryListFilter);
assertTrue(filter instanceof PatternMatchingEntryListFilter);
}
@Test
public void defaultAndNull() throws Exception {
EntryListFilter <File>filter = this.extractFilter("defaultAndNull");
EntryListFilter<File> filter = this.extractFilter("defaultAndNull");
assertNotNull(filter);
assertFalse(filter instanceof CompositeEntryListFilter);
assertTrue(filter instanceof AcceptOnceEntryFileListFilter);
File testFile = new File("test");
File[] files = new File[]{testFile, testFile, testFile};
List<File> result = filter.filterEntries(files);
assertEquals(1 , result.size());
assertEquals(1, result.size());
}
@Test

View File

@@ -19,7 +19,6 @@ package org.springframework.integration.file.config;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.integration.file.entries.*;
import org.springframework.integration.file.filters.*;
import java.io.File;
import java.util.Collection;
@@ -33,89 +32,90 @@ import static org.junit.Assert.*;
*/
public class FileListFilterFactoryBeanTests {
@Test(expected = IllegalArgumentException.class)
public void customFilterAndFilenamePatternAreMutuallyExclusive() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilterReference(new TestFilter());
factory.setFilenamePattern(Pattern.compile("foo"));
factory.getObject();
}
@Test(expected = IllegalArgumentException.class)
public void customFilterAndFilenamePatternAreMutuallyExclusive() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilterReference(new TestFilter());
factory.setFilenamePattern(Pattern.compile("foo"));
factory.getObject();
}
@Test
public void customFilterAndPreventDuplicatesNull() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
TestFilter testFilter = new TestFilter();
factory.setFilterReference(testFilter);
EntryListFilter<File> result = factory.getObject();
assertFalse(result instanceof CompositeFileListFilter);
assertSame(testFilter, result);
}
@Test
public void customFilterAndPreventDuplicatesNull() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
TestFilter testFilter = new TestFilter();
factory.setFilterReference(testFilter);
EntryListFilter<File> result = factory.getObject();
assertFalse(result instanceof CompositeEntryListFilter);
assertSame(testFilter, result);
}
@Test
@SuppressWarnings("unchecked")
public void customFilterAndPreventDuplicatesTrue() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
TestFilter testFilter = new TestFilter();
factory.setFilterReference(testFilter);
factory.setPreventDuplicates(Boolean.TRUE);
EntryListFilter<File> result = factory.getObject();
assertTrue(result instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
assertTrue(filters.iterator().next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(filters.contains(testFilter));
}
@Test
@SuppressWarnings("unchecked")
public void customFilterAndPreventDuplicatesTrue() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
TestFilter testFilter = new TestFilter();
factory.setFilterReference(testFilter);
factory.setPreventDuplicates(Boolean.TRUE);
EntryListFilter<File> result = factory.getObject();
assertTrue(result instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
assertTrue(filters.iterator().next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(filters.contains(testFilter));
}
@Test
public void customFilterAndPreventDuplicatesFalse() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
TestFilter testFilter = new TestFilter();
factory.setFilterReference(testFilter);
factory.setPreventDuplicates(Boolean.FALSE);
EntryListFilter<File> result = factory.getObject();
assertFalse(result instanceof CompositeEntryListFilter);
assertSame(testFilter, result);
}
@Test
public void customFilterAndPreventDuplicatesFalse() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
TestFilter testFilter = new TestFilter();
factory.setFilterReference(testFilter);
factory.setPreventDuplicates(Boolean.FALSE);
EntryListFilter<File> result = factory.getObject();
assertFalse(result instanceof CompositeEntryListFilter);
assertSame(testFilter, result);
}
@Test
@SuppressWarnings("unchecked")
public void filenamePatternAndPreventDuplicatesNull() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilenamePattern(Pattern.compile("foo"));
EntryListFilter<File> result = factory.getObject();
assertTrue(result instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
Iterator<EntryListFilter> iterator = filters.iterator();
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(iterator.next() instanceof PatternMatchingEntryListFilter);
}
@Test
@SuppressWarnings("unchecked")
public void filenamePatternAndPreventDuplicatesNull() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilenamePattern(Pattern.compile("foo"));
EntryListFilter<File> result = factory.getObject();
assertTrue(result instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
Iterator<EntryListFilter> iterator = filters.iterator();
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(iterator.next() instanceof PatternMatchingEntryListFilter);
}
@Test
@SuppressWarnings("unchecked")
public void filenamePatternAndPreventDuplicatesTrue() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilenamePattern(Pattern.compile("foo"));
factory.setPreventDuplicates(Boolean.TRUE);
EntryListFilter<File> result = factory.getObject();
assertTrue(result instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
Iterator<EntryListFilter> iterator = filters.iterator();
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(iterator.next() instanceof PatternMatchingEntryListFilter);
}
@Test
@SuppressWarnings("unchecked")
public void filenamePatternAndPreventDuplicatesTrue() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilenamePattern(Pattern.compile("foo"));
factory.setPreventDuplicates(Boolean.TRUE);
EntryListFilter<File> result = factory.getObject();
assertTrue(result instanceof CompositeEntryListFilter);
Collection filters = (Collection) new DirectFieldAccessor(result).getPropertyValue("fileFilters");
Iterator<EntryListFilter> iterator = filters.iterator();
assertTrue(iterator.next() instanceof AcceptOnceEntryFileListFilter);
assertTrue(iterator.next() instanceof PatternMatchingEntryListFilter);
}
@Test
public void filenamePatternAndPreventDuplicatesFalse() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilenamePattern(Pattern.compile("foo"));
factory.setPreventDuplicates(Boolean.FALSE);
EntryListFilter<File> result = factory.getObject();
assertFalse(result instanceof CompositeEntryListFilter);;
@Test
public void filenamePatternAndPreventDuplicatesFalse() throws Exception {
FileListFilterFactoryBean factory = new FileListFilterFactoryBean();
factory.setFilenamePattern(Pattern.compile("foo"));
factory.setPreventDuplicates(Boolean.FALSE);
EntryListFilter<File> result = factory.getObject();
assertFalse(result instanceof CompositeEntryListFilter);
;
// CompositeEntryListFilter
assertTrue(result instanceof PatternMatchingEntryListFilter ) ;
}
assertTrue(result instanceof PatternMatchingEntryListFilter);
}
private static class TestFilter extends AbstractEntryListFilter<File> {
private static class TestFilter extends AbstractEntryListFilter<File> {
@Override
public boolean accept(File file) {
return true;

View File

@@ -16,13 +16,8 @@
package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
import java.io.File;
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;
@@ -31,6 +26,10 @@ import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.io.File;
import static org.junit.Assert.assertEquals;
/**
* @author Iwein Fuld
* @author Mark Fisher
@@ -40,31 +39,31 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class FileOutboundAdaptersWithClasspathInPropertiesTests {
@Autowired
@Qualifier("adapter")
private EventDrivenConsumer adapter;
@Autowired
@Qualifier("adapter")
private EventDrivenConsumer adapter;
@Autowired
@Qualifier("gateway")
private EventDrivenConsumer gateway;
@Autowired
@Qualifier("gateway")
private EventDrivenConsumer gateway;
@Test
public void outboundChannelAdapter() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(
new DirectFieldAccessor(adapter).getPropertyValue("handler"));
File expected = new ClassPathResource("").getFile();
File actual = (File) accessor.getPropertyValue("destinationDirectory");
assertEquals("'destinationDirectory' should be set", expected, actual);
}
@Test
public void outboundChannelAdapter() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(
new DirectFieldAccessor(adapter).getPropertyValue("handler"));
File expected = new ClassPathResource("").getFile();
File actual = (File) accessor.getPropertyValue("destinationDirectory");
assertEquals("'destinationDirectory' should be set", expected, actual);
}
@Test
public void outboundGateway() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(
new DirectFieldAccessor(gateway).getPropertyValue("handler"));
File expected = new ClassPathResource("").getFile();
File actual = (File) accessor.getPropertyValue("destinationDirectory");
assertEquals("'destinationDirectory' should be set", expected, actual);
}
@Test
public void outboundGateway() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(
new DirectFieldAccessor(gateway).getPropertyValue("handler"));
File expected = new ClassPathResource("").getFile();
File actual = (File) accessor.getPropertyValue("destinationDirectory");
assertEquals("'destinationDirectory' should be set", expected, actual);
}
}

View File

@@ -16,11 +16,8 @@
package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
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;
@@ -28,6 +25,8 @@ import org.springframework.integration.file.FileWritingMessageHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
/**
* @author Mark Fisher
*/
@@ -35,19 +34,19 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class FileOutboundGatewayParserTests {
@Autowired
private ApplicationContext context;
@Autowired
private ApplicationContext context;
@Test
public void checkOrderedGateway() throws Exception {
Object gateway = context.getBean("ordered");
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
gatewayAccessor.getPropertyValue("handler");
assertEquals(Boolean.FALSE, gatewayAccessor.getPropertyValue("autoStartup"));
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
assertEquals(777, handlerAccessor.getPropertyValue("order"));
}
@Test
public void checkOrderedGateway() throws Exception {
Object gateway = context.getBean("ordered");
DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
FileWritingMessageHandler handler = (FileWritingMessageHandler)
gatewayAccessor.getPropertyValue("handler");
assertEquals(Boolean.FALSE, gatewayAccessor.getPropertyValue("autoStartup"));
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
assertEquals(777, handlerAccessor.getPropertyValue("order"));
}
}

View File

@@ -16,11 +16,8 @@
package org.springframework.integration.file.config;
import static org.junit.Assert.assertEquals;
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;
@@ -30,6 +27,8 @@ import org.springframework.integration.transformer.MessageTransformingHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
/**
* @author Mark Fisher
*/
@@ -37,20 +36,20 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
public class FileToStringTransformerParserTests {
@Autowired
@Qualifier("transformer")
EventDrivenConsumer endpoint;
@Autowired
@Qualifier("transformer")
EventDrivenConsumer endpoint;
@Test
public void checkDeleteFilesValue() {
DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(endpoint);
MessageTransformingHandler handler = (MessageTransformingHandler)
endpointAccessor.getPropertyValue("handler");
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
FileToStringTransformer transformer = (FileToStringTransformer)
handlerAccessor.getPropertyValue("transformer");
DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer);
assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles"));
}
@Test
public void checkDeleteFilesValue() {
DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(endpoint);
MessageTransformingHandler handler = (MessageTransformingHandler)
endpointAccessor.getPropertyValue("handler");
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
FileToStringTransformer transformer = (FileToStringTransformer)
handlerAccessor.getPropertyValue("transformer");
DirectFieldAccessor transformerAccessor = new DirectFieldAccessor(transformer);
assertEquals(Boolean.TRUE, transformerAccessor.getPropertyValue("deleteFiles"));
}
}

View File

@@ -1,11 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="filter" class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
<constructor-arg value="[fo+\.[tx]{3}"/>
</bean>
<bean id="filter" class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
<constructor-arg>
<bean class="org.springframework.integration.file.entries.FileEntryNamer"/>
</constructor-arg>
<constructor-arg value="[fo+\.[tx]{3}"/>
</bean>
</beans>

View File

@@ -22,9 +22,8 @@ import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.integration.file.filters.CompositeFileListFilter;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.entries.CompositeEntryListFilter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -52,9 +51,10 @@ public class FileLockingNamespaceTests {
FileReadingMessageSource customLockingSource;
@Before public void extractSources() {
nioLockingSource = (FileReadingMessageSource) new DirectFieldAccessor( nioAdapter).getPropertyValue("source");
customLockingSource = (FileReadingMessageSource) new DirectFieldAccessor( customAdapter).getPropertyValue("source");
@Before
public void extractSources() {
nioLockingSource = (FileReadingMessageSource) new DirectFieldAccessor(nioAdapter).getPropertyValue("source");
customLockingSource = (FileReadingMessageSource) new DirectFieldAccessor(customAdapter).getPropertyValue("source");
}
@Test
@@ -69,7 +69,7 @@ public class FileLockingNamespaceTests {
}
private Object extractFromScanner(String propertyName, FileReadingMessageSource source) {
return new DirectFieldAccessor( new DirectFieldAccessor(source).getPropertyValue("scanner") ).getPropertyValue(propertyName);
return new DirectFieldAccessor(new DirectFieldAccessor(source).getPropertyValue("scanner")).getPropertyValue(propertyName);
}
@Test

View File

@@ -1,11 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="filter" class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
<constructor-arg value="fo+\.[tx]{3}"/>
</bean>
<!--<bean class="org.springframework.integration.file.filters.PatternMatchingFileListFilter">
<constructor-arg value="fo+\.[tx]{3}"/>
</bean>
-->
<bean id="filter" class="org.springframework.integration.file.entries.PatternMatchingEntryListFilter">
<constructor-arg>
<bean class="org.springframework.integration.file.entries.FileEntryNamer"/>
</constructor-arg>
<constructor-arg value="fo+\.[tx]{3}"/>
</bean>
</beans>

View File

@@ -39,7 +39,8 @@ import java.util.regex.Pattern;
public class FtpFileSource implements MessageSource<File>, InitializingBean, Lifecycle {
private FileReadingMessageSource fileSource;
private FtpInboundSynchronizer synchronizer;
private EntryNamer fileEntryName = new FileEntryNamer();
private EntryNamer fileEntryName = new FileEntryNamer();
public FtpFileSource() {
this(new FileReadingMessageSource(), new FtpInboundSynchronizer());
}
@@ -49,8 +50,8 @@ public class FtpFileSource implements MessageSource<File>, InitializingBean, Lif
this.synchronizer = synchronizer;
Pattern completePattern = Pattern.compile("^.*(?<!" + FtpInboundSynchronizer.INCOMPLETE_EXTENSION + ")$");
EntryListFilter<File> f =new CompositeEntryListFilter<File>(new AcceptOnceEntryFileListFilter<File>(),
new PatternMatchingEntryListFilter(fileEntryName,completePattern));
EntryListFilter<File> f = new CompositeEntryListFilter<File>(new AcceptOnceEntryFileListFilter<File>(),
new PatternMatchingEntryListFilter(fileEntryName, completePattern));
fileSource.setFilter(f);
}
@@ -93,7 +94,7 @@ public class FtpFileSource implements MessageSource<File>, InitializingBean, Lif
}
public void onFailure(Message<File> failedMessage, Throwable t) {
fileSource.onFailure(failedMessage, t);
fileSource.onFailure(failedMessage);
}
public void onSend(Message<File> sentMessage) {

View File

@@ -22,10 +22,11 @@ import java.util.*;
/**
* Patterned very much on the {@link org.springframework.integration.file.filters.CompositeFileListFilter}
* Patterned very much on th
*
* @author Josh Long
*/ @Deprecated
*/
@Deprecated
public class CompositeFtpFileListFilter implements SftpFileListFilter {
private Set<SftpFileListFilter> filters;

View File

@@ -28,14 +28,14 @@ import java.util.regex.Pattern;
/**
* Validates {@link com.jcraft.jsch.ChannelSftp.LsEntry}s against a {@link java.util.regex.Pattern}.
* Patterned very much like {@link org.springframework.integration.file.filters.PatternMatchingFileListFilter}.
*
* @author Josh Long
*/ @Deprecated
*/
@Deprecated
public class PatternMatchingSftpFileListFilter extends AbstractSftpFileListFilter implements InitializingBean {
private Log logger = LogFactory.getLog(getClass());
private Pattern pattern;
private String patternExpression;