|
54 | 54 | import java.util.Collections;
|
55 | 55 | import java.util.List;
|
56 | 56 | import java.util.Map;
|
| 57 | +import java.util.function.BiConsumer; |
57 | 58 | import java.util.function.Consumer;
|
58 | 59 | import java.util.function.Function;
|
59 | 60 | import java.util.function.Supplier;
|
@@ -163,6 +164,51 @@ void testConsumerBinding() {
|
163 | 164 | assertThat(componentsService.getMessages()).contains(Map.entry(String.class.getName(), message));
|
164 | 165 | }
|
165 | 166 |
|
| 167 | + @Test |
| 168 | + void testBiConsumerBinding() { |
| 169 | + // Given a binding "spring.cloud.stream.bindings.testBiConsumer-in-0.destination=test-consumer-input-topic" |
| 170 | + BindingProperties testBiConsumerInBinding = new BindingProperties(); |
| 171 | + String topicName = "test-biconsumer-input-topic"; |
| 172 | + testBiConsumerInBinding.setDestination(topicName); |
| 173 | + when(bindingServiceProperties.getBindings()).thenReturn(Map.of("testBiConsumer-in-0", testBiConsumerInBinding)); |
| 174 | + |
| 175 | + // When scan is called |
| 176 | + Map<String, ChannelObject> actualChannels = channelsScanner.scan(); |
| 177 | + Map<String, Operation> actualOperations = operationsScanner.scan(); |
| 178 | + |
| 179 | + // Then the returned channels contain a ChannelItem with the correct data |
| 180 | + MessageObject message = MessageObject.builder() |
| 181 | + .name(String.class.getName()) |
| 182 | + .title("string") |
| 183 | + .payload(MessagePayload.of(MultiFormatSchema.builder() |
| 184 | + .schema(SchemaObject.builder().type(SchemaType.STRING).build()) |
| 185 | + .build())) |
| 186 | + .headers(MessageHeaders.of( |
| 187 | + MessageReference.toSchema(AsyncHeadersNotDocumented.NOT_DOCUMENTED.getTitle()))) |
| 188 | + .bindings(Map.of("kafka", new EmptyMessageBinding())) |
| 189 | + .build(); |
| 190 | + |
| 191 | + ChannelObject expectedChannel = ChannelObject.builder() |
| 192 | + .channelId(topicName) |
| 193 | + .address(topicName) |
| 194 | + .bindings(channelBinding) |
| 195 | + .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) |
| 196 | + .build(); |
| 197 | + |
| 198 | + Operation expectedOperation = Operation.builder() |
| 199 | + .action(OperationAction.RECEIVE) |
| 200 | + .bindings(operationBinding) |
| 201 | + .description("Auto-generated description") |
| 202 | + .channel(ChannelReference.fromChannel(topicName)) |
| 203 | + .messages(List.of(MessageReference.toChannelMessage(topicName, message))) |
| 204 | + .build(); |
| 205 | + |
| 206 | + assertThat(actualChannels).containsExactly(Map.entry(topicName, expectedChannel)); |
| 207 | + assertThat(actualOperations) |
| 208 | + .containsExactly(Map.entry("test-biconsumer-input-topic_publish_testBiConsumer", expectedOperation)); |
| 209 | + assertThat(componentsService.getMessages()).contains(Map.entry(String.class.getName(), message)); |
| 210 | + } |
| 211 | + |
166 | 212 | @Test
|
167 | 213 | void testSupplierBinding() {
|
168 | 214 | // Given a binding "spring.cloud.stream.bindings.testSupplier-out-0.destination=test-supplier-output-topic"
|
@@ -488,5 +534,10 @@ public Function<String, Integer> testFunction() {
|
488 | 534 | public Function<KStream<Void, String>, KStream<Void, Integer>> kStreamTestFunction() {
|
489 | 535 | return stream -> stream.mapValues(s -> 1);
|
490 | 536 | }
|
| 537 | + |
| 538 | + @Bean |
| 539 | + public BiConsumer<String, Map<String, Object>> testBiConsumer() { |
| 540 | + return (value, header) -> System.out.println(value); |
| 541 | + } |
491 | 542 | }
|
492 | 543 | }
|
0 commit comments