.get(); IntegrationFlowContext integrationFlowContext = this.beanFactory.getBean(IntegrationFlowContext.class); integrationFlowContext.registration(standardIntegrationFlow) .autoStartup(false) .register();
.get(); IntegrationFlowContext integrationFlowContext = this.beanFactory.getBean(IntegrationFlowContext.class); integrationFlowContext.registration(standardIntegrationFlow) .autoStartup(false) .register();
@Test public void testIncludesDynamic() { Graph graph = this.server.getGraph(); assertThat(graph.getNodes().size()).isEqualTo(32); IntegrationFlow flow = f -> f.handle(m -> { }); IntegrationFlowRegistration reg = this.flowContext.registration(flow).register(); graph = this.server.rebuild(); assertThat(graph.getNodes().size()).isEqualTo(34); this.flowContext.remove(reg.getId()); graph = this.server.rebuild(); assertThat(graph.getNodes().size()).isEqualTo(32); }
@Test public void testConcurrentRegistration() throws InterruptedException { ExecutorService executorService = Executors.newCachedThreadPool(); List<IntegrationFlowRegistration> flowRegistrations = new CopyOnWriteArrayList<>(); AtomicBoolean exceptionHappened = new AtomicBoolean(); for (int i = 0; i < 100; i++) { int index = i; executorService.execute(() -> { IntegrationFlow flow = f -> f .transform(m -> m); try { IntegrationFlowContext.IntegrationFlowRegistrationBuilder registration = this.integrationFlowContext.registration(flow); if (index % 2 == 0) { registration.id("concurrentFlow#" + index); } flowRegistrations.add(registration.register()); } catch (Exception e) { exceptionHappened.set(true); } }); } executorService.shutdownNow(); assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS)); assertFalse(exceptionHappened.get()); flowRegistrations.forEach(IntegrationFlowRegistration::destroy); }
@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 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(); }
@Test public void testDisabledBeansOverride() { assertThatThrownBy( () -> this.integrationFlowContext .registration(f -> f.channel(c -> c.direct("doNotOverrideChannel"))) .register()) .isExactlyInstanceOf(BeanCreationException.class) .hasCauseExactlyInstanceOf(BeanDefinitionOverrideException.class) .hasMessageContaining("Invalid bean definition with name 'doNotOverrideChannel'"); }
@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 testFromPublisher() { 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, Integer>transform(p -> p * 2) .channel(resultChannel) .get(); this.integrationFlowContext.registration(integrationFlow) .register(); for (int i = 0; i < 4; i++) { Message<?> receive = resultChannel.receive(10000); assertNotNull(receive); assertEquals((i + 1) * 2, receive.getPayload()); } }
@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(); }
@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 testDynamicSubFlow() { PollableChannel resultChannel = new QueueChannel(); this.integrationFlowContext.registration(flow -> flow.publishSubscribeChannel(p -> p .minSubscribers(1) .subscribe(f -> f.channel(resultChannel)) )) .id("dynamicFlow") .register(); this.integrationFlowContext.messagingTemplateFor("dynamicFlow").send(new GenericMessage<>("test")); Message<?> receive = resultChannel.receive(1000); assertNotNull(receive); assertEquals("test", receive.getPayload()); MessageHistory messageHistory = MessageHistory.read(receive); assertNotNull(messageHistory); String messageHistoryString = messageHistory.toString(); assertThat(messageHistoryString, Matchers.containsString("dynamicFlow.input")); assertThat(messageHistoryString, Matchers.containsString("dynamicFlow.subFlow#0.channel#1")); this.integrationFlowContext.remove("dynamicFlow"); }
.registration(flow -> flow .bridge(e -> e.role(testRole)) .channel(resultChannel))
.channel(channel) .get(); IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow).register(); assertTrue(started.get());
this.integrationFlowContext.registration( flow -> flow .handle(new MessageProducingHandler())
@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(); }
this.integrationFlowContext.registration(myFlow) .id(flowId) .useFlowIdAsPrefix()
@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 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()); }