counter: 1.2.9 - Reconfigured tests to receive data as domain-instances
[demos/kafka/wordcount] / src / test / java / de / juplo / kafka / wordcount / counter / CounterStreamProcessorTopologyTest.java
index c2ada6f..42ca78b 100644 (file)
@@ -1,13 +1,19 @@
 package de.juplo.kafka.wordcount.counter;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.kafka.common.serialization.*;
-import org.apache.kafka.streams.*;
+import org.apache.kafka.streams.TestInputTopic;
+import org.apache.kafka.streams.TestOutputTopic;
+import org.apache.kafka.streams.Topology;
+import org.apache.kafka.streams.TopologyTestDriver;
 import org.apache.kafka.streams.state.Stores;
 import org.junit.jupiter.api.Test;
+import org.springframework.kafka.support.serializer.JsonDeserializer;
+import org.springframework.kafka.support.serializer.JsonSerde;
+import org.springframework.kafka.support.serializer.JsonSerializer;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
+import java.util.stream.Collectors;
 
 
 public class CounterStreamProcessorTopologyTest
@@ -21,25 +27,37 @@ public class CounterStreamProcessorTopologyTest
     Topology topology = CounterStreamProcessor.buildTopology(
         IN,
         OUT,
-        Stores.inMemoryKeyValueStore("TOPOLOGY-TEST"),
-        new ObjectMapper());
+        Stores.inMemoryKeyValueStore("TOPOLOGY-TEST"));
 
-    CounterApplicationConfiguriation config =
+    CounterApplicationConfiguriation applicationConfiguriation =
         new CounterApplicationConfiguriation();
-    Properties properties =
-        config.propertyMap(new CounterApplicationProperties());
+    Properties streamProcessorProperties =
+        applicationConfiguriation.streamProcessorProperties(new CounterApplicationProperties());
 
-    TopologyTestDriver testDriver = new TopologyTestDriver(topology, properties);
+    Map<String, ?> propertyMap = streamProcessorProperties
+        .entrySet()
+        .stream()
+        .collect(
+            Collectors.toMap(
+                entry -> (String)entry.getKey(),
+                entry -> entry.getValue()
+            ));
+    JsonSerde<?> keySerde = new JsonSerde<>();
+    keySerde.configure(propertyMap, true);
+    JsonSerde<?> valueSerde = new JsonSerde<>();
+    valueSerde.configure(propertyMap, false);
+
+    TopologyTestDriver testDriver = new TopologyTestDriver(topology, streamProcessorProperties);
 
-    TestInputTopic<String, String> in = testDriver.createInputTopic(
+    TestInputTopic<String, Word> in = testDriver.createInputTopic(
         IN,
-        new StringSerializer(),
-        new StringSerializer());
+        (JsonSerializer<String>)keySerde.serializer(),
+        (JsonSerializer<Word>)valueSerde.serializer());
 
-    TestOutputTopic<String, String> out = testDriver.createOutputTopic(
+    TestOutputTopic<Word, WordCount> out = testDriver.createOutputTopic(
         OUT,
-        new StringDeserializer(),
-        new StringDeserializer());
+        (JsonDeserializer<Word>)keySerde.deserializer(),
+        (JsonDeserializer<WordCount>)valueSerde.deserializer());
 
     TestData.writeInputData((key, value) -> in.pipeInput(key, value));