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;
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());
}
{
testDriver.close();
}
+
+
+ private static JsonSerializer serializer()
+ {
+ return new JsonSerializer().noTypeInfo();
+ }
+
+ private JsonDeserializer<TestOutputWord> keyDeserializer()
+ {
+ return deserializer(true);
+ }
+
+ private static JsonDeserializer<TestOutputWordCounter> valueDeserializer()
+ {
+ return deserializer(false);
+ }
+
+ private static <T> JsonDeserializer<T> deserializer(boolean isKey)
+ {
+ JsonDeserializer<T> 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<String, Class> typeMappings()
+ {
+ return Map.of(
+ "word", TestOutputWord.class,
+ "counter", TestOutputWordCounter.class);
+ }
}