Search in sources :

Example 6 with FileListFilter

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

the class PatternMatchingFileListFilterTests method patternEditorInContext.

@Test
@SuppressWarnings("unchecked")
public void patternEditorInContext() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("patternMatchingFileListFilterTests.xml", this.getClass());
    FileListFilter<File> filter = (FileListFilter<File>) context.getBean("filter");
    File[] files = new File[] { new File("/some/path/foo.txt") };
    List<File> accepted = filter.filterFiles(files);
    assertEquals(1, accepted.size());
    context.close();
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) FileListFilter(org.springframework.integration.file.filters.FileListFilter) RegexPatternFileListFilter(org.springframework.integration.file.filters.RegexPatternFileListFilter) File(java.io.File) Test(org.junit.Test)

Example 7 with FileListFilter

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

the class FileInboundChannelAdapterWithPatternParserTests method compositeFilterSetSize.

@Test
@SuppressWarnings("unchecked")
public void compositeFilterSetSize() {
    DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
    Set<FileListFilter<File>> filters = (Set<FileListFilter<File>>) new DirectFieldAccessor(scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
    assertEquals(2, filters.size());
}
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) File(java.io.File) Test(org.junit.Test)

Example 8 with FileListFilter

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

the class FileInboundChannelAdapterWithPatternParserTests method patternFilter.

@Test
@SuppressWarnings("unchecked")
public void patternFilter() {
    DirectFieldAccessor scannerAccessor = new DirectFieldAccessor(accessor.getPropertyValue("scanner"));
    Set<FileListFilter<?>> filters = (Set<FileListFilter<?>>) new DirectFieldAccessor(scannerAccessor.getPropertyValue("filter")).getPropertyValue("fileFilters");
    String pattern = null;
    for (FileListFilter<?> filter : filters) {
        if (filter instanceof SimplePatternFileListFilter) {
            pattern = (String) new DirectFieldAccessor(filter).getPropertyValue("path");
        }
    }
    assertNotNull("expected SimplePatternFileListFilterTest", pattern);
    assertEquals("*.txt", pattern.toString());
}
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) SimplePatternFileListFilter(org.springframework.integration.file.filters.SimplePatternFileListFilter) Test(org.junit.Test)

Example 9 with FileListFilter

use of org.springframework.integration.file.filters.FileListFilter 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 10 with FileListFilter

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

the class FileInboundChannelAdapterWithClasspathInPropertiesTests method inputDirectory.

@Test
@SuppressWarnings("unchecked")
public void inputDirectory() throws Exception {
    File expected = new ClassPathResource("").getFile();
    File actual = (File) accessor.getPropertyValue("directory");
    assertEquals("'directory' should be set", expected, actual);
    FileListFilter<File> fileListFilter = TestUtils.getPropertyValue(this.source, "scanner.filter", FileListFilter.class);
    assertThat(fileListFilter, instanceOf(CompositeFileListFilter.class));
    Set<FileListFilter<File>> fileFilters = TestUtils.getPropertyValue(fileListFilter, "fileFilters", Set.class);
    assertEquals(2, fileFilters.size());
    Iterator<FileListFilter<File>> iterator = fileFilters.iterator();
    iterator.next();
    FileListFilter<File> expressionFilter = iterator.next();
    assertThat(expressionFilter, instanceOf(ExpressionFileListFilter.class));
    assertEquals("true", TestUtils.getPropertyValue(expressionFilter, "expression.expression", String.class));
    assertSame(this.beanFactory, TestUtils.getPropertyValue(expressionFilter, "beanFactory"));
}
Also used : CompositeFileListFilter(org.springframework.integration.file.filters.CompositeFileListFilter) ExpressionFileListFilter(org.springframework.integration.file.filters.ExpressionFileListFilter) FileListFilter(org.springframework.integration.file.filters.FileListFilter) ExpressionFileListFilter(org.springframework.integration.file.filters.ExpressionFileListFilter) CompositeFileListFilter(org.springframework.integration.file.filters.CompositeFileListFilter) File(java.io.File) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

FileListFilter (org.springframework.integration.file.filters.FileListFilter)11 Test (org.junit.Test)10 CompositeFileListFilter (org.springframework.integration.file.filters.CompositeFileListFilter)9 File (java.io.File)8 AcceptOnceFileListFilter (org.springframework.integration.file.filters.AcceptOnceFileListFilter)6 RegexPatternFileListFilter (org.springframework.integration.file.filters.RegexPatternFileListFilter)5 ArrayList (java.util.ArrayList)4 Set (java.util.Set)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)4 SimplePatternFileListFilter (org.springframework.integration.file.filters.SimplePatternFileListFilter)4 Collection (java.util.Collection)3 BeanFactory (org.springframework.beans.factory.BeanFactory)2 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)2 Expression (org.springframework.expression.Expression)2 AcceptAllFileListFilter (org.springframework.integration.file.filters.AcceptAllFileListFilter)2 PropertiesPersistingMetadataStore (org.springframework.integration.metadata.PropertiesPersistingMetadataStore)2 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)1 Method (java.lang.reflect.Method)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Pattern (java.util.regex.Pattern)1