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;
public final static String TOPIC_OUT = "out";
@Autowired
- KafkaTemplate<String, Recording> kafkaTemplate;
+ KafkaTemplate<String, TestRecording> kafkaTemplate;
@Autowired
Consumer consumer;
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;
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<>();