@Test void testRuntimeBeanRegistration(@Autowired IntegrationFlowContext context) throws Exception { Set<ObjectName> query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(2); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(0); IntegrationFlow dynamicFlow = IntegrationFlows.from(() -> "foo", e -> e.poller(p -> p.fixedDelay(1000))) .channel("channelTwo") .nullChannel(); IntegrationFlowContext.IntegrationFlowRegistration registration = context.registration(dynamicFlow) .id("dynamic") .register(); query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(4); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(1); registration.destroy(); query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(2); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(0); }
@Test public void testFluxMessageChannelCleanUp() throws InterruptedException { FluxMessageChannel flux = MessageChannels.flux().get(); CountDownLatch finishLatch = new CountDownLatch(1); IntegrationFlow testFlow = f -> f .<String>split(__ -> Flux.fromStream(IntStream.range(0, 100).boxed()), null) .channel(flux) .aggregate(a -> a.releaseStrategy(m -> m.size() == 100)) .handle(__ -> finishLatch.countDown()); IntegrationFlowContext.IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(testFlow) .register(); flowRegistration.getInputChannel().send(new GenericMessage<>("foo")); assertTrue(finishLatch.await(10, TimeUnit.SECONDS)); assertTrue(TestUtils.getPropertyValue(flux, "publishers", Map.class).isEmpty()); flowRegistration.destroy(); }
@Test public void testRegistrationDuplicationRejected() { String testId = "testId"; StandardIntegrationFlow testFlow = IntegrationFlows.from(Supplier.class) .get(); IntegrationFlowRegistration flowRegistration = 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.")); } flowRegistration.destroy(); }
startsWith(flowId + ".")); flowRegistration.destroy();
assertEquals("test2", receive.getPayload()); flowRegistration.destroy();
assertNotNull(this.integrationManagementConfigurer.getHandlerMetrics("bridge")); flowRegistration.destroy();
assertEquals("test", receive.getPayload()); flowRegistration.destroy();
@Test public void testDynamicHttpEndpoint() throws Exception { IntegrationFlow flow = IntegrationFlows.from(Http.inboundGateway("/dynamic") .requestMapping(r -> r.params("name")) .payloadExpression("#requestParams.name[0]")) .<String, String>transform(String::toLowerCase) .get(); IntegrationFlowContext.IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow).register(); this.mockMvc.perform( get("/dynamic") .with(httpBasic("admin", "admin")) .param("name", "BAR")) .andExpect( content() .string("bar")); flowRegistration.destroy(); this.mockMvc.perform( get("/dynamic") .with(httpBasic("admin", "admin")) .param("name", "BAZ")) .andExpect( status() .isNotFound()); }
@Test public void testWithAnonymousMessageProducerSpecStart() { final AtomicBoolean started = new AtomicBoolean(); class MyProducer extends MessageProducerSupport { @Override protected void doStart() { started.set(true); super.doStart(); } } class MyProducerSpec extends MessageProducerSpec<MyProducerSpec, MyProducer> { MyProducerSpec(MyProducer producer) { super(producer); } } MyProducerSpec spec = new MyProducerSpec(new MyProducer()); QueueChannel channel = new QueueChannel(); IntegrationFlow flow = IntegrationFlows.from(spec.id("fooChannel")) .channel(channel) .get(); IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow).register(); assertTrue(started.get()); flowRegistration.destroy(); }
@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(); }
@Test public void testDynamicHttpEndpoint() throws Exception { IntegrationFlow flow = IntegrationFlows.from(WebFlux.inboundGateway("/dynamic") .requestMapping(r -> r.params("name")) .payloadExpression("#requestParams.name[0]")) .<String, String>transform(String::toLowerCase) .get(); IntegrationFlowContext.IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow).register(); this.webTestClient.get().uri("/dynamic?name=BAR") .headers(headers -> headers.setBasicAuth("guest", "guest")) .exchange() .expectBody(String.class) .isEqualTo("bar"); flowRegistration.destroy(); this.webTestClient.get().uri("/dynamic?name=BAZ") .headers(headers -> headers.setBasicAuth("guest", "guest")) .exchange() .expectStatus() .isNotFound(); }
@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(); }
@Test public void testDynamicAdapterFlow() { IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(new MyFlowAdapter()).register(); PollableChannel resultChannel = this.beanFactory.getBean("flowAdapterOutput", PollableChannel.class); Message<?> receive = resultChannel.receive(1000); assertNotNull(receive); assertEquals("flowAdapterMessage", receive.getPayload()); flowRegistration.destroy(); }