List of usage examples for org.springframework.integration.ftp.inbound FtpInboundFileSynchronizingMessageSource FtpInboundFileSynchronizingMessageSource
public FtpInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<FTPFile> synchronizer)
From source file:org.springframework.integration.ftp.inbound.FtpInboundRemoteFileSystemSynchronizerTests.java
@Test public void testCopyFileToLocalDir() throws Exception { File localDirectoy = new File("test"); assertFalse(localDirectoy.exists()); TestFtpSessionFactory ftpSessionFactory = new TestFtpSessionFactory(); ftpSessionFactory.setUsername("kermit"); ftpSessionFactory.setPassword("frog"); ftpSessionFactory.setHost("foo.com"); FtpInboundFileSynchronizer synchronizer = spy(new FtpInboundFileSynchronizer(ftpSessionFactory)); synchronizer.setDeleteRemoteFiles(true); synchronizer.setRemoteDirectory("remote-test-dir"); synchronizer.setFilter(new FtpRegexPatternFileListFilter(".*\\.test$")); synchronizer.setIntegrationEvaluationContext(ExpressionUtils.createStandardEvaluationContext()); ExpressionParser expressionParser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); Expression expression = expressionParser.parseExpression("#this.toUpperCase() + '.a'"); synchronizer.setLocalFilenameGeneratorExpression(expression); FtpInboundFileSynchronizingMessageSource ms = new FtpInboundFileSynchronizingMessageSource(synchronizer); ms.setAutoCreateLocalDirectory(true); ms.setLocalDirectory(localDirectoy); ms.afterPropertiesSet();//w w w. j av a 2 s .c o m Message<File> atestFile = ms.receive(); assertNotNull(atestFile); assertEquals("A.TEST.a", atestFile.getPayload().getName()); Message<File> btestFile = ms.receive(); assertNotNull(btestFile); assertEquals("B.TEST.a", btestFile.getPayload().getName()); 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(localDirectoy); assertTrue(new File("test/A.TEST.a").exists()); assertTrue(new File("test/B.TEST.a").exists()); }