X-Git-Url: https://juplo.de/gitweb/?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Fde%2Fjuplo%2Fkafka%2Fwordcount%2Fcounter%2FCounterStreamProcessorTopologyTest.java;h=06a0798198493851127b02bd88b1bec49632c2ca;hb=29899898af28dcbb50326ae5837ada195829c592;hp=9c86c6c20dd5d23dfde4940e8ce487e9e8db9dd5;hpb=c7f134403fb392077f24567d916a211949c7b197;p=demos%2Fkafka%2Fwordcount diff --git a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java index 9c86c6c..06a0798 100644 --- a/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java +++ b/src/test/java/de/juplo/kafka/wordcount/counter/CounterStreamProcessorTopologyTest.java @@ -19,6 +19,9 @@ import org.springframework.kafka.support.serializer.JsonSerializer; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; +import java.util.Map; +import java.util.stream.Collectors; + import static de.juplo.kafka.wordcount.counter.CounterApplicationConfiguriation.serializationConfig; import static de.juplo.kafka.wordcount.counter.CounterStreamProcessor.STORE_NAME; @@ -45,15 +48,8 @@ public class CounterStreamProcessorTopologyTest testDriver = new TopologyTestDriver(topology, serializationConfig()); - in = testDriver.createInputTopic( - IN, - new JsonSerializer().noTypeInfo(), - new JsonSerializer().noTypeInfo()); - - out = testDriver.createOutputTopic( - OUT, - new JsonDeserializer(TestOutputWord.class).ignoreTypeHeaders(), - new JsonDeserializer(TestOutputWordCounter.class).ignoreTypeHeaders()); + in = testDriver.createInputTopic(IN, serializer(), serializer()); + out = testDriver.createOutputTopic(OUT, keyDeserializer(), valueDeserializer()); } @@ -83,4 +79,45 @@ public class CounterStreamProcessorTopologyTest { testDriver.close(); } + + + private static JsonSerializer serializer() + { + return new JsonSerializer().noTypeInfo(); + } + + private JsonDeserializer keyDeserializer() + { + return deserializer(true); + } + + private static JsonDeserializer valueDeserializer() + { + return deserializer(false); + } + + private static JsonDeserializer deserializer(boolean isKey) + { + JsonDeserializer deserializer = new JsonDeserializer<>(); + deserializer.configure( + Map.of(JsonDeserializer.TYPE_MAPPINGS, typeMappingsConfig()), + isKey); + return deserializer; + } + + private static String typeMappingsConfig() + { + return typeMappings() + .entrySet() + .stream() + .map(entry -> entry.getKey() + ":" + entry.getValue().getName()) + .collect(Collectors.joining(",")); + } + + private static Map typeMappings() + { + return Map.of( + "word", TestOutputWord.class, + "counter", TestOutputWordCounter.class); + } }