Search in sources :

Example 6 with AcceptOnceFileListFilter

use of org.springframework.integration.file.filters.AcceptOnceFileListFilter in project spring-integration by spring-projects.

the class FileInboundChannelAdapterParserTests method 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 and be of instance AcceptOnceFileListFilter but got " + filter.getClass().getSimpleName(), filter instanceof AcceptOnceFileListFilter);
    assertThat(scanner.getClass().getName(), containsString("FileReadingMessageSource$WatchServiceDirectoryScanner"));
    FileReadingMessageSource.WatchEventType[] watchEvents = (FileReadingMessageSource.WatchEventType[]) this.accessor.getPropertyValue("watchEvents");
    assertEquals(2, watchEvents.length);
    for (FileReadingMessageSource.WatchEventType watchEvent : watchEvents) {
        assertNotEquals(FileReadingMessageSource.WatchEventType.CREATE, watchEvent);
        assertThat(watchEvent, isOneOf(FileReadingMessageSource.WatchEventType.MODIFY, FileReadingMessageSource.WatchEventType.DELETE));
    }
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) DefaultDirectoryScanner(org.springframework.integration.file.DefaultDirectoryScanner) FileReadingMessageSource(org.springframework.integration.file.FileReadingMessageSource) Test(org.junit.Test)

Example 7 with AcceptOnceFileListFilter

use of org.springframework.integration.file.filters.AcceptOnceFileListFilter in project spring-integration by spring-projects.

the class FileInboundChannelAdapterWithPatternParserTests method acceptOnceFilter.

@Test
@SuppressWarnings("unchecked")
public void acceptOnceFilter() {
    DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
    Set<FileListFilter<File>> filters = (Set<FileListFilter<File>>) new DirectFieldAccessor(scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
    boolean hasAcceptOnceFilter = false;
    for (FileListFilter<File> filter : filters) {
        if (filter instanceof AcceptOnceFileListFilter) {
            hasAcceptOnceFilter = true;
        }
    }
    assertTrue("expected AcceptOnceFileListFilter", hasAcceptOnceFilter);
}
Also used : Set(java.util.Set) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) FileListFilter(org.springframework.integration.file.filters.FileListFilter) SimplePatternFileListFilter(org.springframework.integration.file.filters.SimplePatternFileListFilter) CompositeFileListFilter(org.springframework.integration.file.filters.CompositeFileListFilter) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) File(java.io.File) Test(org.junit.Test)

Example 8 with AcceptOnceFileListFilter

use of org.springframework.integration.file.filters.AcceptOnceFileListFilter in project spring-integration by spring-projects.

the class FileInboundChannelAdapterWithPreventDuplicatesFlagTests method defaultAndTrue.

@Test
public void defaultAndTrue() throws Exception {
    FileListFilter<File> filter = this.extractFilter("defaultAndTrue");
    assertFalse(filter instanceof CompositeFileListFilter);
    assertTrue(filter instanceof AcceptOnceFileListFilter);
    File testFile = new File("test");
    File[] files = new File[] { testFile, testFile, testFile };
    List<File> result = filter.filterFiles(files);
    assertEquals(1, result.size());
}
Also used : CompositeFileListFilter(org.springframework.integration.file.filters.CompositeFileListFilter) AcceptOnceFileListFilter(org.springframework.integration.file.filters.AcceptOnceFileListFilter) File(java.io.File) Test(org.junit.Test)

Aggregations

AcceptOnceFileListFilter (org.springframework.integration.file.filters.AcceptOnceFileListFilter)8 File (java.io.File)7 Test (org.junit.Test)7 CompositeFileListFilter (org.springframework.integration.file.filters.CompositeFileListFilter)7 FileListFilter (org.springframework.integration.file.filters.FileListFilter)4 ArrayList (java.util.ArrayList)3 RegexPatternFileListFilter (org.springframework.integration.file.filters.RegexPatternFileListFilter)3 Collection (java.util.Collection)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 SimplePatternFileListFilter (org.springframework.integration.file.filters.SimplePatternFileListFilter)2 PropertiesPersistingMetadataStore (org.springframework.integration.metadata.PropertiesPersistingMetadataStore)2 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)1 Set (java.util.Set)1 FTPFile (org.apache.commons.net.ftp.FTPFile)1 Expression (org.springframework.expression.Expression)1 ExpressionParser (org.springframework.expression.ExpressionParser)1 SpelParserConfiguration (org.springframework.expression.spel.SpelParserConfiguration)1 SpelExpressionParser (org.springframework.expression.spel.standard.SpelExpressionParser)1 DefaultDirectoryScanner (org.springframework.integration.file.DefaultDirectoryScanner)1