use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpFileListFilterTests method testMarkerFile.
@Test
public void testMarkerFile() throws Exception {
FtpSystemMarkerFilePresentFileListFilter filter = new FtpSystemMarkerFilePresentFileListFilter(new FtpSimplePatternFileListFilter("*.txt"));
FTPFile[] files = template.list("ftpSource");
assertThat(files.length, greaterThan(0));
List<FTPFile> filtered = filter.filterFiles(files);
assertThat(filtered.size(), equalTo(0));
File remoteDir = getSourceRemoteDirectory();
File marker = new File(remoteDir, "ftpSource2.txt.complete");
marker.createNewFile();
files = template.list("ftpSource");
filtered = filter.filterFiles(files);
assertThat(filtered.size(), equalTo(1));
assertThat(filtered.get(0).getName(), equalTo("ftpSource2.txt"));
marker.delete();
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpOutboundTests method testHandleFileContentMessage.
@Test
public void testHandleFileContentMessage() throws Exception {
File file = new File("remote-target-dir/handlerContent.test");
if (file.exists()) {
file.delete();
}
assertFalse(file.exists());
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setFileNameGenerator(message -> "handlerContent.test");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage<String>("String data"));
assertTrue(file.exists());
byte[] inFile = FileCopyUtils.copyToByteArray(file);
assertEquals("String data", new String(inFile));
file.delete();
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpOutboundTests method testHandleMissingFileMessage.
@Test
public void testHandleMissingFileMessage() throws Exception {
File targetDir = new File("remote-target-dir");
assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists());
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression(targetDir.getName()));
handler.setFileNameGenerator(message -> ((File) message.getPayload()).getName() + ".test");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
File srcFile = new File(UUID.randomUUID() + ".txt");
Log logger = spy(TestUtils.getPropertyValue(handler, "remoteFileTemplate.logger", Log.class));
when(logger.isWarnEnabled()).thenReturn(true);
final AtomicReference<String> logged = new AtomicReference<>();
doAnswer(invocation -> {
logged.set(invocation.getArgument(0));
invocation.callRealMethod();
return null;
}).when(logger).warn(Mockito.anyString());
RemoteFileTemplate<?> template = TestUtils.getPropertyValue(handler, "remoteFileTemplate", RemoteFileTemplate.class);
new DirectFieldAccessor(template).setPropertyValue("logger", logger);
handler.handleMessage(new GenericMessage<File>(srcFile));
assertNotNull(logged.get());
assertEquals("File " + srcFile.toString() + " does not exist", logged.get());
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpOutboundTests method testHandleFileAsByte.
@Test
public void testHandleFileAsByte() throws Exception {
File file = new File("remote-target-dir/handlerContent.test");
if (file.exists()) {
file.delete();
}
assertFalse(file.exists());
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir"));
handler.setFileNameGenerator(message -> "handlerContent.test");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
handler.handleMessage(new GenericMessage<byte[]>("byte[] data".getBytes()));
assertTrue(file.exists());
byte[] inFile = FileCopyUtils.copyToByteArray(file);
assertEquals("byte[] data", new String(inFile));
file.delete();
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpOutboundTests method testHandleFileMessage.
@Test
public void testHandleFileMessage() throws Exception {
File targetDir = new File("remote-target-dir");
assertTrue("target directory does not exist: " + targetDir.getName(), targetDir.exists());
FileTransferringMessageHandler<FTPFile> handler = new FileTransferringMessageHandler<FTPFile>(sessionFactory);
handler.setRemoteDirectoryExpression(new LiteralExpression(targetDir.getName()));
handler.setFileNameGenerator(message -> ((File) message.getPayload()).getName() + ".test");
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
File srcFile = File.createTempFile("testHandleFileMessage", ".tmp");
srcFile.deleteOnExit();
File destFile = new File(targetDir, srcFile.getName() + ".test");
destFile.deleteOnExit();
handler.handleMessage(new GenericMessage<File>(srcFile));
assertTrue("destination file was not created", destFile.exists());
}
Aggregations