Search in sources :

Example 16 with IntegrationFlow

use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.

the class SftpTests method testSftpOutboundFlow.

@Test
public void testSftpOutboundFlow() {
    IntegrationFlow flow = f -> f.handle(Sftp.outboundAdapter(sessionFactory(), FileExistsMode.FAIL).useTemporaryFileName(false).fileNameExpression("headers['" + FileHeaders.FILENAME + "']").remoteDirectory("sftpTarget"));
    IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
    String fileName = "foo.file";
    registration.getInputChannel().send(MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, fileName).build());
    RemoteFileTemplate<ChannelSftp.LsEntry> template = new RemoteFileTemplate<>(sessionFactory());
    ChannelSftp.LsEntry[] files = template.execute(session -> session.list(getTargetRemoteDirectory().getName() + "/" + fileName));
    assertEquals(1, files.length);
    assertEquals(3, files[0].getAttrs().getSize());
    registration.destroy();
}
Also used : DirtiesContext(org.springframework.test.annotation.DirtiesContext) QueueChannel(org.springframework.integration.channel.QueueChannel) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) RunWith(org.junit.runner.RunWith) FileHeaders(org.springframework.integration.file.FileHeaders) Autowired(org.springframework.beans.factory.annotation.Autowired) IntegrationFlowContext(org.springframework.integration.dsl.context.IntegrationFlowContext) FileExistsMode(org.springframework.integration.file.support.FileExistsMode) Assert.assertThat(org.junit.Assert.assertThat) MessageBuilder(org.springframework.integration.support.MessageBuilder) Matcher(java.util.regex.Matcher) Pollers(org.springframework.integration.dsl.Pollers) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) IntegrationFlows(org.springframework.integration.dsl.IntegrationFlows) Message(org.springframework.messaging.Message) SpringRunner(org.springframework.test.context.junit4.SpringRunner) RemoteFileTemplate(org.springframework.integration.file.remote.RemoteFileTemplate) SftpRemoteFileTemplate(org.springframework.integration.sftp.session.SftpRemoteFileTemplate) ChannelSftp(com.jcraft.jsch.ChannelSftp) Matchers.isOneOf(org.hamcrest.Matchers.isOneOf) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Matchers(org.hamcrest.Matchers) AbstractRemoteFileOutboundGateway(org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway) Test(org.junit.Test) EnableIntegration(org.springframework.integration.config.EnableIntegration) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) File(java.io.File) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Configuration(org.springframework.context.annotation.Configuration) List(java.util.List) SftpTestSupport(org.springframework.integration.sftp.SftpTestSupport) GenericMessage(org.springframework.messaging.support.GenericMessage) Matchers.containsString(org.hamcrest.Matchers.containsString) Assert.assertEquals(org.junit.Assert.assertEquals) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) InputStream(java.io.InputStream) RemoteFileTemplate(org.springframework.integration.file.remote.RemoteFileTemplate) SftpRemoteFileTemplate(org.springframework.integration.sftp.session.SftpRemoteFileTemplate) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 17 with IntegrationFlow

use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.

the class SftpTests method testSftpInboundFlow.

@Test
public void testSftpInboundFlow() {
    QueueChannel out = new QueueChannel();
    IntegrationFlow flow = IntegrationFlows.from(Sftp.inboundAdapter(sessionFactory()).preserveTimestamp(true).remoteDirectory("sftpSource").regexFilter(".*\\.txt$").localFilenameExpression("#this.toUpperCase() + '.a'").localDirectory(getTargetLocalDirectory()), e -> e.id("sftpInboundAdapter").poller(Pollers.fixedDelay(100))).channel(out).get();
    IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
    Message<?> message = out.receive(10_000);
    assertNotNull(message);
    Object payload = message.getPayload();
    assertThat(payload, instanceOf(File.class));
    File file = (File) payload;
    assertThat(file.getName(), isOneOf(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"));
    assertThat(file.getAbsolutePath(), containsString("localTarget"));
    message = out.receive(10_000);
    assertNotNull(message);
    file = (File) message.getPayload();
    assertThat(file.getName(), isOneOf(" SFTPSOURCE1.TXT.a", "SFTPSOURCE2.TXT.a"));
    assertThat(file.getAbsolutePath(), containsString("localTarget"));
    registration.destroy();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) File(java.io.File) Test(org.junit.Test)

Aggregations

IntegrationFlow (org.springframework.integration.dsl.IntegrationFlow)17 Test (org.junit.Test)14 QueueChannel (org.springframework.integration.channel.QueueChannel)13 StandardIntegrationFlow (org.springframework.integration.dsl.StandardIntegrationFlow)12 IntegrationFlowRegistration (org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration)10 Message (org.springframework.messaging.Message)9 GenericMessage (org.springframework.messaging.support.GenericMessage)9 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Assert.assertNotNull (org.junit.Assert.assertNotNull)8 Assert.assertThat (org.junit.Assert.assertThat)8 RunWith (org.junit.runner.RunWith)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Configuration (org.springframework.context.annotation.Configuration)8 EnableIntegration (org.springframework.integration.config.EnableIntegration)8 IntegrationFlows (org.springframework.integration.dsl.IntegrationFlows)8 IntegrationFlowContext (org.springframework.integration.dsl.context.IntegrationFlowContext)8 DirtiesContext (org.springframework.test.annotation.DirtiesContext)8 SpringRunner (org.springframework.test.context.junit4.SpringRunner)8 File (java.io.File)7