GRÜN: (ungewollt!) - Unabhängigkeit der Tests wieder hergestellt
[demos/kafka/training] / src / test / java / de / juplo / kafka / GenericApplicationTests.java
index cff44e2..449c389 100644 (file)
@@ -1,5 +1,6 @@
 package de.juplo.kafka;
 
+import com.mongodb.client.MongoClient;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.clients.consumer.ConsumerRecord;
 import org.apache.kafka.clients.consumer.KafkaConsumer;
@@ -12,6 +13,7 @@ import org.apache.kafka.common.utils.Bytes;
 import org.junit.jupiter.api.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
+import org.springframework.boot.autoconfigure.mongo.MongoProperties;
 import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;
 import org.springframework.boot.test.context.ConfigDataApplicationContextInitializer;
 import org.springframework.boot.test.context.TestConfiguration;
@@ -60,6 +62,10 @@ abstract class GenericApplicationTests<K, V>
        @Autowired
        ExecutorService executor;
        @Autowired
+       MongoClient mongoClient;
+       @Autowired
+       MongoProperties mongoProperties;
+       @Autowired
        PollIntervalAwareConsumerRebalanceListener rebalanceListener;
        @Autowired
        RecordHandler<K, V> recordHandler;
@@ -346,6 +352,8 @@ abstract class GenericApplicationTests<K, V>
                                        }
                                };
 
+               mongoClient.getDatabase(mongoProperties.getDatabase()).drop();
+
                endlessConsumer =
                                new EndlessConsumer<>(
                                                executor,