use of org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration in project spring-integration by spring-projects.
the class ManualFlowTests method testRoleControl.
@Test
public void testRoleControl() {
String testRole = "bridge";
PollableChannel resultChannel = new QueueChannel();
IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow -> flow.bridge(e -> e.role(testRole)).channel(resultChannel)).register();
MessagingTemplate messagingTemplate = this.integrationFlowContext.messagingTemplateFor(flowRegistration.getId());
messagingTemplate.send(new GenericMessage<>("test"));
Message<?> receive = resultChannel.receive(1000);
assertNotNull(receive);
assertEquals("test", receive.getPayload());
this.roleController.stopLifecyclesInRole(testRole);
try {
messagingTemplate.send(new GenericMessage<>("test2"));
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getMessage(), containsString("Dispatcher has no subscribers for channel"));
}
this.roleController.startLifecyclesInRole(testRole);
messagingTemplate.send(new GenericMessage<>("test2"));
receive = resultChannel.receive(1000);
assertNotNull(receive);
assertEquals("test2", receive.getPayload());
flowRegistration.destroy();
assertTrue(this.roleController.getEndpointsRunningStatus(testRole).isEmpty());
}
use of org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration 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();
}
use of org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration in project spring-integration by spring-projects.
the class IpIntegrationTests method testTcpGateways.
@Test
public void testTcpGateways() {
TestingUtilities.waitListening(this.server1, null);
IntegrationFlow flow = f -> f.handle(Tcp.outboundGateway(Tcp.netClient("localhost", this.server1.getPort()).serializer(TcpCodecs.crlf()).deserializer(TcpCodecs.lengthHeader1()).id("client1")).remoteTimeout(m -> 5000)).transform(Transformers.objectToString());
IntegrationFlowRegistration theFlow = this.flowContext.registration(flow).register();
assertThat(theFlow.getMessagingTemplate().convertSendAndReceive("foo", String.class), equalTo("FOO"));
}
use of org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration in project spring-integration by spring-projects.
the class FtpTests method testFtpOutboundFlow.
@Test
public void testFtpOutboundFlow() {
IntegrationFlow flow = f -> f.handle(Ftp.outboundAdapter(sessionFactory(), FileExistsMode.FAIL).useTemporaryFileName(false).fileNameExpression("headers['" + FileHeaders.FILENAME + "']").remoteDirectory("ftpTarget"));
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
String fileName = "foo.file";
Message<ByteArrayInputStream> message = MessageBuilder.withPayload(new ByteArrayInputStream("foo".getBytes(StandardCharsets.UTF_8))).setHeader(FileHeaders.FILENAME, fileName).build();
registration.getInputChannel().send(message);
RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(sessionFactory());
FTPFile[] files = template.execute(session -> session.list(getTargetRemoteDirectory().getName() + "/" + fileName));
assertEquals(1, files.length);
assertEquals(3, files[0].getSize());
registration.destroy();
}
use of org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration in project spring-integration by spring-projects.
the class FtpTests method testFtpMgetFlow.
@Test
@SuppressWarnings("unchecked")
public void testFtpMgetFlow() {
QueueChannel out = new QueueChannel();
IntegrationFlow flow = f -> f.handle(Ftp.outboundGateway(sessionFactory(), AbstractRemoteFileOutboundGateway.Command.MGET, "payload").options(AbstractRemoteFileOutboundGateway.Option.RECURSIVE).fileExistsMode(FileExistsMode.IGNORE).filterExpression("name matches 'subFtpSource|.*1.txt'").localDirectoryExpression("'" + getTargetLocalDirectoryName() + "' + #remoteDirectory").localFilenameExpression("#remoteFileName.replaceFirst('ftpSource', 'localTarget')")).channel(out);
IntegrationFlowRegistration registration = this.flowContext.registration(flow).register();
String dir = "ftpSource/";
registration.getInputChannel().send(new GenericMessage<>(dir + "*"));
Message<?> result = out.receive(10_000);
assertNotNull(result);
List<File> localFiles = (List<File>) result.getPayload();
// should have filtered ftpSource2.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 + "subFtpSource"));
registration.destroy();
}
Aggregations