1 package de.juplo.kafka.wordcount.counter;
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 lombok.extern.slf4j.Slf4j;
7 import org.apache.kafka.common.serialization.StringSerializer;
8 import org.apache.kafka.streams.TestInputTopic;
9 import org.apache.kafka.streams.TestOutputTopic;
10 import org.apache.kafka.streams.Topology;
11 import org.apache.kafka.streams.TopologyTestDriver;
12 import org.apache.kafka.streams.state.Stores;
13 import org.junit.jupiter.api.AfterEach;
14 import org.junit.jupiter.api.BeforeEach;
15 import org.junit.jupiter.api.Test;
16 import org.springframework.kafka.support.serializer.JsonDeserializer;
17 import org.springframework.kafka.support.serializer.JsonSerializer;
18 import org.springframework.util.LinkedMultiValueMap;
19 import org.springframework.util.MultiValueMap;
21 import static de.juplo.kafka.wordcount.counter.CounterApplicationConfiguriation.serializationConfig;
25 public class CounterStreamProcessorTopologyTest
27 public final static String IN = "TEST-IN";
28 public final static String OUT = "TEST-OUT";
31 TopologyTestDriver testDriver;
32 TestInputTopic<String, TestInputWord> in;
33 TestOutputTopic<TestOutputWord, TestOutputWordCounter> out;
37 public void setUpTestDriver()
39 Topology topology = CounterStreamProcessor.buildTopology(
42 Stores.inMemoryKeyValueStore("TOPOLOGY-TEST"));
44 testDriver = new TopologyTestDriver(topology, serializationConfig());
46 in = testDriver.createInputTopic(
48 new StringSerializer(),
49 new JsonSerializer().noTypeInfo());
51 out = testDriver.createOutputTopic(
53 new JsonDeserializer()
54 .copyWithType(TestOutputWord.class)
56 new JsonDeserializer()
57 .copyWithType(TestOutputWordCounter.class)
58 .ignoreTypeHeaders());
67 .forEach(word -> in.pipeInput(word.getUser(), word));
69 MultiValueMap<TestOutputWord, TestOutputWordCounter> receivedMessages = new LinkedMultiValueMap<>();
72 .forEach(record -> receivedMessages.add(record.key(), record.value()));
74 TestData.assertExpectedMessages(receivedMessages);
78 public void tearDown()