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 private static final TestInputWord[] INPUT_MESSAGES = new TestInputWord[]
19 TestInputWord.of("peter","Hallo"),
20 TestInputWord.of("klaus","Müsch"),
21 TestInputWord.of("peter","Welt"),
22 TestInputWord.of("klaus","Müsch"),
23 TestInputWord.of("klaus","s"),
24 TestInputWord.of("peter","Boäh"),
25 TestInputWord.of("peter","Welt"),
26 TestInputWord.of("peter","Boäh"),
27 TestInputWord.of("klaus","s"),
28 TestInputWord.of("peter","Boäh"),
29 TestInputWord.of("klaus","s"),
32 static Stream<TestInputWord> getInputMessages()
34 return Stream.of(TestData.INPUT_MESSAGES);
37 static void assertExpectedMessages(MultiValueMap<TestOutputWord, TestOutputWordCounter> receivedMessages)
39 expectedMessages().forEach(
41 assertThat(receivedMessages.get(word))
42 .containsExactlyElementsOf(counter));
45 private static final KeyValue<TestOutputWord, TestOutputWordCounter>[] EXPECTED_MESSAGES = new KeyValue[]
48 TestOutputWord.of("peter","Hallo"),
49 TestOutputWordCounter.of("peter","Hallo",1)),
51 TestOutputWord.of("klaus","Müsch"),
52 TestOutputWordCounter.of("klaus","Müsch",1)),
54 TestOutputWord.of("peter","Welt"),
55 TestOutputWordCounter.of("peter","Welt",1)),
57 TestOutputWord.of("klaus","Müsch"),
58 TestOutputWordCounter.of("klaus","Müsch",2)),
60 TestOutputWord.of("klaus","s"),
61 TestOutputWordCounter.of("klaus","s",1)),
63 TestOutputWord.of("peter","Boäh"),
64 TestOutputWordCounter.of("peter","Boäh",1)),
66 TestOutputWord.of("peter","Welt"),
67 TestOutputWordCounter.of("peter","Welt",2)),
69 TestOutputWord.of("peter","Boäh"),
70 TestOutputWordCounter.of("peter","Boäh",2)),
72 TestOutputWord.of("klaus","s"),
73 TestOutputWordCounter.of("klaus","s",2)),
75 TestOutputWord.of("peter","Boäh"),
76 TestOutputWordCounter.of("peter","Boäh",3)),
78 TestOutputWord.of("klaus","s"),
79 TestOutputWordCounter.of("klaus","s",3)),
82 static MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages()
84 MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages = new LinkedMultiValueMap<>();
86 .of(EXPECTED_MESSAGES)
87 .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
88 return expectedMessages;