use of org.springframework.integration.file.DefaultDirectoryScanner 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));
}
}
use of org.springframework.integration.file.DefaultDirectoryScanner in project spring-integration by spring-projects.
the class AbstractInboundFileSynchronizingMessageSource method afterPropertiesSet.
@Override
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.notNull(this.localDirectory, "localDirectory must not be null");
try {
if (!this.localDirectory.exists()) {
if (this.autoCreateLocalDirectory) {
if (logger.isDebugEnabled()) {
logger.debug("The '" + this.localDirectory + "' directory doesn't exist; Will create.");
}
this.localDirectory.mkdirs();
} else {
throw new FileNotFoundException(this.localDirectory.getName());
}
}
this.fileSource.setDirectory(this.localDirectory);
if (this.localFileListFilter == null) {
this.localFileListFilter = new FileSystemPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), getComponentName());
}
FileListFilter<File> filter = buildFilter();
if (this.scannerExplicitlySet) {
Assert.state(!this.fileSource.isUseWatchService(), "'useWatchService' and 'scanner' are mutually exclusive.");
this.fileSource.getScanner().setFilter(filter);
} else if (!this.fileSource.isUseWatchService()) {
DirectoryScanner directoryScanner = new DefaultDirectoryScanner();
directoryScanner.setFilter(filter);
this.fileSource.setScanner(directoryScanner);
} else {
this.fileSource.setFilter(filter);
}
if (this.getBeanFactory() != null) {
this.fileSource.setBeanFactory(this.getBeanFactory());
}
this.fileSource.afterPropertiesSet();
this.synchronizer.afterPropertiesSet();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new BeanInitializationException("Failure during initialization of MessageSource for: " + this.getClass(), e);
}
}
Aggregations