WIP:ALIGN
authorKai Moritz <kai@juplo.de>
Fri, 15 Sep 2023 09:42:32 +0000 (11:42 +0200)
committerKai Moritz <kai@juplo.de>
Fri, 15 Sep 2023 11:17:29 +0000 (13:17 +0200)
src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaChatHomeServiceTest.java
src/test/java/de/juplo/kafka/chat/backend/implementation/kafka/KafkaTestUtils.java

index f12775a..1f7ec4d 100644 (file)
@@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
 import org.springframework.boot.autoconfigure.task.TaskExecutionAutoConfiguration;
 import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.context.annotation.Import;
 import org.springframework.kafka.core.KafkaTemplate;
 import org.springframework.kafka.test.context.EmbeddedKafka;
 
@@ -19,6 +18,7 @@ import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServ
 
 @SpringBootTest(
     classes = {
+        KafkaTestUtils.KafkaTestConfiguration.class,
         KafkaAutoConfiguration.class,
         TaskExecutionAutoConfiguration.class,
     },
@@ -27,7 +27,6 @@ import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServ
         "chat.backend.kafka.data-channel-topic=" + DATA_TOPIC,
         "chat.backend.kafka.num-partitions=" + NUM_SHARDS,
 })
-@Import(KafkaTestUtils.class)
 @EmbeddedKafka(
     topics = { INFO_TOPIC, DATA_TOPIC },
     partitions = 10)
index 5272729..8d948ef 100644 (file)
@@ -19,35 +19,38 @@ import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServ
 import static de.juplo.kafka.chat.backend.implementation.kafka.KafkaChatHomeServiceTest.INFO_TOPIC;
 
 
-@TestConfiguration
-@Import(KafkaServicesConfiguration.class)
-@EnableConfigurationProperties(ChatBackendProperties.class)
-@TestPropertySource(properties = {
-    "spring.main.allow-bean-definition-overriding=true",
-    "chat.backend.services=kafka",
-    "chat.backend.kafka.client-id-PREFIX=TEST",
-    "chat.backend.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
-    "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
-})
 @Slf4j
 public abstract class KafkaTestUtils
 {
-  @Bean
-  WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
+  @TestConfiguration
+  @Import(KafkaServicesConfiguration.class)
+  @EnableConfigurationProperties(ChatBackendProperties.class)
+  @TestPropertySource(properties = {
+      "spring.main.allow-bean-definition-overriding=true",
+      "chat.backend.services=kafka",
+      "chat.backend.kafka.client-id-PREFIX=TEST",
+      "chat.backend.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
+      "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
+  })
+  public static class KafkaTestConfiguration
   {
-    return consumer ->
+    @Bean
+    WorkAssignor dataChannelWorkAssignor(DataChannel dataChannel)
     {
-      List<TopicPartition> assignedPartitions =
-          List.of(new TopicPartition(DATA_TOPIC, 2));
-      consumer.assign(assignedPartitions);
-      dataChannel.onPartitionsAssigned(assignedPartitions);
-    };
-  }
+      return consumer ->
+      {
+        List<TopicPartition> assignedPartitions =
+            List.of(new TopicPartition(DATA_TOPIC, 2));
+        consumer.assign(assignedPartitions);
+        dataChannel.onPartitionsAssigned(assignedPartitions);
+      };
+    }
 
-  @Bean
-  Clock clock()
-  {
-    return Clock.systemDefaultZone();
+    @Bean
+    Clock clock()
+    {
+      return Clock.systemDefaultZone();
+    }
   }