Add Testcontainers
This commit is contained in:
@ -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