use of org.springframework.integration.file.remote.ClientCallbackWithoutResult in project spring-integration by spring-projects.
the class FtpRemoteFileTemplateTests method testINT3412AppendStatRmdir.
@Test
public void testINT3412AppendStatRmdir() throws IOException {
FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sessionFactory);
DefaultFileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
fileNameGenerator.setExpression("'foobar.txt'");
template.setFileNameGenerator(fileNameGenerator);
template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
template.setUseTemporaryFileName(false);
template.execute(session -> {
session.mkdir("foo/");
return session.mkdir("foo/bar/");
});
template.append(new GenericMessage<String>("foo"));
template.append(new GenericMessage<String>("bar"));
assertTrue(template.exists("foo/foobar.txt"));
template.executeWithClient((ClientCallbackWithoutResult<FTPClient>) client -> {
try {
FTPFile[] files = client.listFiles("foo/foobar.txt");
assertEquals(6, files[0].getSize());
} catch (IOException e) {
throw new RuntimeException(e);
}
});
template.execute((SessionCallbackWithoutResult<FTPFile>) session -> {
assertTrue(session.remove("foo/foobar.txt"));
assertTrue(session.rmdir("foo/bar/"));
FTPFile[] files = session.list("foo/");
assertEquals(0, files.length);
assertTrue(session.rmdir("foo/"));
});
assertFalse(template.getSession().exists("foo"));
}
use of org.springframework.integration.file.remote.ClientCallbackWithoutResult in project spring-integration by spring-projects.
the class SftpRemoteFileTemplateTests method testINT3412AppendStatRmdir.
@Test
public void testINT3412AppendStatRmdir() {
SftpRemoteFileTemplate template = new SftpRemoteFileTemplate(sessionFactory);
DefaultFileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
fileNameGenerator.setExpression("'foobar.txt'");
template.setFileNameGenerator(fileNameGenerator);
template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
template.setUseTemporaryFileName(false);
template.execute(session -> {
session.mkdir("foo/");
return session.mkdir("foo/bar/");
});
template.append(new GenericMessage<String>("foo"));
template.append(new GenericMessage<String>("bar"));
assertTrue(template.exists("foo/foobar.txt"));
template.executeWithClient((ClientCallbackWithoutResult<ChannelSftp>) client -> {
try {
SftpATTRS file = client.lstat("foo/foobar.txt");
assertEquals(6, file.getSize());
} catch (SftpException e) {
throw new RuntimeException(e);
}
});
template.execute((SessionCallbackWithoutResult<LsEntry>) session -> {
LsEntry[] files = session.list("foo/");
assertEquals(4, files.length);
assertTrue(session.remove("foo/foobar.txt"));
assertTrue(session.rmdir("foo/bar/"));
files = session.list("foo/");
assertEquals(2, files.length);
List<LsEntry> list = Arrays.asList(files);
assertThat(list.stream().map(l -> l.getFilename()).collect(Collectors.toList()), containsInAnyOrder(".", ".."));
assertTrue(session.rmdir("foo/"));
});
assertFalse(template.exists("foo"));
}
Aggregations