|
20 | 20 | import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
21 | 21 |
|
22 | 22 | import java.lang.reflect.Method;
|
| 23 | +import java.util.Map; |
| 24 | +import java.util.Objects; |
23 | 25 | import java.util.function.Function;
|
24 | 26 |
|
25 | 27 | import org.junit.jupiter.api.Test;
|
|
35 | 37 | import org.springframework.integration.dsl.IntegrationFlow;
|
36 | 38 | import org.springframework.integration.dsl.IntegrationFlows;
|
37 | 39 | import org.springframework.integration.dsl.MessageChannels;
|
| 40 | +import org.springframework.integration.gateway.GatewayProxyFactoryBean; |
| 41 | +import org.springframework.integration.gateway.MessagingGatewaySupport; |
38 | 42 | import org.springframework.integration.gateway.MethodArgsHolder;
|
39 | 43 | import org.springframework.integration.support.MessageBuilder;
|
40 | 44 | import org.springframework.messaging.Message;
|
@@ -102,18 +106,28 @@ void testNestedGatewayErrorPropagation() {
|
102 | 106 | }
|
103 | 107 |
|
104 | 108 | @Autowired
|
105 |
| - private Function<Object, Message<?>> functionGateay; |
| 109 | + private MessageFunction functionGateway; |
| 110 | + |
| 111 | + @Autowired |
| 112 | + @Qualifier("&functionGateway.gateway") |
| 113 | + private GatewayProxyFactoryBean functionGatewayFactoryBean; |
106 | 114 |
|
107 | 115 | @Test
|
108 | 116 | void testHeadersFromFunctionGateway() {
|
109 |
| - Object payload = this.functionGateay |
| 117 | + Object payload = this.functionGateway |
110 | 118 | .andThen(message -> {
|
111 | 119 | assertThat(message.getHeaders()).containsKeys("gatewayMethod", "gatewayArgs");
|
112 | 120 | return message.getPayload();
|
113 | 121 | })
|
114 | 122 | .apply("testPayload");
|
115 | 123 |
|
116 | 124 | assertThat(payload).isEqualTo("testPayload");
|
| 125 | + |
| 126 | + Map<Method, MessagingGatewaySupport> gateways = this.functionGatewayFactoryBean.getGateways(); |
| 127 | + assertThat(gateways).hasSize(1); |
| 128 | + |
| 129 | + Method method = gateways.keySet().iterator().next(); |
| 130 | + assertThat(method.getName()).isEqualTo("apply"); |
117 | 131 | }
|
118 | 132 |
|
119 | 133 | @Autowired
|
@@ -188,7 +202,23 @@ public IntegrationFlow routingGateway() {
|
188 | 202 |
|
189 | 203 | }
|
190 | 204 |
|
191 |
| - interface MessageFunction extends Function<Object, Message<?>> { |
| 205 | + interface MessageFunction { |
| 206 | + |
| 207 | + Message<?> apply(Object t); |
| 208 | + |
| 209 | + default <V> Function<V, Message<?>> compose(Function<? super V, Object> before) { |
| 210 | + Objects.requireNonNull(before); |
| 211 | + return (v) -> apply(before.apply(v)); |
| 212 | + } |
| 213 | + |
| 214 | + default <V> Function<Object, V> andThen(Function<? super Message<?>, ? extends V> after) { |
| 215 | + Objects.requireNonNull(after); |
| 216 | + return (t) -> after.apply(apply(t)); |
| 217 | + } |
| 218 | + |
| 219 | + static <T> Function<T, T> identity() { |
| 220 | + return t -> t; |
| 221 | + } |
192 | 222 |
|
193 | 223 | }
|
194 | 224 |
|
|
0 commit comments