Skip to content

Commit

Permalink
feat: redo not totally working Testcontainers config for Kafka
Browse files Browse the repository at this point in the history
  • Loading branch information
bobeal committed Dec 23, 2024
1 parent d522201 commit 8f70cea
Show file tree
Hide file tree
Showing 16 changed files with 37 additions and 49 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -59,7 +60,7 @@ import java.util.UUID

@SpringBootTest
@ActiveProfiles("test")
class EntityAccessRightsServiceTests : WithTimescaleContainer {
class EntityAccessRightsServiceTests : WithTimescaleContainer, WithKafkaContainer() {

@Autowired
private lateinit var entityAccessRightsService: EntityAccessRightsService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,7 +37,7 @@ import java.util.UUID

@SpringBootTest
@ActiveProfiles("test")
class SubjectReferentialServiceTests : WithTimescaleContainer {
class SubjectReferentialServiceTests : WithTimescaleContainer, WithKafkaContainer() {

@Autowired
private lateinit var subjectReferentialService: SubjectReferentialService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import java.time.ZonedDateTime

@SpringBootTest
@ActiveProfiles("test")
class EntityAttributeServiceTests : WithTimescaleContainer, WithKafkaContainer {
class EntityAttributeServiceTests : WithTimescaleContainer, WithKafkaContainer() {

@Autowired
@SpykBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
}

0 comments on commit 8f70cea

Please sign in to comment.