tonitch/back/test #139
@ -31,6 +31,8 @@ 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")
|
||||||
|
testImplementation("org.hamcrest:hamcrest")
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.register("run") {
|
tasks.register("run") {
|
||||||
|
@ -1,13 +1,70 @@
|
|||||||
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.boot.testcontainers.service.connection.ServiceConnection;
|
||||||
|
import org.springframework.web.service.annotation.GetExchange;
|
||||||
|
import org.testcontainers.containers.PostgreSQLContainer;
|
||||||
|
import org.testcontainers.junit.jupiter.Container;
|
||||||
|
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||||
|
|
||||||
|
import io.restassured.RestAssured;
|
||||||
|
|
||||||
|
import com.github.dockerjava.api.model.ExposedPort;
|
||||||
|
import com.github.dockerjava.api.model.HostConfig;
|
||||||
|
import com.github.dockerjava.api.model.PortBinding;
|
||||||
|
import com.github.dockerjava.api.model.Ports;
|
||||||
|
|
||||||
|
@Testcontainers
|
||||||
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||||
class ClydeApplicationTests {
|
class ClydeApplicationTests {
|
||||||
|
|
||||||
|
@LocalServerPort
|
||||||
|
private Integer port;
|
||||||
|
|
||||||
|
@Container
|
||||||
|
@ServiceConnection
|
||||||
|
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:alpine")
|
||||||
|
.withDatabaseName("clyde")
|
||||||
|
.withUsername("devel")
|
||||||
|
.withPassword("devel")
|
||||||
|
.withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
|
||||||
|
new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(5432), new ExposedPort(5432)))
|
||||||
|
));
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ClydeApplication controller;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void beforeAll(){
|
||||||
|
postgres.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
static void afterAll() {
|
||||||
|
postgres.stop();
|
||||||
|
}
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
RestAssured.baseURI = "http://localhost:" + port;
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void contextLoads() {
|
void contextLoads(){
|
||||||
|
assertThat(controller).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void enableMock(){
|
||||||
|
RestAssured.get("/ping").then().statusCode(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user