use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpServerOutboundTests method testMgetPartial.
@Test
public void testMgetPartial() throws Exception {
Session<FTPFile> session = spyOnSession();
doAnswer(invocation -> {
FTPFile[] files = (FTPFile[]) invocation.callRealMethod();
// add an extra file where the get will fail
files = Arrays.copyOf(files, files.length + 1);
FTPFile bogusFile = new FTPFile();
bogusFile.setName("bogus.txt");
files[files.length - 1] = bogusFile;
return files;
}).when(session).list("ftpSource/subFtpSource/*");
String dir = "ftpSource/subFtpSource/";
try {
this.inboundMGet.send(new GenericMessage<Object>(dir + "*"));
fail("expected exception");
} catch (PartialSuccessException e) {
assertEquals(2, e.getDerivedInput().size());
assertEquals(1, e.getPartialResults().size());
assertThat(e.getCause().getMessage(), containsString("/ftpSource/subFtpSource/bogus.txt: No such file or directory."));
}
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpServerOutboundTests method testMgetRecursivePartial.
@Test
public void testMgetRecursivePartial() throws Exception {
Session<FTPFile> session = spyOnSession();
doAnswer(invocation -> {
FTPFile[] files = (FTPFile[]) invocation.callRealMethod();
// add an extra file where the get will fail
files = Arrays.copyOf(files, files.length + 1);
FTPFile bogusFile = new FTPFile();
bogusFile.setName("bogus.txt");
bogusFile.setTimestamp(Calendar.getInstance());
files[files.length - 1] = bogusFile;
return files;
}).when(session).list("ftpSource/subFtpSource/");
String dir = "ftpSource/";
try {
this.inboundMGetRecursive.send(new GenericMessage<Object>(dir + "*"));
fail("expected exception");
} catch (PartialSuccessException e) {
assertEquals(4, e.getDerivedInput().size());
assertEquals(2, e.getPartialResults().size());
assertThat(e.getCause().getMessage(), containsString("/ftpSource/subFtpSource/bogus.txt: No such file or directory."));
}
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpServerOutboundTests method testRawGETWithTemplate.
@Test
public void testRawGETWithTemplate() throws Exception {
RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<FTPFile>(this.ftpSessionFactory);
template.setFileNameExpression(new SpelExpressionParser().parseExpression("payload"));
template.setBeanFactory(mock(BeanFactory.class));
template.afterPropertiesSet();
final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
assertTrue(template.get(new GenericMessage<String>("ftpSource/ ftpSource1.txt"), (InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos1)));
assertEquals("source1", new String(baos1.toByteArray()));
final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
assertTrue(template.get(new GenericMessage<String>("ftpSource/ftpSource2.txt"), (InputStreamCallback) stream -> FileCopyUtils.copy(stream, baos2)));
assertEquals("source2", new String(baos2.toByteArray()));
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpServerOutboundTests method testMGETOnNullDir.
@Test
@SuppressWarnings("unchecked")
public void testMGETOnNullDir() throws IOException {
Session<FTPFile> session = ftpSessionFactory.getSession();
((FTPClient) session.getClientInstance()).changeWorkingDirectory("ftpSource");
session.close();
this.inboundMGet.send(new GenericMessage<Object>(""));
Message<?> result = this.output.receive(1000);
assertNotNull(result);
List<File> localFiles = (List<File>) result.getPayload();
assertThat(localFiles.size(), Matchers.greaterThan(0));
for (File file : localFiles) {
assertThat(file.getName(), isOneOf(" localTarget1.txt", "localTarget2.txt"));
assertThat(file.getName(), not(containsString("null")));
}
}
use of org.apache.commons.net.ftp.FTPFile in project spring-integration by spring-projects.
the class FtpServerOutboundTests method testLsForNullDir.
@Test
@SuppressWarnings("unchecked")
public void testLsForNullDir() throws IOException {
Session<FTPFile> session = ftpSessionFactory.getSession();
((FTPClient) session.getClientInstance()).changeWorkingDirectory("ftpSource");
session.close();
this.inboundLs.send(new GenericMessage<String>("foo"));
Message<?> receive = this.output.receive(10000);
assertNotNull(receive);
assertThat(receive.getPayload(), instanceOf(List.class));
List<String> files = (List<String>) receive.getPayload();
assertEquals(2, files.size());
assertThat(files, containsInAnyOrder(" ftpSource1.txt", "ftpSource2.txt"));
FTPFile[] ftpFiles = ftpSessionFactory.getSession().list(null);
for (FTPFile ftpFile : ftpFiles) {
if (!ftpFile.isDirectory()) {
assertTrue(files.contains(ftpFile.getName()));
}
}
}
Aggregations