diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index c592c100..13a14565 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -18,9 +18,6 @@ jobs: - uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Copy maven settings - run: | - wget https://raw.githubusercontent.com/entur/ror-maven-settings/master/.m2/settings.xml -O .github/workflows/settings.xml - uses: actions/setup-java@v4 with: java-version: 17 diff --git a/pom.xml b/pom.xml index 86766044..7ee714c7 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ 17 - false + true 4.4.5 4.9 9.1.3 @@ -238,6 +238,15 @@ + + org.testcontainers + junit-jupiter + test + + + org.testcontainers + gcloud + org.entur netex-validator-java diff --git a/src/test/java/no/entur/antu/AntuRouteBuilderIntegrationTestBase.java b/src/test/java/no/entur/antu/AntuRouteBuilderIntegrationTestBase.java index bb60436f..dadfdc7f 100644 --- a/src/test/java/no/entur/antu/AntuRouteBuilderIntegrationTestBase.java +++ b/src/test/java/no/entur/antu/AntuRouteBuilderIntegrationTestBase.java @@ -39,27 +39,35 @@ import org.apache.camel.model.ModelCamelContext; import org.apache.camel.test.spring.junit5.CamelSpringBootTest; import org.apache.camel.test.spring.junit5.UseAdviceWith; +import org.entur.pubsub.base.EnturGooglePubSubAdmin; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; import org.rutebanken.helper.storage.repository.InMemoryBlobStoreRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.PubSubEmulatorContainer; +import org.testcontainers.junit.jupiter.Testcontainers; +import org.testcontainers.utility.DockerImageName; @CamelSpringBootTest @UseAdviceWith @ActiveProfiles( - { - "test", - "default", - "in-memory-blobstore", - "google-pubsub-emulator", - "google-pubsub-autocreate", - } + { "test", "default", "in-memory-blobstore", "google-pubsub-autocreate" } ) +@Testcontainers @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) public abstract class AntuRouteBuilderIntegrationTestBase { + private static PubSubEmulatorContainer pubsubEmulator; + + @Autowired + private EnturGooglePubSubAdmin enturGooglePubSubAdmin; + @Value("${blobstore.gcs.antu.exchange.container.name}") private String antuExchangeContainerName; @@ -89,8 +97,41 @@ void initInMemoryBlobStoreRepositories() { antuInMemoryBlobStoreRepository.setContainerName(antuContainerName); } + @BeforeAll + public static void init() { + pubsubEmulator = + new PubSubEmulatorContainer( + DockerImageName.parse( + "gcr.io/google.com/cloudsdktool/cloud-sdk:emulators" + ) + ); + pubsubEmulator.start(); + } + + @AfterAll + public static void tearDown() { + pubsubEmulator.stop(); + } + + @AfterEach + public void teardown() { + enturGooglePubSubAdmin.deleteAllSubscriptions(); + } + @AfterEach void stopContext() { context.stop(); } + + @DynamicPropertySource + static void emulatorProperties(DynamicPropertyRegistry registry) { + registry.add( + "spring.cloud.gcp.pubsub.emulator-host", + pubsubEmulator::getEmulatorEndpoint + ); + registry.add( + "camel.component.google-pubsub.endpoint", + pubsubEmulator::getEmulatorEndpoint + ); + } } diff --git a/src/test/resources/application.properties b/src/test/resources/application.properties index 307338d7..e74bc884 100644 --- a/src/test/resources/application.properties +++ b/src/test/resources/application.properties @@ -47,10 +47,9 @@ blobstore.gcs.project.id=test # PubSub antu.pubsub.project.id=test logging.level.io.grpc.internal.ManagedChannelOrphanWrapper=OFF -camel.component.google-pubsub.endpoint=localhost:8095 + # Spring Cloud GCP is used in unit tests only for spawning a PubSub emulator and creating Topics and Subscriptions spring.cloud.gcp.project-id=${antu.pubsub.project.id} -spring.cloud.gcp.pubsub.emulatorHost=localhost:8095 camel.component.google-pubsub.authenticate=false camel.component.google-pubsub.synchronous-pull-retryable-codes=DEADLINE_EXCEEDED