use of org.springframework.integration.ftp.session.FtpRemoteFileTemplate in project spring-integration by spring-projects.
the class FtpTests method testFtpInboundStreamFlow.
@Test
public void testFtpInboundStreamFlow() throws Exception {
QueueChannel out = new QueueChannel();
StandardIntegrationFlow flow = IntegrationFlows.from(Ftp.inboundStreamingAdapter(new FtpRemoteFileTemplate(sessionFactory())).remoteDirectory("ftpSource").maxFetchSize(11).regexFilter(".*\\.txt$"), e -> e.id("ftpInboundAdapter").poller(Pollers.fixedDelay(100))).channel(out).get();
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
Message<?> message = out.receive(10_000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(InputStream.class));
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" ftpSource1.txt", "ftpSource2.txt"));
new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
message = out.receive(10_000);
assertNotNull(message);
assertThat(message.getPayload(), instanceOf(InputStream.class));
assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" ftpSource1.txt", "ftpSource2.txt"));
new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
MessageSource<?> source = context.getBean(FtpStreamingMessageSource.class);
assertThat(TestUtils.getPropertyValue(source, "maxFetchSize"), equalTo(11));
registration.destroy();
}
use of org.springframework.integration.ftp.session.FtpRemoteFileTemplate in project spring-integration by spring-projects.
the class FtpServerOutboundTests method testInt3412FileMode.
@Test
public void testInt3412FileMode() {
FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(ftpSessionFactory);
assertFalse(template.exists("ftpTarget/appending.txt"));
Message<String> m = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "appending.txt").build();
appending.send(m);
appending.send(m);
assertLength6(template);
ignoring.send(m);
assertLength6(template);
try {
failing.send(m);
fail("Expected exception");
} catch (MessagingException e) {
assertThat(e.getCause().getCause().getMessage(), containsString("The destination file already exists"));
}
}
Aggregations