Add Testcontainers
This commit is contained in:
15
pom.xml
15
pom.xml
@ -85,6 +85,21 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -1,8 +1,11 @@
|
||||
package ch.dlmw.swisssignchallenge;
|
||||
|
||||
import ch.dlmw.swisssignchallenge.config.TestConfig;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
@Import(TestConfig.class)
|
||||
@SpringBootTest
|
||||
class SwisssignChallengeApplicationTests {
|
||||
|
||||
|
@ -0,0 +1,30 @@
|
||||
package ch.dlmw.swisssignchallenge.config;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
|
||||
@TestConfiguration
|
||||
public class TestConfig {
|
||||
private static final PostgreSQLContainer<?> POSTGRES_CONTAINER = new PostgreSQLContainer<>("postgres:latest")
|
||||
.withDatabaseName("testdb")
|
||||
.withUsername("testuser")
|
||||
.withPassword("testpass");
|
||||
|
||||
static {
|
||||
POSTGRES_CONTAINER.start();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
var dataSource = new DriverManagerDataSource();
|
||||
dataSource.setUrl(POSTGRES_CONTAINER.getJdbcUrl());
|
||||
dataSource.setUsername(POSTGRES_CONTAINER.getUsername());
|
||||
dataSource.setPassword(POSTGRES_CONTAINER.getPassword());
|
||||
dataSource.setDriverClassName("org.postgresql.Driver");
|
||||
return dataSource;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user