use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.
the class ManualFlowTests method testWrongLifecycle.
@Test
public void testWrongLifecycle() {
class MyIntegrationFlow implements IntegrationFlow {
@Override
public void configure(IntegrationFlowDefinition<?> flow) {
flow.bridge();
}
}
IntegrationFlow testFlow = new MyIntegrationFlow();
// This is fine because we are not going to start it automatically.
assertNotNull(this.integrationFlowContext.registration(testFlow).autoStartup(false).register());
try {
this.integrationFlowContext.registration(testFlow).register();
fail("IllegalStateException expected");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("Consider to implement it for [" + testFlow + "]."));
}
try {
this.integrationFlowContext.remove("foo");
fail("IllegalStateException expected");
} catch (Exception e) {
assertThat(e, instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("But [" + "foo" + "] ins't one of them."));
}
}
use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.
the class ManualFlowTests method testWithAnonymousMessageProducerStart.
@Test
public void testWithAnonymousMessageProducerStart() {
final AtomicBoolean started = new AtomicBoolean();
MessageProducerSupport producer = new MessageProducerSupport() {
@Override
protected void doStart() {
started.set(true);
super.doStart();
}
};
QueueChannel channel = new QueueChannel();
IntegrationFlow flow = IntegrationFlows.from(producer).channel(channel).get();
this.integrationFlowContext.registration(flow).register();
assertTrue(started.get());
}
use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.
the class ManualFlowTests method testDynaSubFlowCreation.
@Test
public void testDynaSubFlowCreation() {
Flux<Message<?>> messageFlux = Flux.just("1,2,3,4").map(v -> v.split(",")).flatMapIterable(Arrays::asList).map(Integer::parseInt).map(GenericMessage::new);
QueueChannel resultChannel = new QueueChannel();
IntegrationFlow integrationFlow = IntegrationFlows.from(messageFlux).<Integer, Boolean>route(p -> p % 2 == 0, m -> m.subFlowMapping(true, sf -> sf.<Integer, String>transform(em -> "even:" + em)).subFlowMapping(false, sf -> sf.<Integer, String>transform(em -> "odd:" + em)).defaultOutputToParentFlow()).channel(resultChannel).get();
this.integrationFlowContext.registration(integrationFlow).register();
for (int i = 0; i < 4; i++) {
Message<?> receive = resultChannel.receive(10_000);
assertNotNull(receive);
}
assertNull(resultChannel.receive(0));
}
use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.
the class SftpTests method testSftpMgetFlow.
@Test
@SuppressWarnings("unchecked")
public void testSftpMgetFlow() {
QueueChannel out = new QueueChannel();
IntegrationFlow flow = f -> f.handle(Sftp.outboundGateway(sessionFactory(), AbstractRemoteFileOutboundGateway.Command.MGET, "payload").options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE).regexFileNameFilter("(subSftpSource|.*1.txt)").localDirectoryExpression("'" + getTargetLocalDirectoryName() + "' + #remoteDirectory").localFilenameExpression("#remoteFileName.replaceFirst('sftpSource', 'localTarget')")).channel(out);
String dir = "sftpSource/";
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
registration.getInputChannel().send(new GenericMessage<>(dir + "*"));
Message<?> result = out.receive(10_000);
assertNotNull(result);
List<File> localFiles = (List<File>) result.getPayload();
// should have filtered sftpSource2.txt
assertEquals(2, localFiles.size());
for (File file : localFiles) {
assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir));
}
assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir + "subSftpSource"));
registration.destroy();
}
use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.
the class SftpTests method testSftpSessionCallback.
@Test
public void testSftpSessionCallback() {
QueueChannel out = new QueueChannel();
IntegrationFlow flow = f -> f.<String>handle((p, h) -> new SftpRemoteFileTemplate(sessionFactory()).execute(s -> s.list(p))).channel(out);
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
registration.getInputChannel().send(new GenericMessage<>("sftpSource"));
Message<?> receive = out.receive(10_000);
assertNotNull(receive);
Object payload = receive.getPayload();
assertThat(payload, instanceOf(ChannelSftp.LsEntry[].class));
assertTrue(((ChannelSftp.LsEntry[]) payload).length > 0);
registration.destroy();
}
Aggregations