diff --git a/common-library/src/it/java/common/container/ContainerFactory.java b/common-library/src/it/java/common/container/ContainerFactory.java index c2e903f71c..fc239333fd 100644 --- a/common-library/src/it/java/common/container/ContainerFactory.java +++ b/common-library/src/it/java/common/container/ContainerFactory.java @@ -1,8 +1,11 @@ package common.container; import dasniko.testcontainers.keycloak.KeycloakContainer; +import org.springframework.boot.testcontainers.service.connection.ServiceConnection; +import org.springframework.context.annotation.Bean; import org.springframework.test.context.DynamicPropertyRegistry; import org.testcontainers.containers.KafkaContainer; +import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.utility.DockerImageName; /** @@ -44,4 +47,16 @@ public static KafkaContainer kafkaContainer(DynamicPropertyRegistry registry, St return kafkaContainer; } + public static PostgreSQLContainer pgvector(DynamicPropertyRegistry registry, String version) { + var image = DockerImageName.parse("pgvector/pgvector:%s".formatted(version)) + .asCompatibleSubstituteFor("postgres"); + var postgres = new PostgreSQLContainer<>(image); + postgres.start(); + + registry.add("spring.datasource.url", postgres::getJdbcUrl); + registry.add("spring.datasource.username", postgres::getUsername); + registry.add("spring.datasource.password", postgres::getPassword); + return postgres; + } + } diff --git a/recommendation/src/test/java/com/yas/recommendation/config/KafkaIntegrationTestConfiguration.java b/recommendation/src/test/java/com/yas/recommendation/config/KafkaIntegrationTestConfiguration.java index 407dcb5640..a5236cf842 100644 --- a/recommendation/src/test/java/com/yas/recommendation/config/KafkaIntegrationTestConfiguration.java +++ b/recommendation/src/test/java/com/yas/recommendation/config/KafkaIntegrationTestConfiguration.java @@ -24,15 +24,7 @@ public KafkaContainer kafkaContainer(DynamicPropertyRegistry registry) { @Bean @ServiceConnection - public PostgreSQLContainer pgvector(DynamicPropertyRegistry registry) { - var image = DockerImageName.parse("pgvector/pgvector:pg16") - .asCompatibleSubstituteFor("postgres"); - var postgres = new PostgreSQLContainer<>(image); - postgres.start(); - - registry.add("spring.datasource.url", postgres::getJdbcUrl); - registry.add("spring.datasource.username", postgres::getUsername); - registry.add("spring.datasource.password", postgres::getPassword); - return postgres; + public PostgreSQLContainer pgvectorContainer(DynamicPropertyRegistry registry) { + return ContainerFactory.pgvector(registry, "pg16"); } }