splitter: 1.2.0 - Introduced `TestRanking`
authorKai Moritz <kai@juplo.de>
Sun, 2 Jun 2024 15:28:55 +0000 (17:28 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 3 Jun 2024 07:34:40 +0000 (09:34 +0200)
* `SplitterApplicationIT` uses the separate class `TestRanking` to
  represent the input data, that comes from the foreign domain.

src/test/java/de/juplo/kafka/wordcount/recorder/TestRecording.java [new file with mode: 0644]
src/test/java/de/juplo/kafka/wordcount/splitter/SplitterApplicationIT.java
src/test/java/de/juplo/kafka/wordcount/splitter/TestData.java

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 (file)
index 0000000..2d09896
--- /dev/null
@@ -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;
+}
index adf4dde..a702e1d 100644 (file)
@@ -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<String, Recording> kafkaTemplate;
+       KafkaTemplate<String, TestRecording> kafkaTemplate;
        @Autowired
        Consumer consumer;
 
index 89cebaa..2af8644 100644 (file)
@@ -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<String, Recording> 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<String, TestRecording> consumer)
+       {
+               Stream
+                               .of(INPUT_MESSAGES)
+                               .forEach(kv -> consumer.accept(kv.key, kv.value));
        }
 
+       static final KeyValue<String, TestRecording>[] 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<String, TestWord> receivedMessages)
        {
                MultiValueMap<String, TestWord> expected = new LinkedMultiValueMap<>();