From: Kai Moritz Date: Sun, 2 Jun 2024 15:28:55 +0000 (+0200) Subject: splitter: 1.2.0 - Introduced `TestRanking` X-Git-Tag: splitter-1.2.0~9 X-Git-Url: http://juplo.de/gitweb/?a=commitdiff_plain;h=cfed6b631771687b645375394c422ec0c02720f5;p=demos%2Fkafka%2Fwordcount splitter: 1.2.0 - Introduced `TestRanking` * `SplitterApplicationIT` uses the separate class `TestRanking` to represent the input data, that comes from the foreign domain. --- diff --git a/src/test/java/de/juplo/kafka/wordcount/recorder/TestRecording.java b/src/test/java/de/juplo/kafka/wordcount/recorder/TestRecording.java new file mode 100644 index 0000000..2d09896 --- /dev/null +++ b/src/test/java/de/juplo/kafka/wordcount/recorder/TestRecording.java @@ -0,0 +1,15 @@ +package de.juplo.kafka.wordcount.recorder; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +@Data +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +public class TestRecording +{ + String user; + String sentence; +} diff --git a/src/test/java/de/juplo/kafka/wordcount/splitter/SplitterApplicationIT.java b/src/test/java/de/juplo/kafka/wordcount/splitter/SplitterApplicationIT.java index adf4dde..a702e1d 100644 --- a/src/test/java/de/juplo/kafka/wordcount/splitter/SplitterApplicationIT.java +++ b/src/test/java/de/juplo/kafka/wordcount/splitter/SplitterApplicationIT.java @@ -1,6 +1,7 @@ package de.juplo.kafka.wordcount.splitter; import de.juplo.kafka.wordcount.counter.TestWord; +import de.juplo.kafka.wordcount.recorder.TestRecording; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,7 +45,7 @@ public class SplitterApplicationIT public final static String TOPIC_OUT = "out"; @Autowired - KafkaTemplate kafkaTemplate; + KafkaTemplate kafkaTemplate; @Autowired Consumer consumer; diff --git a/src/test/java/de/juplo/kafka/wordcount/splitter/TestData.java b/src/test/java/de/juplo/kafka/wordcount/splitter/TestData.java index 89cebaa..2af8644 100644 --- a/src/test/java/de/juplo/kafka/wordcount/splitter/TestData.java +++ b/src/test/java/de/juplo/kafka/wordcount/splitter/TestData.java @@ -1,6 +1,7 @@ package de.juplo.kafka.wordcount.splitter; import de.juplo.kafka.wordcount.counter.TestWord; +import de.juplo.kafka.wordcount.recorder.TestRecording; import org.apache.kafka.streams.KeyValue; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -15,26 +16,29 @@ import static org.awaitility.Awaitility.await; public class TestData { - static void writeInputData(BiConsumer consumer) - { - Recording recording; - - recording = new Recording(); - recording.setUser("peter"); - recording.setSentence("Hallo Welt!"); - consumer.accept(recording.getUser(), recording); - - recording = new Recording(); - recording.setUser("klaus"); - recording.setSentence("Müsch gäb's auch!"); - consumer.accept(recording.getUser(), recording); + static final String PETER = "peter"; + static final String KLAUS = "klaus"; - recording = new Recording(); - recording.setUser("peter"); - recording.setSentence("Boäh, echt! ß mal nä Nümmäh!"); - consumer.accept(recording.getUser(), recording); + static void writeInputData(BiConsumer consumer) + { + Stream + .of(INPUT_MESSAGES) + .forEach(kv -> consumer.accept(kv.key, kv.value)); } + static final KeyValue[] INPUT_MESSAGES = new KeyValue[] + { + new KeyValue<>( + PETER, + TestRecording.of(PETER, "Hallo Welt!")), + new KeyValue<>( + KLAUS, + TestRecording.of(KLAUS, "Müsch gäb's auch!")), + new KeyValue<>( + PETER, + TestRecording.of(PETER, "Boäh, echt! ß mal nä Nümmäh!")), + }; + static void assertExpectedMessages(MultiValueMap receivedMessages) { MultiValueMap expected = new LinkedMultiValueMap<>();