diff --git a/build.gradle.kts b/build.gradle.kts index 5dee80a29..5669991b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -79,6 +79,7 @@ subprojects { runtimeOnly("io.micrometer:micrometer-registry-prometheus") testImplementation("org.springframework.boot:spring-boot-starter-test") + testImplementation("org.springframework.boot:spring-boot-testcontainers") testImplementation("io.projectreactor:reactor-test") testImplementation("com.ninja-squad:springmockk:4.0.2") testImplementation("org.springframework.security:spring-security-test") diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/EntityAccessRightsServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/EntityAccessRightsServiceTests.kt index 38f051872..15a71eecb 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/EntityAccessRightsServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/EntityAccessRightsServiceTests.kt @@ -10,6 +10,7 @@ import com.egm.stellio.search.authorization.model.SubjectReferential import com.egm.stellio.search.entity.model.EntitiesQueryFromGet import com.egm.stellio.search.entity.model.Entity import com.egm.stellio.search.entity.service.EntityService +import com.egm.stellio.search.support.WithKafkaContainer import com.egm.stellio.search.support.WithTimescaleContainer import com.egm.stellio.search.support.buildSapAttribute import com.egm.stellio.shared.model.AccessDeniedException @@ -59,7 +60,7 @@ import java.util.UUID @SpringBootTest @ActiveProfiles("test") -class EntityAccessRightsServiceTests : WithTimescaleContainer { +class EntityAccessRightsServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var entityAccessRightsService: EntityAccessRightsService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/SubjectReferentialServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/SubjectReferentialServiceTests.kt index 8d09e591a..5ec77a83b 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/SubjectReferentialServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/authorization/service/SubjectReferentialServiceTests.kt @@ -6,6 +6,7 @@ import com.egm.stellio.search.authorization.getSubjectInfoForGroup import com.egm.stellio.search.authorization.getSubjectInfoForUser import com.egm.stellio.search.authorization.model.SubjectReferential import com.egm.stellio.search.support.EMPTY_JSON_PAYLOAD +import com.egm.stellio.search.support.WithKafkaContainer import com.egm.stellio.search.support.WithTimescaleContainer import com.egm.stellio.shared.model.AccessDeniedException import com.egm.stellio.shared.util.ADMIN_ROLES @@ -36,7 +37,7 @@ import java.util.UUID @SpringBootTest @ActiveProfiles("test") -class SubjectReferentialServiceTests : WithTimescaleContainer { +class SubjectReferentialServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var subjectReferentialService: SubjectReferentialService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/csr/service/ContextSourceRegistrationServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/csr/service/ContextSourceRegistrationServiceTests.kt index 865e11889..9f99f0a4d 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/csr/service/ContextSourceRegistrationServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/csr/service/ContextSourceRegistrationServiceTests.kt @@ -5,6 +5,7 @@ import com.egm.stellio.search.csr.model.CSRFilters import com.egm.stellio.search.csr.model.ContextSourceRegistration import com.egm.stellio.search.csr.model.ContextSourceRegistration.Companion.notFoundMessage import com.egm.stellio.search.csr.model.Operation +import com.egm.stellio.search.support.WithKafkaContainer import com.egm.stellio.search.support.WithTimescaleContainer import com.egm.stellio.shared.model.AlreadyExistsException import com.egm.stellio.shared.model.ResourceNotFoundException @@ -33,7 +34,7 @@ import java.util.UUID @SpringBootTest @ActiveProfiles("test") @TestPropertySource(properties = ["application.authentication.enabled=false"]) -class ContextSourceRegistrationServiceTests : WithTimescaleContainer { +class ContextSourceRegistrationServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var contextSourceRegistrationService: ContextSourceRegistrationService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/AttributeServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/AttributeServiceTests.kt index cd43ffb21..5f9508c19 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/AttributeServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/AttributeServiceTests.kt @@ -52,7 +52,7 @@ import java.time.ZoneOffset @SpringBootTest @ActiveProfiles("test") -class AttributeServiceTests : WithTimescaleContainer, WithKafkaContainer { +class AttributeServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var attributeService: AttributeService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/EntityTypeServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/EntityTypeServiceTests.kt index abae6170b..a052910d4 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/EntityTypeServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/discovery/service/EntityTypeServiceTests.kt @@ -59,7 +59,7 @@ import org.springframework.test.context.ActiveProfiles @SpringBootTest @ActiveProfiles("test") -class EntityTypeServiceTests : WithTimescaleContainer, WithKafkaContainer { +class EntityTypeServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var entityTypeService: EntityTypeService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityAttributeServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityAttributeServiceTests.kt index 227379112..654d4a8b2 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityAttributeServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityAttributeServiceTests.kt @@ -58,7 +58,7 @@ import java.time.ZonedDateTime @SpringBootTest @ActiveProfiles("test") -class EntityAttributeServiceTests : WithTimescaleContainer, WithKafkaContainer { +class EntityAttributeServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired @SpykBean diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityQueryServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityQueryServiceTests.kt index 431f205e8..c60a3fd4e 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityQueryServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityQueryServiceTests.kt @@ -40,7 +40,7 @@ import java.time.ZonedDateTime @SpringBootTest @ActiveProfiles("test") -class EntityQueryServiceTests : WithTimescaleContainer, WithKafkaContainer { +class EntityQueryServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var entityQueryService: EntityQueryService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceQueriesTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceQueriesTests.kt index aba8f10a8..c86692508 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceQueriesTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceQueriesTests.kt @@ -52,7 +52,7 @@ import java.net.URI @SpringBootTest @ActiveProfiles("test") -class EntityServiceQueriesTests : WithTimescaleContainer, WithKafkaContainer { +class EntityServiceQueriesTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var entityQueryService: EntityQueryService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceTests.kt index 30ec92ffc..54b86b4c5 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/entity/service/EntityServiceTests.kt @@ -60,7 +60,7 @@ import org.springframework.test.context.ActiveProfiles @SpringBootTest @ActiveProfiles("test") -class EntityServiceTests : WithTimescaleContainer, WithKafkaContainer { +class EntityServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var entityService: EntityService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/scope/ScopeServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/scope/ScopeServiceTests.kt index 537391e45..24bc39f48 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/scope/ScopeServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/scope/ScopeServiceTests.kt @@ -44,7 +44,7 @@ import java.util.stream.Stream @SpringBootTest @ActiveProfiles("test") -class ScopeServiceTests : WithTimescaleContainer, WithKafkaContainer { +class ScopeServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var scopeService: ScopeService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/support/WithKafkaContainer.kt b/search-service/src/test/kotlin/com/egm/stellio/search/support/WithKafkaContainer.kt index f8f9fe1f2..727ef5444 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/support/WithKafkaContainer.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/support/WithKafkaContainer.kt @@ -1,29 +1,21 @@ package com.egm.stellio.search.support -import org.springframework.test.context.DynamicPropertyRegistry -import org.springframework.test.context.DynamicPropertySource +import org.springframework.boot.testcontainers.service.connection.ServiceConnection +import org.testcontainers.junit.jupiter.Container +import org.testcontainers.junit.jupiter.Testcontainers import org.testcontainers.kafka.ConfluentKafkaContainer -import org.testcontainers.utility.DockerImageName -interface WithKafkaContainer { +@Testcontainers +@Suppress("UtilityClassWithPublicConstructor") +open class WithKafkaContainer { companion object { - private val kafkaImage: DockerImageName = - DockerImageName.parse("confluentinc/cp-kafka:7.6.0") - - private val kafkaContainer = ConfluentKafkaContainer(kafkaImage).apply { - withReuse(true) - } - + @Container + @ServiceConnection @JvmStatic - @DynamicPropertySource - fun properties(registry: DynamicPropertyRegistry) { - registry.add("spring.kafka.bootstrap-servers") { kafkaContainer.bootstrapServers } - } - - init { - kafkaContainer.start() + val kafkaContainer = ConfluentKafkaContainer("confluentinc/cp-kafka:7.6.0").apply { + withReuse(true) } } } diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AggregatedTemporalQueryServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AggregatedTemporalQueryServiceTests.kt index 775715ee5..3efe15704 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AggregatedTemporalQueryServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AggregatedTemporalQueryServiceTests.kt @@ -45,7 +45,7 @@ import java.util.UUID @SpringBootTest @ActiveProfiles("test") -class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaContainer { +class AggregatedTemporalQueryServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var attributeInstanceService: AttributeInstanceService diff --git a/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AttributeInstanceServiceTests.kt b/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AttributeInstanceServiceTests.kt index d8426dfa8..5cca2a169 100644 --- a/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AttributeInstanceServiceTests.kt +++ b/search-service/src/test/kotlin/com/egm/stellio/search/temporal/service/AttributeInstanceServiceTests.kt @@ -84,7 +84,7 @@ import java.util.UUID @SpringBootTest @ActiveProfiles("test") -class AttributeInstanceServiceTests : WithTimescaleContainer, WithKafkaContainer { +class AttributeInstanceServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var attributeInstanceService: AttributeInstanceService diff --git a/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt b/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt index 2c952d7bf..e886eba82 100644 --- a/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt +++ b/subscription-service/src/test/kotlin/com/egm/stellio/subscription/service/SubscriptionServiceTests.kt @@ -76,7 +76,7 @@ import kotlin.time.Duration @SpringBootTest @ActiveProfiles("test") @TestPropertySource(properties = ["application.authentication.enabled=false"]) -class SubscriptionServiceTests : WithTimescaleContainer, WithKafkaContainer { +class SubscriptionServiceTests : WithTimescaleContainer, WithKafkaContainer() { @Autowired private lateinit var subscriptionService: SubscriptionService diff --git a/subscription-service/src/test/kotlin/com/egm/stellio/subscription/support/WithKafkaContainer.kt b/subscription-service/src/test/kotlin/com/egm/stellio/subscription/support/WithKafkaContainer.kt index cbe761176..2b40e471c 100644 --- a/subscription-service/src/test/kotlin/com/egm/stellio/subscription/support/WithKafkaContainer.kt +++ b/subscription-service/src/test/kotlin/com/egm/stellio/subscription/support/WithKafkaContainer.kt @@ -1,29 +1,21 @@ package com.egm.stellio.subscription.support -import org.springframework.test.context.DynamicPropertyRegistry -import org.springframework.test.context.DynamicPropertySource +import org.springframework.boot.testcontainers.service.connection.ServiceConnection +import org.testcontainers.junit.jupiter.Container +import org.testcontainers.junit.jupiter.Testcontainers import org.testcontainers.kafka.ConfluentKafkaContainer -import org.testcontainers.utility.DockerImageName -interface WithKafkaContainer { +@Testcontainers +@Suppress("UtilityClassWithPublicConstructor") +open class WithKafkaContainer { companion object { - private val kafkaImage: DockerImageName = - DockerImageName.parse("confluentinc/cp-kafka:7.6.0") - - private val kafkaContainer = ConfluentKafkaContainer(kafkaImage).apply { - withReuse(true) - } - + @Container + @ServiceConnection @JvmStatic - @DynamicPropertySource - fun properties(registry: DynamicPropertyRegistry) { - registry.add("spring.kafka.bootstrap-servers") { kafkaContainer.bootstrapServers } - } - - init { - kafkaContainer.start() + val kafkaContainer = ConfluentKafkaContainer("confluentinc/cp-kafka:7.6.0").apply { + withReuse(true) } } }