2026-03-16 18:15:32 +01:00
|
|
|
package com.cameleer3.server.app;
|
|
|
|
|
|
2026-03-17 00:02:19 +01:00
|
|
|
import org.opensearch.testcontainers.OpensearchContainer;
|
2026-03-16 18:56:13 +01:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
2026-03-16 18:15:32 +01:00
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
2026-03-16 18:56:13 +01:00
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
2026-03-16 19:41:05 +01:00
|
|
|
import org.springframework.test.context.ActiveProfiles;
|
2026-03-16 18:15:32 +01:00
|
|
|
import org.springframework.test.context.DynamicPropertyRegistry;
|
|
|
|
|
import org.springframework.test.context.DynamicPropertySource;
|
|
|
|
|
import org.testcontainers.containers.PostgreSQLContainer;
|
2026-03-16 19:06:54 +01:00
|
|
|
import org.testcontainers.utility.DockerImageName;
|
2026-03-16 18:15:32 +01:00
|
|
|
|
|
|
|
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
2026-03-16 19:41:05 +01:00
|
|
|
@ActiveProfiles("test")
|
2026-03-16 18:15:32 +01:00
|
|
|
public abstract class AbstractPostgresIT {
|
|
|
|
|
|
2026-03-16 19:06:54 +01:00
|
|
|
private static final DockerImageName TIMESCALEDB_IMAGE =
|
2026-03-16 19:13:47 +01:00
|
|
|
DockerImageName.parse("timescale/timescaledb-ha:pg16")
|
2026-03-16 19:06:54 +01:00
|
|
|
.asCompatibleSubstituteFor("postgres");
|
|
|
|
|
|
2026-03-17 00:02:19 +01:00
|
|
|
static final PostgreSQLContainer<?> postgres;
|
|
|
|
|
static final OpensearchContainer<?> opensearch;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
|
postgres = new PostgreSQLContainer<>(TIMESCALEDB_IMAGE)
|
|
|
|
|
.withDatabaseName("cameleer3")
|
|
|
|
|
.withUsername("cameleer")
|
|
|
|
|
.withPassword("test");
|
|
|
|
|
postgres.start();
|
|
|
|
|
|
|
|
|
|
opensearch = new OpensearchContainer<>("opensearchproject/opensearch:2.19.0");
|
|
|
|
|
opensearch.start();
|
|
|
|
|
}
|
2026-03-16 18:15:32 +01:00
|
|
|
|
2026-03-16 18:56:13 +01:00
|
|
|
@Autowired
|
|
|
|
|
protected JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
2026-03-16 18:15:32 +01:00
|
|
|
@DynamicPropertySource
|
|
|
|
|
static void configureProperties(DynamicPropertyRegistry registry) {
|
|
|
|
|
registry.add("spring.datasource.url", postgres::getJdbcUrl);
|
|
|
|
|
registry.add("spring.datasource.username", postgres::getUsername);
|
|
|
|
|
registry.add("spring.datasource.password", postgres::getPassword);
|
|
|
|
|
registry.add("spring.datasource.driver-class-name", () -> "org.postgresql.Driver");
|
|
|
|
|
registry.add("spring.flyway.enabled", () -> "true");
|
2026-03-18 11:16:31 +01:00
|
|
|
registry.add("spring.flyway.url", postgres::getJdbcUrl);
|
|
|
|
|
registry.add("spring.flyway.user", postgres::getUsername);
|
|
|
|
|
registry.add("spring.flyway.password", postgres::getPassword);
|
2026-03-17 00:02:19 +01:00
|
|
|
registry.add("opensearch.url", opensearch::getHttpHostAddress);
|
2026-03-16 18:15:32 +01:00
|
|
|
}
|
|
|
|
|
}
|