#418 - Replaced external Postgres DB with one created through TestContainers.
This commit is contained in:
@@ -38,6 +38,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
|
||||
@@ -24,6 +24,9 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.r2dbc.function.DatabaseClient;
|
||||
import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
||||
import org.testcontainers.containers.PostgreSQLContainer;
|
||||
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
@@ -31,6 +34,8 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext
|
||||
@Configuration
|
||||
class InfrastructureConfiguration {
|
||||
|
||||
private PostgreSQLContainer postgres = new PostgreSQLContainer();
|
||||
|
||||
@Bean
|
||||
CustomerRepository customerRepository(R2dbcRepositoryFactory factory) {
|
||||
return factory.getRepository(CustomerRepository.class);
|
||||
@@ -56,14 +61,22 @@ class InfrastructureConfiguration {
|
||||
@Bean
|
||||
PostgresqlConnectionFactory connectionFactory() {
|
||||
|
||||
|
||||
postgres.start();
|
||||
|
||||
PostgresqlConnectionConfiguration config = PostgresqlConnectionConfiguration.builder() //
|
||||
.host("localhost") //
|
||||
.port(5432) //
|
||||
.database("postgres") //
|
||||
.username("postgres") //
|
||||
.password("") //
|
||||
.host(postgres.getContainerIpAddress()) //
|
||||
.port(postgres.getFirstMappedPort()) //
|
||||
.database(postgres.getDatabaseName()) //
|
||||
.username(postgres.getUsername()) //
|
||||
.password(postgres.getPassword()) //
|
||||
.build();
|
||||
|
||||
return new PostgresqlConnectionFactory(config);
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void shutdown() {
|
||||
postgres.stop();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user