1 package de.juplo.kafka.wordcount.counter;
3 import de.juplo.kafka.wordcount.splitter.TestInputWord;
4 import de.juplo.kafka.wordcount.top10.TestOutputWord;
5 import de.juplo.kafka.wordcount.top10.TestOutputWordCounter;
6 import org.apache.kafka.streams.KeyValue;
7 import org.springframework.util.LinkedMultiValueMap;
8 import org.springframework.util.MultiValueMap;
10 import java.util.stream.Stream;
12 import static org.assertj.core.api.Assertions.assertThat;
17 static final String PETER = "peter";
18 static final String KLAUS = "klaus";
20 private static final KeyValue<String, TestInputWord>[] INPUT_MESSAGES = new KeyValue[]
24 TestInputWord.of(PETER, "Hallo")),
27 TestInputWord.of(KLAUS, "Müsch")),
30 TestInputWord.of(PETER, "Welt")),
33 TestInputWord.of(KLAUS, "Müsch")),
36 TestInputWord.of(KLAUS, "s")),
39 TestInputWord.of(PETER, "Boäh")),
42 TestInputWord.of(PETER, "Welt")),
45 TestInputWord.of(PETER, "Boäh")),
48 TestInputWord.of(KLAUS, "s")),
51 TestInputWord.of(PETER, "Boäh")),
54 TestInputWord.of(KLAUS, "s")),
57 static Stream<KeyValue<String, TestInputWord>> getInputMessages()
59 return Stream.of(TestData.INPUT_MESSAGES);
62 static void assertExpectedMessages(MultiValueMap<TestOutputWord, TestOutputWordCounter> receivedMessages)
64 expectedMessages().forEach(
66 assertThat(receivedMessages.get(word))
67 .containsExactlyElementsOf(counter));
70 private static final KeyValue<TestOutputWord, TestOutputWordCounter>[] EXPECTED_MESSAGES = new KeyValue[]
73 TestOutputWord.of(PETER, "Hallo"),
74 TestOutputWordCounter.of(PETER, "Hallo",1)),
76 TestOutputWord.of(KLAUS, "Müsch"),
77 TestOutputWordCounter.of(KLAUS, "Müsch",1)),
79 TestOutputWord.of(PETER, "Welt"),
80 TestOutputWordCounter.of(PETER, "Welt",1)),
82 TestOutputWord.of(KLAUS, "Müsch"),
83 TestOutputWordCounter.of(KLAUS, "Müsch",2)),
85 TestOutputWord.of(KLAUS, "s"),
86 TestOutputWordCounter.of(KLAUS, "s",1)),
88 TestOutputWord.of(PETER, "Boäh"),
89 TestOutputWordCounter.of(PETER, "Boäh",1)),
91 TestOutputWord.of(PETER, "Welt"),
92 TestOutputWordCounter.of(PETER, "Welt",2)),
94 TestOutputWord.of(PETER, "Boäh"),
95 TestOutputWordCounter.of(PETER, "Boäh",2)),
97 TestOutputWord.of(KLAUS, "s"),
98 TestOutputWordCounter.of(KLAUS, "s",2)),
100 TestOutputWord.of(PETER, "Boäh"),
101 TestOutputWordCounter.of(PETER, "Boäh",3)),
103 TestOutputWord.of(KLAUS, "s"),
104 TestOutputWordCounter.of(KLAUS, "s",3)),
107 static MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages()
109 MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages = new LinkedMultiValueMap<>();
111 .of(EXPECTED_MESSAGES)
112 .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
113 return expectedMessages;