feature: simple application test
This commit is contained in:
parent
3b1893d836
commit
c9f713bc12
4
pom.xml
4
pom.xml
@ -38,6 +38,10 @@
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-webflux</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
|
73
src/test/java/tk/antoine/roux/MainIT.java
Normal file
73
src/test/java/tk/antoine/roux/MainIT.java
Normal file
@ -0,0 +1,73 @@
|
||||
package tk.antoine.roux;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.reactive.server.EntityExchangeResult;
|
||||
import org.springframework.test.web.reactive.server.FluxExchangeResult;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.client.MockMvcWebTestClient;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||
import static org.springframework.http.MediaType.TEXT_PLAIN;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureWebTestClient
|
||||
@AutoConfigureObservability
|
||||
class MainIT {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webClient;
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that actuator health endpoint return 200")
|
||||
void actuatorHealth() {
|
||||
// Given
|
||||
|
||||
// When
|
||||
ResponseSpec result = webClient.get()
|
||||
.uri("/api/health")
|
||||
.accept(APPLICATION_JSON)
|
||||
.exchange();
|
||||
|
||||
// Then
|
||||
result.expectStatus().isOk();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Check that actuator prometheus contain metric 'application_ready_time_seconds'")
|
||||
void actuatorPrometheus() {
|
||||
// Given
|
||||
|
||||
// When
|
||||
ResponseSpec result = webClient.get()
|
||||
.uri("/api/prometheus")
|
||||
.accept(TEXT_PLAIN)
|
||||
.exchange();
|
||||
|
||||
// Then
|
||||
EntityExchangeResult<String> stringEntityExchangeResult = result
|
||||
.expectStatus().isOk()
|
||||
.expectBody(String.class)
|
||||
.returnResult();
|
||||
|
||||
String responseBody = stringEntityExchangeResult.getResponseBody();
|
||||
Assertions.assertThat(responseBody).containsPattern(
|
||||
Pattern.compile("^application_ready_time_seconds.* [0-9]\\.[0-9]*$", Pattern.MULTILINE)
|
||||
);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user