base test [dnw]

This commit is contained in:
Debucquoy Anthony 2024-03-17 01:55:13 +01:00
parent 069466ef5f
commit c6cc9a9e5d
2 changed files with 48 additions and 4 deletions

View File

@ -31,6 +31,7 @@ dependencies {
testImplementation("org.springframework.boot:spring-boot-testcontainers") testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:postgresql") testImplementation("org.testcontainers:postgresql")
testImplementation("io.rest-assured:rest-assured")
} }
tasks.register("run") { tasks.register("run") {

View File

@ -1,13 +1,56 @@
package ovh.herisson.Clyde; package ovh.herisson.Clyde;
import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat;
// import org.springframework.boot.test.context.SpringBootTest;
// @SpringBootTest import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.PostgreSQLContainer;
import io.restassured.RestAssured;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class ClydeApplicationTests { class ClydeApplicationTests {
@LocalServerPort
private Integer port;
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine");
@Autowired
private ClydeApplication controller;
@BeforeAll
static void beforeAll(){
postgres.start();
}
@AfterAll
static void afterAll() {
postgres.stop();
}
@DynamicPropertySource
static void configure(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", postgres::getJdbcUrl);
registry.add("spring.datasource.username", postgres::getUsername);
registry.add("spring.datasource.password", postgres::getUsername);
}
@BeforeEach
void setUp() {
RestAssured.baseURI = "http://localhost:" + port;
}
@Test @Test
void contextLoads() { void contextLoads() throws Exception {
assertThat(controller).isNotNull();
} }
} }