Der Integration-Test prüft auch, ob der HealthIndicator 'UP' zurückgibt
authorKai Moritz <kai@juplo.de>
Fri, 12 Aug 2022 21:27:45 +0000 (23:27 +0200)
committerKai Moritz <kai@juplo.de>
Sat, 13 Aug 2022 07:22:38 +0000 (09:22 +0200)
src/test/java/de/juplo/kafka/ApplicationIT.java

index 4c149cc..cded0ee 100644 (file)
@@ -1,14 +1,18 @@
 package de.juplo.kafka;
 
 import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo;
 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 static de.juplo.kafka.ApplicationTests.TOPIC;
 
 
 @SpringBootTest(
+    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
     properties = {
         "consumer.bootstrap-server=${spring.embedded.kafka.brokers}",
         "consumer.topic=" + TOPIC,
@@ -19,7 +23,21 @@ public class ApplicationIT
 {
   public static final String TOPIC = "FOO";
 
+  @LocalServerPort
+  private int port;
+
+  @Autowired
+  private TestRestTemplate restTemplate;
+
+
 
   @Test
-  public void testApplicationStartup() {}
+  public void testApplicationStartup()
+  {
+    restTemplate.getForObject(
+        "http://localhost:" + port + "/actuator/health",
+        String.class
+        )
+        .contains("UP");
+  }
 }