import org.apache.kafka.streams.Topology;
import org.apache.kafka.streams.TopologyTestDriver;
import org.apache.kafka.streams.state.Stores;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.kafka.support.serializer.JsonDeserializer;
import org.springframework.kafka.support.serializer.JsonSerde;
public final static String IN = "TEST-IN";
public final static String OUT = "TEST-OUT";
- @Test
- public void test()
+
+ TopologyTestDriver testDriver;
+ TestInputTopic<String, Word> in;
+ TestOutputTopic<Word, WordCounter> out;
+
+
+ @BeforeEach
+ public void setUpTestDriver()
{
Topology topology = CounterStreamProcessor.buildTopology(
IN,
JsonSerde<?> valueSerde = new JsonSerde<>();
valueSerde.configure(propertyMap, false);
- TopologyTestDriver testDriver = new TopologyTestDriver(topology, streamProcessorProperties);
+ testDriver = new TopologyTestDriver(topology, streamProcessorProperties);
- TestInputTopic<String, Word> in = testDriver.createInputTopic(
+ in = testDriver.createInputTopic(
IN,
(JsonSerializer<String>)keySerde.serializer(),
(JsonSerializer<Word>)valueSerde.serializer());
- TestOutputTopic<Word, WordCounter> out = testDriver.createOutputTopic(
+ out = testDriver.createOutputTopic(
OUT,
(JsonDeserializer<Word>)keySerde.deserializer(),
(JsonDeserializer<WordCounter>)valueSerde.deserializer());
+ }
+
+ @Test
+ public void test()
+ {
TestData.injectInputMessages((key, value) -> in.pipeInput(key, value));
MultiValueMap<Word, WordCounter> receivedMessages = new LinkedMultiValueMap<>();
TestData.assertExpectedMessages(receivedMessages);
}
+
+ @AfterEach
+ public void tearDown()
+ {
+ testDriver.close();
+ }
}