package com.cameleer3.server.app; import org.opensearch.testcontainers.OpensearchContainer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.utility.DockerImageName; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") public abstract class AbstractPostgresIT { private static final DockerImageName TIMESCALEDB_IMAGE = DockerImageName.parse("timescale/timescaledb-ha:pg16") .asCompatibleSubstituteFor("postgres"); 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(); } @Autowired protected JdbcTemplate jdbcTemplate; @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"); registry.add("opensearch.url", opensearch::getHttpHostAddress); } }