|
17 | 17 | package org.springframework.cloud.stream.function; |
18 | 18 |
|
19 | 19 | import java.util.function.Function; |
| 20 | +import java.util.function.Supplier; |
20 | 21 |
|
21 | 22 | import org.junit.jupiter.api.Test; |
22 | 23 |
|
|
29 | 30 | import org.springframework.cloud.stream.binder.test.TestChannelBinderConfiguration; |
30 | 31 | import org.springframework.context.ConfigurableApplicationContext; |
31 | 32 | import org.springframework.context.annotation.Bean; |
| 33 | +import org.springframework.context.annotation.Configuration; |
32 | 34 | import org.springframework.integration.support.MessageBuilder; |
33 | 35 | import org.springframework.messaging.Message; |
| 36 | +import org.springframework.messaging.support.GenericMessage; |
34 | 37 |
|
35 | 38 | import static org.assertj.core.api.Assertions.assertThat; |
36 | 39 |
|
@@ -76,6 +79,22 @@ void successfulPostProcessingOfSingleFunction() { |
76 | 79 | } |
77 | 80 | } |
78 | 81 |
|
| 82 | + @Test |
| 83 | + void successfulPostProcessingOfSupplierFunctionCompposition() throws Exception { |
| 84 | + System.clearProperty("spring.cloud.function.definition"); |
| 85 | + try (ConfigurableApplicationContext context = new SpringApplicationBuilder( |
| 86 | + TestChannelBinderConfiguration.getCompleteConfiguration(SupplierPostProcessingTestConfiguration.class)) |
| 87 | + .web(WebApplicationType.NONE).run("--spring.jmx.enabled=false", |
| 88 | + "--spring.cloud.function.definition=hello|uppercase", |
| 89 | + "--spring.cloud.stream.bindings.hellouppercase-out-0.producer.poller.fixed-delay=100")) { |
| 90 | + Thread.sleep(1000); |
| 91 | + OutputDestination outputDestination = context.getBean(OutputDestination.class); |
| 92 | + |
| 93 | + assertThat(outputDestination.receive(5000, "hellouppercase-out-0").getPayload()).isEqualTo("HELLO".getBytes()); |
| 94 | + assertThat(context.getBean(SupplierPostProcessingTestConfiguration.class).postProcessed).isTrue(); |
| 95 | + } |
| 96 | + } |
| 97 | + |
79 | 98 | @Test |
80 | 99 | void noPostProcessingOnError() { |
81 | 100 | System.clearProperty("spring.cloud.function.definition"); |
@@ -207,6 +226,31 @@ public Function<String, String> reverse() { |
207 | 226 | } |
208 | 227 | } |
209 | 228 |
|
| 229 | + @EnableAutoConfiguration |
| 230 | + @Configuration |
| 231 | + public static class SupplierPostProcessingTestConfiguration { |
| 232 | + |
| 233 | + public static boolean postProcessed; |
| 234 | + |
| 235 | + @Bean |
| 236 | + public Supplier<Message<String>> hello() { |
| 237 | + return () -> new GenericMessage<>("hello"); |
| 238 | + } |
| 239 | + |
| 240 | + @Bean |
| 241 | + public Function<String, String> uppercase() { |
| 242 | + return new PostProcessingFunction<String, String>() { |
| 243 | + public String apply(String input) { |
| 244 | + return input.toUpperCase(); |
| 245 | + } |
| 246 | + |
| 247 | + public void postProcess(Message<String> result) { |
| 248 | + postProcessed = true; |
| 249 | + } |
| 250 | + }; |
| 251 | + } |
| 252 | + } |
| 253 | + |
210 | 254 | private static class SingleFunctionPostProcessingFunction implements PostProcessingFunction<String, String> { |
211 | 255 |
|
212 | 256 | private boolean success; |
|
0 commit comments