package de.juplo.kafka.wordcount.splitter;
-import de.juplo.kafka.wordcount.counter.TestWord;
-import de.juplo.kafka.wordcount.recorder.TestRecording;
+import de.juplo.kafka.wordcount.counter.TestOutputUser;
+import de.juplo.kafka.wordcount.counter.TestOutputWord;
+import de.juplo.kafka.wordcount.recorder.TestInputRecording;
+import de.juplo.kafka.wordcount.recorder.TestInputUser;
import org.apache.kafka.streams.KeyValue;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.time.Duration;
-import java.util.function.BiConsumer;
import java.util.stream.Stream;
import static org.assertj.core.api.Assertions.assertThat;
public class TestData
{
- static final String PETER = "peter";
- static final String KLAUS = "klaus";
+ static final TestInputUser PETER = TestInputUser.of("peter");
+ static final TestInputUser KLAUS = TestInputUser.of("klaus");
- static void writeInputData(BiConsumer<String, TestRecording> consumer)
+
+ static final Stream<KeyValue<TestInputUser, TestInputRecording>> getInputMessages()
{
- Stream
- .of(INPUT_MESSAGES)
- .forEach(kv -> consumer.accept(kv.key, kv.value));
+ return Stream.of(INPUT_MESSAGES);
}
- static final KeyValue<String, TestRecording>[] INPUT_MESSAGES = new KeyValue[]
+ private static final KeyValue<TestInputUser, TestInputRecording>[] INPUT_MESSAGES = new KeyValue[]
{
new KeyValue<>(
PETER,
- TestRecording.of(PETER, "Hallo Welt!")),
+ TestInputRecording.of(PETER.getUser(), "Hallo Welt!")),
new KeyValue<>(
KLAUS,
- TestRecording.of(KLAUS, "Müsch gäb's auch!")),
+ TestInputRecording.of(KLAUS.getUser(), "Müsch gäb's auch!")),
new KeyValue<>(
PETER,
- TestRecording.of(PETER, "Boäh, echt! ß mal nä Nümmäh!")),
+ TestInputRecording.of(PETER.getUser(), "Boäh, echt! ß mal nä Nümmäh!")),
};
- static void assertExpectedMessages(MultiValueMap<String, TestWord> receivedMessages)
+ static void assertExpectedMessages(MultiValueMap<TestOutputUser, TestOutputWord> receivedMessages)
{
- MultiValueMap<String, TestWord> expected = new LinkedMultiValueMap<>();
- expectedMessages.forEach(keyValue -> expected.add(keyValue.key, keyValue.value));
await("Received expected messages")
.atMost(Duration.ofSeconds(5))
- .untilAsserted(() -> expected.forEach((user, word) ->
+ .untilAsserted(() -> expectedMessages().forEach((user, word) ->
assertThat(receivedMessages.get(user)).containsExactlyElementsOf(word)));
}
- static Stream<KeyValue<String, TestWord>> expectedMessages = Stream.of(
+ private static final KeyValue<TestOutputUser, TestOutputWord>[] EXPECTED_MESSAGES = new KeyValue[]
+ {
KeyValue.pair(
- "peter",
- TestWord.of("peter", "Hallo")),
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "Hallo")),
KeyValue.pair(
- "peter",
- TestWord.of("peter", "Welt")),
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "Welt")),
KeyValue.pair(
- "klaus",
- TestWord.of("klaus", "Müsch")),
+ TestOutputUser.of(KLAUS.getUser()),
+ TestOutputWord.of(KLAUS.getUser(), "Müsch")),
KeyValue.pair(
- "klaus",
- TestWord.of("klaus", "gäb")),
+ TestOutputUser.of(KLAUS.getUser()),
+ TestOutputWord.of(KLAUS.getUser(), "gäb")),
KeyValue.pair(
- "klaus",
- TestWord.of("klaus", "s")),
+ TestOutputUser.of(KLAUS.getUser()),
+ TestOutputWord.of(KLAUS.getUser(), "s")),
KeyValue.pair(
- "klaus",
- TestWord.of("klaus", "auch")),
+ TestOutputUser.of(KLAUS.getUser()),
+ TestOutputWord.of(KLAUS.getUser(), "auch")),
KeyValue.pair(
- "peter",
- TestWord.of("peter", "Boäh")),
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "Boäh")),
KeyValue.pair(
- "peter",
- TestWord.of("peter", "echt")),
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "echt")),
KeyValue.pair(
- "peter",
- TestWord.of("peter", "ß")),
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "ß")),
KeyValue.pair(
- "peter",
- TestWord.of("peter", "mal")),
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "mal")),
KeyValue.pair(
- "peter",
- TestWord.of("peter", "nä")),
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "nä")),
KeyValue.pair(
- "peter",
- TestWord.of("peter", "Nümmäh")));
+ TestOutputUser.of(PETER.getUser()),
+ TestOutputWord.of(PETER.getUser(), "Nümmäh")),
+ };
+
+ static MultiValueMap<TestOutputUser, TestOutputWord> expectedMessages()
+ {
+ MultiValueMap<TestOutputUser, TestOutputWord> expectedMessages = new LinkedMultiValueMap<>();
+ Stream
+ .of(EXPECTED_MESSAGES)
+ .forEach(keyValue -> expectedMessages.add(keyValue.key, keyValue.value));
+ return expectedMessages;
+ }
}