use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration by spring-projects.
the class FileInboundChannelAdapterWithPreventDuplicatesFlagTests method defaultAndFalse.
@Test
public void defaultAndFalse() throws Exception {
FileListFilter<File> filter = this.extractFilter("defaultAndFalse");
assertNotNull(filter);
assertFalse(filter instanceof CompositeFileListFilter);
assertFalse(filter instanceof AcceptOnceFileListFilter);
File testFile = new File("test");
File[] files = new File[] { testFile, testFile, testFile };
List<File> result = filter.filterFiles(files);
assertEquals(3, result.size());
}
use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration by spring-projects.
the class FtpInboundChannelAdapterSpec method composeFilters.
@SuppressWarnings("unchecked")
private CompositeFileListFilter<FTPFile> composeFilters(FileListFilter<FTPFile> fileListFilter) {
CompositeFileListFilter<FTPFile> compositeFileListFilter = new CompositeFileListFilter<>();
compositeFileListFilter.addFilters(fileListFilter, new FtpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "ftpMessageSource"));
return compositeFileListFilter;
}
use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration by spring-projects.
the class SftpInboundRemoteFileSystemSynchronizerTests method testCopyFileToLocalDir.
@Test
public void testCopyFileToLocalDir() throws Exception {
File localDirectory = new File("test");
assertFalse(localDirectory.exists());
TestSftpSessionFactory ftpSessionFactory = new TestSftpSessionFactory();
ftpSessionFactory.setUser("kermit");
ftpSessionFactory.setPassword("frog");
ftpSessionFactory.setHost("foo.com");
SftpInboundFileSynchronizer synchronizer = spy(new SftpInboundFileSynchronizer(ftpSessionFactory));
synchronizer.setDeleteRemoteFiles(true);
synchronizer.setPreserveTimestamp(true);
synchronizer.setRemoteDirectory("remote-test-dir");
SftpRegexPatternFileListFilter patternFilter = new SftpRegexPatternFileListFilter(".*\\.test$");
PropertiesPersistingMetadataStore store = spy(new PropertiesPersistingMetadataStore());
store.setBaseDirectory("test");
store.afterPropertiesSet();
SftpPersistentAcceptOnceFileListFilter persistFilter = new SftpPersistentAcceptOnceFileListFilter(store, "foo");
List<FileListFilter<LsEntry>> filters = new ArrayList<FileListFilter<LsEntry>>();
filters.add(persistFilter);
filters.add(patternFilter);
CompositeFileListFilter<LsEntry> filter = new CompositeFileListFilter<LsEntry>(filters);
synchronizer.setFilter(filter);
synchronizer.setBeanFactory(mock(BeanFactory.class));
synchronizer.afterPropertiesSet();
SftpInboundFileSynchronizingMessageSource ms = new SftpInboundFileSynchronizingMessageSource(synchronizer);
ms.setAutoCreateLocalDirectory(true);
ms.setLocalDirectory(localDirectory);
ms.setBeanFactory(mock(BeanFactory.class));
CompositeFileListFilter<File> localFileListFilter = new CompositeFileListFilter<File>();
localFileListFilter.addFilter(new RegexPatternFileListFilter(".*\\.test$"));
AcceptOnceFileListFilter<File> localAcceptOnceFilter = new AcceptOnceFileListFilter<File>();
localFileListFilter.addFilter(localAcceptOnceFilter);
ms.setLocalFilter(localFileListFilter);
ms.afterPropertiesSet();
ms.start();
Message<File> atestFile = ms.receive();
assertNotNull(atestFile);
assertEquals("a.test", atestFile.getPayload().getName());
// The test remote files are created with the current timestamp + 1 day.
assertThat(atestFile.getPayload().lastModified(), Matchers.greaterThan(System.currentTimeMillis()));
Message<File> btestFile = ms.receive();
assertNotNull(btestFile);
assertEquals("b.test", btestFile.getPayload().getName());
// The test remote files are created with the current timestamp + 1 day.
assertThat(atestFile.getPayload().lastModified(), Matchers.greaterThan(System.currentTimeMillis()));
Message<File> nothing = ms.receive();
assertNull(nothing);
// two times because on the third receive (above) the internal queue will be empty, so it will attempt
verify(synchronizer, times(2)).synchronizeToLocalDirectory(localDirectory, Integer.MIN_VALUE);
assertTrue(new File("test/a.test").exists());
assertTrue(new File("test/b.test").exists());
TestUtils.getPropertyValue(localAcceptOnceFilter, "seenSet", Collection.class).clear();
new File("test/a.test").delete();
new File("test/b.test").delete();
// the remote filter should prevent a re-fetch
nothing = ms.receive();
assertNull(nothing);
ms.stop();
verify(synchronizer).close();
verify(store).close();
}
use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration by spring-projects.
the class SftpStreamingInboundChannelAdapterSpec method composeFilters.
@SuppressWarnings("unchecked")
private CompositeFileListFilter<LsEntry> composeFilters(FileListFilter<LsEntry> fileListFilter) {
CompositeFileListFilter<LsEntry> compositeFileListFilter = new CompositeFileListFilter<>();
compositeFileListFilter.addFilters(fileListFilter, new SftpPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "sftpStreamingMessageSource"));
return compositeFileListFilter;
}
use of org.springframework.integration.file.filters.CompositeFileListFilter in project spring-integration-aws by spring-projects.
the class S3InboundChannelAdapterParserTests method testS3InboundChannelAdapterComplete.
@Test
@SuppressWarnings("unchecked")
public void testS3InboundChannelAdapterComplete() throws Exception {
assertThat(TestUtils.getPropertyValue(this.s3Inbound, "autoStartup", Boolean.class)).isFalse();
PriorityBlockingQueue<?> blockingQueue = TestUtils.getPropertyValue(this.s3Inbound, "source.fileSource.toBeReceived", PriorityBlockingQueue.class);
Comparator<?> comparator = blockingQueue.comparator();
assertThat(comparator).isSameAs(this.comparator);
assertThat(this.s3Inbound.getComponentName()).isEqualTo("s3Inbound");
assertThat(this.s3Inbound.getComponentType()).isEqualTo("aws:s3-inbound-channel-adapter");
assertThat(TestUtils.getPropertyValue(this.s3Inbound, "outputChannel")).isSameAs(this.s3Channel);
S3InboundFileSynchronizingMessageSource inbound = TestUtils.getPropertyValue(this.s3Inbound, "source", S3InboundFileSynchronizingMessageSource.class);
S3InboundFileSynchronizer fisync = TestUtils.getPropertyValue(inbound, "synchronizer", S3InboundFileSynchronizer.class);
assertThat(TestUtils.getPropertyValue(fisync, "remoteDirectoryExpression", Expression.class).getExpressionString()).isEqualTo("'foo/bar'");
assertThat(TestUtils.getPropertyValue(fisync, "localFilenameGeneratorExpression")).isNotNull();
assertThat(TestUtils.getPropertyValue(fisync, "preserveTimestamp", Boolean.class)).isTrue();
assertThat(TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class)).isEqualTo(".foo");
String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator");
assertThat(remoteFileSeparator).isEqualTo("\\");
CompositeFileListFilter<?> filter = TestUtils.getPropertyValue(fisync, "filter", CompositeFileListFilter.class);
assertThat(filter).isNotNull();
Set<FileListFilter<?>> fileFilters = TestUtils.getPropertyValue(filter, "fileFilters", Set.class);
assertThat(fileFilters).size().isEqualTo(2);
List<FileListFilter<?>> filters = new ArrayList<>(fileFilters);
assertThat(filters.get(0)).isInstanceOf(S3SimplePatternFileListFilter.class);
assertThat(filters.get(1)).isInstanceOf(S3PersistentAcceptOnceFileListFilter.class);
assertThat(TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory")).isSameAs(this.s3SessionFactory);
assertThat(TestUtils.getPropertyValue(inbound, "fileSource.scanner.filter.fileFilters", Collection.class).contains(this.acceptAllFilter)).isTrue();
final AtomicReference<Method> genMethod = new AtomicReference<Method>();
ReflectionUtils.doWithMethods(AbstractInboundFileSynchronizer.class, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
if ("generateLocalFileName".equals(method.getName())) {
method.setAccessible(true);
genMethod.set(method);
}
}
});
assertThat(genMethod.get().invoke(fisync, "foo")).isEqualTo("FOO.afoo");
}
Aggregations