Skip to content

Commit

Permalink
add test for actuator health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Huisman committed Nov 19, 2024
1 parent f1e616b commit 85ba773
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/test/java/nl/ictu/TestingWebApplicationTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package nl.ictu;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
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.test.context.ActiveProfiles;

import static org.assertj.core.api.Assertions.assertThat;

@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class TestingWebApplicationTests {

@LocalServerPort
private int port;

@Value("${management.server.port}")
private int actuatorPort;

@Autowired
private TestRestTemplate restTemplate;

@Test
public void contextLoads() {
}

@Test
public void testActuatorHealthEndpoint() throws Exception {
assertThat(
restTemplate
.getForObject("http://localhost:" + actuatorPort + "/monitor/health", String.class)
).contains("{\"status\":\"UP\"}");
}

}

0 comments on commit 85ba773

Please sign in to comment.