counter: 1.2.15 - Removed logging of type-headers in tests
[demos/kafka/wordcount] / src / test / java / de / juplo / kafka / wordcount / counter / TestData.java
1 package de.juplo.kafka.wordcount.counter;
2
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;
9
10 import java.util.stream.Stream;
11
12 import static org.assertj.core.api.Assertions.assertThat;
13
14
15 class TestData
16 {
17         private static final TestInputWord[] INPUT_MESSAGES = new TestInputWord[]
18         {
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"),
30         };
31
32         static Stream<TestInputWord> getInputMessages()
33         {
34                 return Stream.of(TestData.INPUT_MESSAGES);
35         }
36
37         static void assertExpectedMessages(MultiValueMap<TestOutputWord, TestOutputWordCounter> receivedMessages)
38         {
39                 expectedMessages().forEach(
40                                 (word, counter) ->
41                                                 assertThat(receivedMessages.get(word))
42                                                                 .containsExactlyElementsOf(counter));
43         }
44
45         private static final KeyValue<TestOutputWord, TestOutputWordCounter>[] EXPECTED_MESSAGES = new KeyValue[]
46         {
47                         KeyValue.pair(
48                                         TestOutputWord.of("peter","Hallo"),
49                                         TestOutputWordCounter.of("peter","Hallo",1)),
50                         KeyValue.pair(
51                                         TestOutputWord.of("klaus","Müsch"),
52                                         TestOutputWordCounter.of("klaus","Müsch",1)),
53                         KeyValue.pair(
54                                         TestOutputWord.of("peter","Welt"),
55                                         TestOutputWordCounter.of("peter","Welt",1)),
56                         KeyValue.pair(
57                                         TestOutputWord.of("klaus","Müsch"),
58                                         TestOutputWordCounter.of("klaus","Müsch",2)),
59                         KeyValue.pair(
60                                         TestOutputWord.of("klaus","s"),
61                                         TestOutputWordCounter.of("klaus","s",1)),
62                         KeyValue.pair(
63                                         TestOutputWord.of("peter","Boäh"),
64                                         TestOutputWordCounter.of("peter","Boäh",1)),
65                         KeyValue.pair(
66                                         TestOutputWord.of("peter","Welt"),
67                                         TestOutputWordCounter.of("peter","Welt",2)),
68                         KeyValue.pair(
69                                         TestOutputWord.of("peter","Boäh"),
70                                         TestOutputWordCounter.of("peter","Boäh",2)),
71                         KeyValue.pair(
72                                         TestOutputWord.of("klaus","s"),
73                                         TestOutputWordCounter.of("klaus","s",2)),
74                         KeyValue.pair(
75                                         TestOutputWord.of("peter","Boäh"),
76                                         TestOutputWordCounter.of("peter","Boäh",3)),
77                         KeyValue.pair(
78                                         TestOutputWord.of("klaus","s"),
79                                         TestOutputWordCounter.of("klaus","s",3)),
80         };
81
82         static MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages()
83         {
84                 MultiValueMap<TestOutputWord, TestOutputWordCounter> expectedMessages = new LinkedMultiValueMap<>();
85                 Stream
86                                 .of(EXPECTED_MESSAGES)
87                                 .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
88                 return expectedMessages;
89         }
90 }