Search in sources :

Example 11 with RemoteFileTemplate

use of org.springframework.integration.file.remote.RemoteFileTemplate 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()));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) RemoteFileTemplate(org.springframework.integration.file.remote.RemoteFileTemplate) FtpRemoteFileTemplate(org.springframework.integration.ftp.session.FtpRemoteFileTemplate) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) BeanFactory(org.springframework.beans.factory.BeanFactory) InputStreamCallback(org.springframework.integration.file.remote.InputStreamCallback) FTPFile(org.apache.commons.net.ftp.FTPFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

RemoteFileTemplate (org.springframework.integration.file.remote.RemoteFileTemplate)11 Test (org.junit.Test)10 Matchers.containsString (org.hamcrest.Matchers.containsString)9 InputStream (java.io.InputStream)7 File (java.io.File)6 BeanFactory (org.springframework.beans.factory.BeanFactory)6 IOException (java.io.IOException)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 LiteralExpression (org.springframework.expression.common.LiteralExpression)5 List (java.util.List)4 Assert.assertThat (org.junit.Assert.assertThat)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)3 Assert.assertEquals (org.junit.Assert.assertEquals)3 GenericMessage (org.springframework.messaging.support.GenericMessage)3 ChannelSftp (com.jcraft.jsch.ChannelSftp)2 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)2 FileOutputStream (java.io.FileOutputStream)2 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2