1 package de.juplo.kafka.wordcount.splitter;
3 import de.juplo.kafka.wordcount.counter.TestWord;
4 import de.juplo.kafka.wordcount.recorder.TestRecording;
5 import org.apache.kafka.streams.KeyValue;
6 import org.springframework.util.LinkedMultiValueMap;
7 import org.springframework.util.MultiValueMap;
9 import java.time.Duration;
10 import java.util.function.BiConsumer;
11 import java.util.stream.Stream;
13 import static org.assertj.core.api.Assertions.assertThat;
14 import static org.awaitility.Awaitility.await;
19 static final String PETER = "peter";
20 static final String KLAUS = "klaus";
22 static void writeInputData(BiConsumer<String, TestRecording> consumer)
26 .forEach(kv -> consumer.accept(kv.key, kv.value));
29 static final KeyValue<String, TestRecording>[] INPUT_MESSAGES = new KeyValue[]
33 TestRecording.of(PETER, "Hallo Welt!")),
36 TestRecording.of(KLAUS, "Müsch gäb's auch!")),
39 TestRecording.of(PETER, "Boäh, echt! ß mal nä Nümmäh!")),
42 static void assertExpectedMessages(MultiValueMap<String, TestWord> receivedMessages)
44 MultiValueMap<String, TestWord> expected = new LinkedMultiValueMap<>();
45 expectedMessages.forEach(keyValue -> expected.add(keyValue.key, keyValue.value));
46 await("Received expected messages")
47 .atMost(Duration.ofSeconds(5))
48 .untilAsserted(() -> expected.forEach((user, word) ->
49 assertThat(receivedMessages.get(user)).containsExactlyElementsOf(word)));
52 static Stream<KeyValue<String, TestWord>> expectedMessages = Stream.of(
55 TestWord.of("peter", "Hallo")),
58 TestWord.of("peter", "Welt")),
61 TestWord.of("klaus", "Müsch")),
64 TestWord.of("klaus", "gäb")),
67 TestWord.of("klaus", "s")),
70 TestWord.of("klaus", "auch")),
73 TestWord.of("peter", "Boäh")),
76 TestWord.of("peter", "echt")),
79 TestWord.of("peter", "ß")),
82 TestWord.of("peter", "mal")),
85 TestWord.of("peter", "nä")),
88 TestWord.of("peter", "Nümmäh")));