Search in sources :

Example 1 with StandardIntegrationFlow

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

the class ManualFlowTests method testRegistrationDuplicationRejected.

@Test
public void testRegistrationDuplicationRejected() {
    String testId = "testId";
    StandardIntegrationFlow testFlow = IntegrationFlows.from(Supplier.class).get();
    this.integrationFlowContext.registration(testFlow).id(testId).register();
    try {
        this.integrationFlowContext.registration(testFlow).id(testId).register();
    } catch (Exception e) {
        assertThat(e, instanceOf(IllegalArgumentException.class));
        assertThat(e.getMessage(), containsString("with flowId '" + testId + "' is already registered."));
    }
}
Also used : Supplier(java.util.function.Supplier) Matchers.containsString(org.hamcrest.Matchers.containsString) MessagingException(org.springframework.messaging.MessagingException) BeanCreationNotAllowedException(org.springframework.beans.factory.BeanCreationNotAllowedException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) Test(org.junit.Test)

Example 2 with StandardIntegrationFlow

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

the class MockMessageSourceTests method testMockMessageSourceDynamicFlow.

@Test
public void testMockMessageSourceDynamicFlow() {
    QueueChannel out = new QueueChannel();
    StandardIntegrationFlow flow = IntegrationFlows.from(MockIntegration.mockMessageSource("foo", "bar", "baz")).<String, String>transform(String::toUpperCase).channel(out).get();
    IntegrationFlowRegistration registration = this.integrationFlowContext.registration(flow).register();
    Message<?> receive = out.receive(10_000);
    assertNotNull(receive);
    assertEquals("FOO", receive.getPayload());
    receive = out.receive(10_000);
    assertNotNull(receive);
    assertEquals("BAR", receive.getPayload());
    for (int i = 0; i < 10; i++) {
        receive = out.receive(10_000);
        assertNotNull(receive);
        assertEquals("BAZ", receive.getPayload());
    }
    registration.destroy();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) Matchers.containsString(org.hamcrest.Matchers.containsString) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) Test(org.junit.Test) SpringIntegrationTest(org.springframework.integration.test.context.SpringIntegrationTest)

Example 3 with StandardIntegrationFlow

use of org.springframework.integration.dsl.StandardIntegrationFlow 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();
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) FtpRemoteFileTemplate(org.springframework.integration.ftp.session.FtpRemoteFileTemplate) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) Test(org.junit.Test)

Example 4 with StandardIntegrationFlow

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

the class SftpTests method testSftpInboundStreamFlow.

@Test
public void testSftpInboundStreamFlow() throws Exception {
    QueueChannel out = new QueueChannel();
    StandardIntegrationFlow flow = IntegrationFlows.from(Sftp.inboundStreamingAdapter(new SftpRemoteFileTemplate(sessionFactory())).remoteDirectory("sftpSource").regexFilter(".*\\.txt$"), 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);
    assertThat(message.getPayload(), instanceOf(InputStream.class));
    assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE), isOneOf(" sftpSource1.txt", "sftpSource2.txt"));
    ((InputStream) message.getPayload()).close();
    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(" sftpSource1.txt", "sftpSource2.txt"));
    ((InputStream) message.getPayload()).close();
    new IntegrationMessageHeaderAccessor(message).getCloseableResource().close();
    registration.destroy();
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) InputStream(java.io.InputStream) SftpRemoteFileTemplate(org.springframework.integration.sftp.session.SftpRemoteFileTemplate) IntegrationFlowRegistration(org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)4 StandardIntegrationFlow (org.springframework.integration.dsl.StandardIntegrationFlow)4 QueueChannel (org.springframework.integration.channel.QueueChannel)3 IntegrationFlowRegistration (org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration)3 InputStream (java.io.InputStream)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Supplier (java.util.function.Supplier)1 BeanCreationNotAllowedException (org.springframework.beans.factory.BeanCreationNotAllowedException)1 FtpRemoteFileTemplate (org.springframework.integration.ftp.session.FtpRemoteFileTemplate)1 SftpRemoteFileTemplate (org.springframework.integration.sftp.session.SftpRemoteFileTemplate)1 SpringIntegrationTest (org.springframework.integration.test.context.SpringIntegrationTest)1 MessageDeliveryException (org.springframework.messaging.MessageDeliveryException)1 MessagingException (org.springframework.messaging.MessagingException)1