Skip to content

Commit

Permalink
Configure Test Containers PubSub emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
erlendev authored and vpaturet committed Jan 28, 2025
1 parent 33314cf commit 9f732fd
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 13 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</scm>
<properties>
<java.version>17</java.version>
<entur.google.pubsub.emulator.download.skip>false</entur.google.pubsub.emulator.download.skip>
<entur.google.pubsub.emulator.download.skip>true</entur.google.pubsub.emulator.download.skip>
<camel.version>4.4.5</camel.version>
<entur.helpers.version>4.9</entur.helpers.version>
<netex-validator-java.version>9.1.3</netex-validator-java.version>
Expand Down Expand Up @@ -238,6 +238,15 @@
</dependency>

<!-- testing -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>gcloud</artifactId>
</dependency>
<dependency>
<groupId>org.entur</groupId>
<artifactId>netex-validator-java</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
);
}
}
3 changes: 1 addition & 2 deletions src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9f732fd

Please sign in to comment.