Letze Angleichungen an Neu-Aufgleisung per REBASE spring/spring-consumer
authorKai Moritz <kai@juplo.de>
Sun, 29 Sep 2024 13:29:07 +0000 (15:29 +0200)
committerKai Moritz <kai@juplo.de>
Thu, 3 Oct 2024 07:38:27 +0000 (09:38 +0200)
pom.xml
src/main/resources/logback.xml [deleted file]
src/test/java/de/juplo/kafka/ApplicationTests.java

diff --git a/pom.xml b/pom.xml
index 156c65e..63651ca 100644 (file)
--- a/pom.xml
+++ b/pom.xml
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.springframework.boot</groupId>
-      <artifactId>spring-boot-starter-validation</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-actuator</artifactId>
       <artifactId>spring-boot-configuration-processor</artifactId>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>org.springframework.boot</groupId>
+      <artifactId>spring-boot-starter-validation</artifactId>
+    </dependency>
     <dependency>
       <groupId>org.springframework.kafka</groupId>
       <artifactId>spring-kafka</artifactId>
           </execution>
         </executions>
       </plugin>
+      <plugin>
+        <groupId>pl.project13.maven</groupId>
+        <artifactId>git-commit-id-plugin</artifactId>
+      </plugin>
       <plugin>
         <groupId>io.fabric8</groupId>
         <artifactId>docker-maven-plugin</artifactId>
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
deleted file mode 100644 (file)
index b8e6780..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-
-  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
-    <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
-      <Pattern>%highlight(%-5level) %m%n</Pattern>
-    </encoder>
-  </appender>
-
-  <logger name="de.juplo" level="TRACE"/>
-  <!-- logger name="org.apache.kafka.clients" level="DEBUG" / -->
-
-  <root level="INFO">
-    <appender-ref ref="STDOUT" />
-  </root>
-
-</configuration>
index 4df6f16..53c15c9 100644 (file)
@@ -2,39 +2,46 @@ package de.juplo.kafka;
 
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
 import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.boot.test.web.client.TestRestTemplate;
-import org.springframework.boot.test.web.server.LocalServerPort;
 import org.springframework.kafka.test.context.EmbeddedKafka;
+import org.springframework.test.web.servlet.MockMvc;
 
+import java.time.Duration;
+
+import static de.juplo.kafka.ApplicationTests.PARTITIONS;
 import static de.juplo.kafka.ApplicationTests.TOPIC;
+import static org.awaitility.Awaitility.await;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 
 
 @SpringBootTest(
-    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
     properties = {
         "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}",
+        "spring.kafka.consumer.auto-offset-reset=earliest",
         "juplo.consumer.topics=" + TOPIC })
-@EmbeddedKafka(topics = TOPIC)
+@AutoConfigureMockMvc
+@EmbeddedKafka(topics = TOPIC, partitions = PARTITIONS)
 public class ApplicationTests
 {
-  public static final String TOPIC = "FOO";
-
-  @LocalServerPort
-  private int port;
+  static final String TOPIC = "FOO";
+  static final int PARTITIONS = 10;
 
   @Autowired
-  private TestRestTemplate restTemplate;
+  MockMvc mockMvc;
 
 
 
   @Test
   public void testApplicationStartup()
   {
-    restTemplate.getForObject(
-        "http://localhost:" + port + "/actuator/health",
-        String.class
-        )
-        .contains("UP");
+    await("Application is healthy")
+      .atMost(Duration.ofSeconds(5))
+      .untilAsserted(() -> mockMvc
+        .perform(get("/actuator/health"))
+        .andExpect(status().isOk())
+        .andExpect(jsonPath("status").value("UP")));
   }
 }