From 4b89ff2a1c9891dafb08222996ca3f64b7c33cfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 10:30:40 +0200 Subject: [PATCH 01/26] wip use test container for pubsub emulator --- .../no/entur/uttu/UttuIntegrationTest.java | 2 +- .../messaging/MessagingServiceTest.java | 20 ++++++++++++++++++- .../resources/application-test.properties | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/test/java/no/entur/uttu/UttuIntegrationTest.java b/src/test/java/no/entur/uttu/UttuIntegrationTest.java index eac0971c..39df8576 100644 --- a/src/test/java/no/entur/uttu/UttuIntegrationTest.java +++ b/src/test/java/no/entur/uttu/UttuIntegrationTest.java @@ -27,7 +27,7 @@ webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = UttuTestApp.class ) -@ActiveProfiles({ "google-pubsub-emulator", "test" }) +@ActiveProfiles({ "test" }) @EnableAspectJAutoProxy(proxyTargetClass = true) public abstract class UttuIntegrationTest { diff --git a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java index df1811d5..cd3884ce 100644 --- a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java +++ b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java @@ -24,11 +24,14 @@ import org.entur.pubsub.base.EnturGooglePubSubAdmin; import org.junit.Assert; import org.junit.Test; +import org.junit.After; +import org.junit.Before; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.utility.DockerImageName; public class MessagingServiceTest extends UttuIntegrationTest { - public static final String TEST_CODESPACE = "rut"; public static final String TEST_EXPORT_FILE_NAME = "netex.zip"; @@ -45,6 +48,21 @@ public class MessagingServiceTest extends UttuIntegrationTest { @Value("${export.notify.queue.name:FlexibleLinesExportQueue}") private String queueName; + static GenericContainer pubsubEmulator = new GenericContainer<>(DockerImageName.parse("gcr.io/google.com/cloudsdktool/google-cloud-cli:latest")) + .withCommand("gcloud beta emulators pubsub start --project=test") + .withExposedPorts(8085); + + @Before + public void setUp() { + pubsubEmulator.start(); + } + + @After + public void tearDown() { + pubsubEmulator.stop(); + } + + @Test public void testNotifyExport() { enturGooglePubSubAdmin.createSubscriptionIfMissing(queueName); diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index fe3d586f..42264b27 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -31,7 +31,7 @@ spring.cloud.gcp.pubsub.project-id=test # Path to credential for accessing the Google Cloud project, using the Spring resource syntax (prefixed with file:) #spring.cloud.gcp.pubsub.credentials.location=file:/path/to/json/file # if this property is present then the client library connects to the PubSub emulator instead of Google Cloud -spring.cloud.gcp.pubsub.emulatorHost=localhost:8088 +spring.cloud.gcp.pubsub.emulatorHost=localhost:8085 # number of parallel pullers for a given Subscriber. Constrained by the number of threads in the executor. spring.cloud.gcp.pubsub.subscriber.parallel-pull-count=1 # number of executor threads (shared by all subscribers) From 21c5873d949a1233bda7deacdf784a13881545b6 Mon Sep 17 00:00:00 2001 From: Vincent Paturet Date: Wed, 15 May 2024 12:26:43 +0200 Subject: [PATCH 02/26] Use testcontainers support for PubSubEmulator --- pom.xml | 9 +++ .../messaging/MessagingServiceTest.java | 80 ++++++++++++++++--- 2 files changed, 76 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index dfbb73a9..30f18adb 100644 --- a/pom.xml +++ b/pom.xml @@ -299,6 +299,15 @@ 1.19.8 test + + org.testcontainers + junit-jupiter + test + + + org.testcontainers + gcloud + org.assertj assertj-core diff --git a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java index cd3884ce..d29cdf03 100644 --- a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java +++ b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java @@ -16,25 +16,35 @@ package no.entur.uttu.export.messaging; +import static org.testcontainers.shaded.org.awaitility.Awaitility.await; + +import com.google.api.gax.core.CredentialsProvider; +import com.google.api.gax.core.NoCredentialsProvider; import com.google.cloud.spring.pubsub.core.PubSubTemplate; +import com.google.cloud.spring.pubsub.core.subscriber.PubSubSubscriberTemplate; import com.google.pubsub.v1.PubsubMessage; import java.nio.charset.StandardCharsets; import java.util.List; import no.entur.uttu.UttuIntegrationTest; import org.entur.pubsub.base.EnturGooglePubSubAdmin; -import org.junit.Assert; -import org.junit.Test; -import org.junit.After; -import org.junit.Before; +import org.junit.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.testcontainers.containers.GenericContainer; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; +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; +@Testcontainers public class MessagingServiceTest extends UttuIntegrationTest { + public static final String TEST_CODESPACE = "rut"; public static final String TEST_EXPORT_FILE_NAME = "netex.zip"; + private static PubSubEmulatorContainer pubsubEmulator; @Autowired private MessagingService messagingService; @@ -42,31 +52,75 @@ public class MessagingServiceTest extends UttuIntegrationTest { @Autowired private PubSubTemplate pubSubTemplate; + @Autowired + PubSubSubscriberTemplate subscriberTemplate; + @Autowired private EnturGooglePubSubAdmin enturGooglePubSubAdmin; @Value("${export.notify.queue.name:FlexibleLinesExportQueue}") private String queueName; - static GenericContainer pubsubEmulator = new GenericContainer<>(DockerImageName.parse("gcr.io/google.com/cloudsdktool/google-cloud-cli:latest")) - .withCommand("gcloud beta emulators pubsub start --project=test") - .withExposedPorts(8085); + @DynamicPropertySource + static void emulatorProperties(DynamicPropertyRegistry registry) { + pubsubEmulator = + new PubSubEmulatorContainer( + DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:emulators") + ); + pubsubEmulator.start(); + registry.add( + "spring.cloud.gcp.pubsub.emulator-host", + pubsubEmulator::getEmulatorEndpoint + ); + } + + @AfterClass + public static void tearDown() { + pubsubEmulator.stop(); + } @Before - public void setUp() { - pubsubEmulator.start(); + public void setup() { + enturGooglePubSubAdmin.createSubscriptionIfMissing(queueName); } @After - public void tearDown() { - pubsubEmulator.stop(); + public void teardown() { + // Drain any messages that are still in the subscription so that they don't interfere with + // subsequent tests. + await().until(() -> subscriberTemplate.pullAndAck(queueName, 1000, true).isEmpty()); } + // By default, autoconfiguration will initialize application default credentials. + // For testing purposes, don't use any credentials. Bootstrap w/ NoCredentialsProvider. + @TestConfiguration + static class PubSubEmulatorConfiguration { + + @Bean + CredentialsProvider googleCredentials() { + return NoCredentialsProvider.create(); + } + } @Test public void testNotifyExport() { - enturGooglePubSubAdmin.createSubscriptionIfMissing(queueName); + messagingService.notifyExport(TEST_CODESPACE, TEST_EXPORT_FILE_NAME); + List messages = pubSubTemplate.pullAndAck(queueName, 1, false); + Assert.assertEquals(messages.size(), 1); + PubsubMessage pubsubMessage = messages.get(0); + String codespace = pubsubMessage + .getAttributesMap() + .get(PubSubMessagingService.HEADER_CHOUETTE_REFERENTIAL); + Assert.assertEquals("rb_" + TEST_CODESPACE, codespace); + Assert.assertEquals( + TEST_EXPORT_FILE_NAME, + pubsubMessage.getData().toString(StandardCharsets.UTF_8) + ); + } + + @Test + public void testNotifyExport2() { messagingService.notifyExport(TEST_CODESPACE, TEST_EXPORT_FILE_NAME); List messages = pubSubTemplate.pullAndAck(queueName, 1, false); From 6f298a70559478c73baeb3410cae93d8806f9715 Mon Sep 17 00:00:00 2001 From: Vincent Paturet Date: Wed, 15 May 2024 12:35:15 +0200 Subject: [PATCH 03/26] Init emulator in BeforeClass --- .../uttu/export/messaging/MessagingServiceTest.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java index d29cdf03..0af864ec 100644 --- a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java +++ b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java @@ -63,15 +63,19 @@ public class MessagingServiceTest extends UttuIntegrationTest { @DynamicPropertySource static void emulatorProperties(DynamicPropertyRegistry registry) { + registry.add( + "spring.cloud.gcp.pubsub.emulator-host", + pubsubEmulator::getEmulatorEndpoint + ); + } + + @BeforeClass + public static void init() { pubsubEmulator = new PubSubEmulatorContainer( DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:emulators") ); pubsubEmulator.start(); - registry.add( - "spring.cloud.gcp.pubsub.emulator-host", - pubsubEmulator::getEmulatorEndpoint - ); } @AfterClass From 1953e225d6bfe51b67c5e5a67d830d39bf29fbde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 12:43:21 +0200 Subject: [PATCH 04/26] Skip emulator download --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 30f18adb..c4f54f10 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ 21 - false + true 2.21 From 0fc86cbc780441ff171122e1a57f68612e38cff8 Mon Sep 17 00:00:00 2001 From: Vincent Paturet Date: Wed, 15 May 2024 13:39:11 +0200 Subject: [PATCH 05/26] Removed duplicated test --- .../export/messaging/MessagingServiceTest.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java index 0af864ec..cb3d322a 100644 --- a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java +++ b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java @@ -122,21 +122,4 @@ public void testNotifyExport() { pubsubMessage.getData().toString(StandardCharsets.UTF_8) ); } - - @Test - public void testNotifyExport2() { - messagingService.notifyExport(TEST_CODESPACE, TEST_EXPORT_FILE_NAME); - - List messages = pubSubTemplate.pullAndAck(queueName, 1, false); - Assert.assertEquals(messages.size(), 1); - PubsubMessage pubsubMessage = messages.get(0); - String codespace = pubsubMessage - .getAttributesMap() - .get(PubSubMessagingService.HEADER_CHOUETTE_REFERENTIAL); - Assert.assertEquals("rb_" + TEST_CODESPACE, codespace); - Assert.assertEquals( - TEST_EXPORT_FILE_NAME, - pubsubMessage.getData().toString(StandardCharsets.UTF_8) - ); - } } From a59e30598fc7fcc47c5549a0f9b58fbbe8127fb2 Mon Sep 17 00:00:00 2001 From: Vincent Paturet Date: Wed, 15 May 2024 15:20:22 +0200 Subject: [PATCH 06/26] Delete all subscriptions after test --- .../entur/uttu/export/messaging/MessagingServiceTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java index cb3d322a..619228bc 100644 --- a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java +++ b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java @@ -16,8 +16,6 @@ package no.entur.uttu.export.messaging; -import static org.testcontainers.shaded.org.awaitility.Awaitility.await; - import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.NoCredentialsProvider; import com.google.cloud.spring.pubsub.core.PubSubTemplate; @@ -90,9 +88,7 @@ public void setup() { @After public void teardown() { - // Drain any messages that are still in the subscription so that they don't interfere with - // subsequent tests. - await().until(() -> subscriberTemplate.pullAndAck(queueName, 1000, true).isEmpty()); + enturGooglePubSubAdmin.deleteAllSubscriptions(); } // By default, autoconfiguration will initialize application default credentials. From 642fda42ded191bdfd0dfa4d43310ae07d70c9be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 17:45:03 +0200 Subject: [PATCH 07/26] Move test-specific properties into code --- .../messaging/MessagingServiceTest.java | 4 ++++ .../resources/application-test.properties | 24 +++---------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java index 619228bc..13b02f26 100644 --- a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java +++ b/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java @@ -65,6 +65,10 @@ static void emulatorProperties(DynamicPropertyRegistry registry) { "spring.cloud.gcp.pubsub.emulator-host", pubsubEmulator::getEmulatorEndpoint ); + registry.add("spring.cloud.gcp.project-id", () -> "test"); + registry.add("spring.cloud.gcp.pubsub.project-id", () -> "test"); + registry.add("export.notify.enabled", () -> true); + registry.add("export.notify.queue.name", () -> "FlexibleLinesExportQueue"); } @BeforeClass diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 42264b27..7a1e7162 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -16,33 +16,15 @@ server.port=11701 server.host=localhost -blobstore.gcs.container.name=internal + spring.jpa.database=POSTGRESQL spring.sql.init.platform=postgres spring.datasource.url=jdbc:tc:postgis:13-3.3:///uttu -# Enable notifications to Marduk when a new NeTex export is uploaded -export.notify.enabled=true -export.notify.queue.name=FlexibleLinesExportQueue - +# Are these used in tests? +blobstore.gcs.container.name=internal spring.cloud.gcp.project-id=test -spring.cloud.gcp.pubsub.project-id=test -# Path to credential for accessing the Google Cloud project, using the Spring resource syntax (prefixed with file:) -#spring.cloud.gcp.pubsub.credentials.location=file:/path/to/json/file -# if this property is present then the client library connects to the PubSub emulator instead of Google Cloud -spring.cloud.gcp.pubsub.emulatorHost=localhost:8085 -# number of parallel pullers for a given Subscriber. Constrained by the number of threads in the executor. -spring.cloud.gcp.pubsub.subscriber.parallel-pull-count=1 -# number of executor threads (shared by all subscribers) -spring.cloud.gcp.pubsub.subscriber.executor-threads=30 -# the client library will automatically extend the ack deadline up to this limit. -spring.cloud.gcp.pubsub.subscriber.max-ack-extension-period=36000 -# number of threads performing ack deadline extension (shared by all subscribers). The default value is 5 -#entur.pubsub.subscriber.system-threads=5 -# path to Google PubSub emulator -# default path if the property is not set (retrieved as a Maven dependency): -#entur.pubsub.emulator.path=target/pubsub-emulator/pubsub-emulator-0.1-SNAPSHOT.jar # Monitoring management.endpoints.enabled-by-default=false From 697108ee5fc13abcd342aff53e7b430ac7d0bf8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 17:49:15 +0200 Subject: [PATCH 08/26] Move messaging service impl to entur sandbox --- .../entur}/export/messaging/MessagingServiceTest.java | 7 +++++-- .../export/messaging/EnturPubSubMessagingService.java} | 9 ++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) rename src/{test/java/no/entur/uttu => ext-test/java/no/entur/uttu/ext/entur}/export/messaging/MessagingServiceTest.java (93%) rename src/{main/java/no/entur/uttu/export/messaging/PubSubMessagingService.java => ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java} (84%) diff --git a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java similarity index 93% rename from src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java rename to src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java index 13b02f26..56666ebd 100644 --- a/src/test/java/no/entur/uttu/export/messaging/MessagingServiceTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java @@ -14,7 +14,7 @@ * */ -package no.entur.uttu.export.messaging; +package no.entur.uttu.ext.entur.export.messaging; import com.google.api.gax.core.CredentialsProvider; import com.google.api.gax.core.NoCredentialsProvider; @@ -24,12 +24,14 @@ import java.nio.charset.StandardCharsets; import java.util.List; import no.entur.uttu.UttuIntegrationTest; +import no.entur.uttu.export.messaging.MessagingService; import org.entur.pubsub.base.EnturGooglePubSubAdmin; import org.junit.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; +import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; import org.testcontainers.containers.PubSubEmulatorContainer; @@ -37,6 +39,7 @@ import org.testcontainers.utility.DockerImageName; @Testcontainers +@ActiveProfiles({"test", "entur-pubsub-messaging-service"}) public class MessagingServiceTest extends UttuIntegrationTest { public static final String TEST_CODESPACE = "rut"; @@ -115,7 +118,7 @@ public void testNotifyExport() { PubsubMessage pubsubMessage = messages.get(0); String codespace = pubsubMessage .getAttributesMap() - .get(PubSubMessagingService.HEADER_CHOUETTE_REFERENTIAL); + .get(EnturPubSubMessagingService.HEADER_CHOUETTE_REFERENTIAL); Assert.assertEquals("rb_" + TEST_CODESPACE, codespace); Assert.assertEquals( TEST_EXPORT_FILE_NAME, diff --git a/src/main/java/no/entur/uttu/export/messaging/PubSubMessagingService.java b/src/ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java similarity index 84% rename from src/main/java/no/entur/uttu/export/messaging/PubSubMessagingService.java rename to src/ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java index cb821d75..30fa3e31 100644 --- a/src/main/java/no/entur/uttu/export/messaging/PubSubMessagingService.java +++ b/src/ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java @@ -1,18 +1,21 @@ -package no.entur.uttu.export.messaging; +package no.entur.uttu.ext.entur.export.messaging; import com.google.cloud.spring.pubsub.core.PubSubTemplate; import java.util.HashMap; import java.util.Map; import java.util.UUID; import no.entur.uttu.config.Context; +import no.entur.uttu.export.messaging.MessagingService; import no.entur.uttu.util.ExportUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Component; @Component -public class PubSubMessagingService implements MessagingService { +@Profile("entur-pubsub-messaging-service") +public class EnturPubSubMessagingService implements MessagingService { public static final String HEADER_CHOUETTE_REFERENTIAL = "RutebankenChouetteReferential"; @@ -29,7 +32,7 @@ public class PubSubMessagingService implements MessagingService { @Value("${export.notify.queue.name:FlexibleLinesExportQueue}") private String queueName; - public PubSubMessagingService(PubSubTemplate pubSubTemplate) { + public EnturPubSubMessagingService(PubSubTemplate pubSubTemplate) { this.pubSubTemplate = pubSubTemplate; } From d4d44c862ae1335981c874cdee585d703a1862d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 17:50:38 +0200 Subject: [PATCH 09/26] Provide default noop impl --- .../export/messaging/NoopMessagingService.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java diff --git a/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java b/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java new file mode 100644 index 00000000..12bb0578 --- /dev/null +++ b/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java @@ -0,0 +1,15 @@ +package no.entur.uttu.export.messaging; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.stereotype.Component; + +@Component +@ConditionalOnMissingBean( + value = MessagingService.class, ignored = NoopMessagingService.class +) +public class NoopMessagingService implements MessagingService { + @Override + public void notifyExport(String codespace, String filename) { + // noop + } +} From bb0bd29feb9ab388b8deb2c26f50e9465fbfcb1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 17:53:41 +0200 Subject: [PATCH 10/26] Move interface to spi package --- .../export/messaging/MessagingServiceTest.java | 2 +- .../messaging/EnturPubSubMessagingService.java | 2 +- .../java/no/entur/uttu/export/ExportService.java | 2 +- .../uttu/export/messaging/MessagingService.java | 5 ----- .../export/messaging/NoopMessagingService.java | 6 +++++- .../export/messaging/spi/MessagingService.java | 14 ++++++++++++++ 6 files changed, 22 insertions(+), 9 deletions(-) delete mode 100644 src/main/java/no/entur/uttu/export/messaging/MessagingService.java create mode 100644 src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java diff --git a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java index 56666ebd..c18f6954 100644 --- a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java @@ -24,7 +24,7 @@ import java.nio.charset.StandardCharsets; import java.util.List; import no.entur.uttu.UttuIntegrationTest; -import no.entur.uttu.export.messaging.MessagingService; +import no.entur.uttu.export.messaging.spi.MessagingService; import org.entur.pubsub.base.EnturGooglePubSubAdmin; import org.junit.*; import org.springframework.beans.factory.annotation.Autowired; diff --git a/src/ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java b/src/ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java index 30fa3e31..b2adc7e2 100644 --- a/src/ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java +++ b/src/ext/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingService.java @@ -5,7 +5,7 @@ import java.util.Map; import java.util.UUID; import no.entur.uttu.config.Context; -import no.entur.uttu.export.messaging.MessagingService; +import no.entur.uttu.export.messaging.spi.MessagingService; import no.entur.uttu.util.ExportUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/no/entur/uttu/export/ExportService.java b/src/main/java/no/entur/uttu/export/ExportService.java index c9866b8c..6c66ac95 100644 --- a/src/main/java/no/entur/uttu/export/ExportService.java +++ b/src/main/java/no/entur/uttu/export/ExportService.java @@ -20,7 +20,7 @@ import java.util.List; import no.entur.uttu.error.codedexception.CodedIllegalArgumentException; import no.entur.uttu.export.linestatistics.ExportedLineStatisticsService; -import no.entur.uttu.export.messaging.MessagingService; +import no.entur.uttu.export.messaging.spi.MessagingService; import no.entur.uttu.export.netex.DataSetProducer; import no.entur.uttu.export.netex.NetexExporter; import no.entur.uttu.model.Line; diff --git a/src/main/java/no/entur/uttu/export/messaging/MessagingService.java b/src/main/java/no/entur/uttu/export/messaging/MessagingService.java deleted file mode 100644 index 686c25d0..00000000 --- a/src/main/java/no/entur/uttu/export/messaging/MessagingService.java +++ /dev/null @@ -1,5 +0,0 @@ -package no.entur.uttu.export.messaging; - -public interface MessagingService { - void notifyExport(String codespace, String filename); -} diff --git a/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java b/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java index 12bb0578..166f38c6 100644 --- a/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java +++ b/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java @@ -1,8 +1,12 @@ package no.entur.uttu.export.messaging; +import no.entur.uttu.export.messaging.spi.MessagingService; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.stereotype.Component; +/** + * The default implementation is a noop operation + */ @Component @ConditionalOnMissingBean( value = MessagingService.class, ignored = NoopMessagingService.class @@ -10,6 +14,6 @@ public class NoopMessagingService implements MessagingService { @Override public void notifyExport(String codespace, String filename) { - // noop + // intentionally empty } } diff --git a/src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java b/src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java new file mode 100644 index 00000000..de523cea --- /dev/null +++ b/src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java @@ -0,0 +1,14 @@ +package no.entur.uttu.export.messaging.spi; + +/** + * Represents a service which can send a notification to an external system about an export + */ +public interface MessagingService { + + /** + * Notify about export + * @param codespace The codespace of the provider + * @param filename The filename for this export + */ + void notifyExport(String codespace, String filename); +} From 314ccd71f06dcad61a42112b57e221bc35e0ffef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 17:54:32 +0200 Subject: [PATCH 11/26] Formatting --- .../entur/export/messaging/MessagingServiceTest.java | 2 +- .../uttu/export/messaging/NoopMessagingService.java | 12 +++++++----- .../uttu/export/messaging/spi/MessagingService.java | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java index c18f6954..81da942a 100644 --- a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java @@ -39,7 +39,7 @@ import org.testcontainers.utility.DockerImageName; @Testcontainers -@ActiveProfiles({"test", "entur-pubsub-messaging-service"}) +@ActiveProfiles({ "test", "entur-pubsub-messaging-service" }) public class MessagingServiceTest extends UttuIntegrationTest { public static final String TEST_CODESPACE = "rut"; diff --git a/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java b/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java index 166f38c6..d4c8a4b0 100644 --- a/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java +++ b/src/main/java/no/entur/uttu/export/messaging/NoopMessagingService.java @@ -9,11 +9,13 @@ */ @Component @ConditionalOnMissingBean( - value = MessagingService.class, ignored = NoopMessagingService.class + value = MessagingService.class, + ignored = NoopMessagingService.class ) public class NoopMessagingService implements MessagingService { - @Override - public void notifyExport(String codespace, String filename) { - // intentionally empty - } + + @Override + public void notifyExport(String codespace, String filename) { + // intentionally empty + } } diff --git a/src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java b/src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java index de523cea..35144e2c 100644 --- a/src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java +++ b/src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java @@ -4,7 +4,6 @@ * Represents a service which can send a notification to an external system about an export */ public interface MessagingService { - /** * Notify about export * @param codespace The codespace of the provider From ce15b184d21ddff3dc5d6db1e81bf471c7a466aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 18:03:27 +0200 Subject: [PATCH 12/26] Rename test class --- ...ingServiceTest.java => EnturPubSubMessagingServiceTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/{MessagingServiceTest.java => EnturPubSubMessagingServiceTest.java} (98%) diff --git a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java similarity index 98% rename from src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java rename to src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java index 81da942a..b559b3b0 100644 --- a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/MessagingServiceTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java @@ -40,7 +40,7 @@ @Testcontainers @ActiveProfiles({ "test", "entur-pubsub-messaging-service" }) -public class MessagingServiceTest extends UttuIntegrationTest { +public class EnturPubSubMessagingServiceTest extends UttuIntegrationTest { public static final String TEST_CODESPACE = "rut"; From 2b3c89a6219ce1b38c8e065c810c349c77d26ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 18:04:08 +0200 Subject: [PATCH 13/26] Fix assertion idiom --- .../entur/export/messaging/EnturPubSubMessagingServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java index b559b3b0..e85e6660 100644 --- a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java @@ -114,7 +114,7 @@ public void testNotifyExport() { messagingService.notifyExport(TEST_CODESPACE, TEST_EXPORT_FILE_NAME); List messages = pubSubTemplate.pullAndAck(queueName, 1, false); - Assert.assertEquals(messages.size(), 1); + Assert.assertEquals(1, messages.size()); PubsubMessage pubsubMessage = messages.get(0); String codespace = pubsubMessage .getAttributesMap() From ba78b37c6d77fc24fe9d4936454968585594714d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 18:12:26 +0200 Subject: [PATCH 14/26] Add readme section --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 2f42ffcb..a1fc9bf1 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,14 @@ see `src/main/java/no/entur/uttu/stopplace/spi/StopPlaceRegistry.java`. Refer to `src/test/resources/fixtures/stopplace.xml` for an example of a NeTEx file with stop places. +## Optional export notification message + +If you want to notify an external system about a NeTEx file export, you can +provide an implementation of the `MessagingService` interface –– see +`src/main/java/no/entur/uttu/export/messaging/spi/MessagingService.java`. + +The default MessagingService implementation is a noop. + ## Running locally ### Build To build the project from source, you need Java 21 and Maven 3. From 99a4d9e70056298c3020877d36d73f6738717dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Wed, 15 May 2024 21:38:43 +0200 Subject: [PATCH 15/26] Clarify which properties are actually needed for tests --- src/test/resources/application-test.properties | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 7a1e7162..2bedc279 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -13,24 +13,20 @@ # limitations under the Licence. # -server.port=11701 -server.host=localhost - - - +# Configure database test container spring.jpa.database=POSTGRESQL spring.sql.init.platform=postgres spring.datasource.url=jdbc:tc:postgis:13-3.3:///uttu -# Are these used in tests? -blobstore.gcs.container.name=internal -spring.cloud.gcp.project-id=test - -# Monitoring +# Monitoring endpoints turned off in tests management.endpoints.enabled-by-default=false management.health.pubsub.enabled=false management.endpoints.web.exposure.exclude=* management.endpoints.jmx.exposure.exclude=* +# This property is needed, but should probably be renamed +blobstore.gcs.container.name=internal + +# Integrations with fixtures uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml From f20b136d05711502af94f177f498ffb3e5c79c53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Tue, 21 May 2024 15:40:22 +0200 Subject: [PATCH 16/26] Restore properties needed by pubsub helper --- src/test/resources/application-test.properties | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 2bedc279..2cf4e5a1 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -30,3 +30,8 @@ blobstore.gcs.container.name=internal # Integrations with fixtures uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml + + +# TODO: These should not be needed in integration tests, but seem to be required by entur google pubsub helper +spring.cloud.gcp.project-id=test +spring.cloud.gcp.pubsub.project-id=test From 898f13852b679dd0da48f4be1dec6c228303362d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 10:22:00 +0200 Subject: [PATCH 17/26] Dummy values for pubsub properties --- README.md | 8 ++++++++ src/test/resources/application-test.properties | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1fc9bf1..87dee4cd 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,14 @@ provide an implementation of the `MessagingService` interface –– see The default MessagingService implementation is a noop. +## Additional properties + +The following properties are needed by a GCP pubsub dependency, and auto-configuration +will fail without them. If you don't use pubsub, you can set them to dummy values: + + spring.cloud.gcp.project-id=test + spring.cloud.gcp.pubsub.project-id=test + ## Running locally ### Build To build the project from source, you need Java 21 and Maven 3. diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 2cf4e5a1..8867fa16 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -32,6 +32,6 @@ uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml -# TODO: These should not be needed in integration tests, but seem to be required by entur google pubsub helper +# Properties needed by pubsub-helper, set to dummy values spring.cloud.gcp.project-id=test spring.cloud.gcp.pubsub.project-id=test From 9eeabb21536de28f09c3df97b4f56ab9a7a659cd Mon Sep 17 00:00:00 2001 From: Vincent Paturet Date: Thu, 23 May 2024 10:47:37 +0200 Subject: [PATCH 18/26] Use unique GCP project ID --- .../export/messaging/EnturPubSubMessagingServiceTest.java | 4 ++-- src/test/resources/application-test.properties | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java index e85e6660..6a41e8a6 100644 --- a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java @@ -68,8 +68,8 @@ static void emulatorProperties(DynamicPropertyRegistry registry) { "spring.cloud.gcp.pubsub.emulator-host", pubsubEmulator::getEmulatorEndpoint ); - registry.add("spring.cloud.gcp.project-id", () -> "test"); - registry.add("spring.cloud.gcp.pubsub.project-id", () -> "test"); + registry.add("spring.cloud.gcp.project-id", () -> "uttu-gcp-test-project"); + registry.add("spring.cloud.gcp.pubsub.project-id", () -> "uttu-gcp-test-project"); registry.add("export.notify.enabled", () -> true); registry.add("export.notify.queue.name", () -> "FlexibleLinesExportQueue"); } diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 8867fa16..09e39432 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -33,5 +33,5 @@ uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml # Properties needed by pubsub-helper, set to dummy values -spring.cloud.gcp.project-id=test -spring.cloud.gcp.pubsub.project-id=test +spring.cloud.gcp.project-id=uttu-gcp-test-project +spring.cloud.gcp.pubsub.project-id=uttu-gcp-test-project From c4fd9641917897a0ece8dd30b5d5bf8bfad8a968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 11:38:03 +0200 Subject: [PATCH 19/26] Make pubsub config import dependent on profile --- README.md | 8 -------- .../uttu/ext/entur/config/EnturConfiguration.java | 11 +++++++++++ src/main/java/no/entur/uttu/App.java | 1 - src/test/java/no/entur/uttu/UttuTestApp.java | 1 - src/test/resources/application-test.properties | 5 ----- 5 files changed, 11 insertions(+), 15 deletions(-) create mode 100644 src/ext/java/no/entur/uttu/ext/entur/config/EnturConfiguration.java diff --git a/README.md b/README.md index 87dee4cd..a1fc9bf1 100644 --- a/README.md +++ b/README.md @@ -57,14 +57,6 @@ provide an implementation of the `MessagingService` interface –– see The default MessagingService implementation is a noop. -## Additional properties - -The following properties are needed by a GCP pubsub dependency, and auto-configuration -will fail without them. If you don't use pubsub, you can set them to dummy values: - - spring.cloud.gcp.project-id=test - spring.cloud.gcp.pubsub.project-id=test - ## Running locally ### Build To build the project from source, you need Java 21 and Maven 3. diff --git a/src/ext/java/no/entur/uttu/ext/entur/config/EnturConfiguration.java b/src/ext/java/no/entur/uttu/ext/entur/config/EnturConfiguration.java new file mode 100644 index 00000000..029a386c --- /dev/null +++ b/src/ext/java/no/entur/uttu/ext/entur/config/EnturConfiguration.java @@ -0,0 +1,11 @@ +package no.entur.uttu.ext.entur.config; + +import org.entur.pubsub.base.config.GooglePubSubConfig; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.Profile; + +@Configuration +@Profile("entur-pubsub-messaging-service") +@Import(GooglePubSubConfig.class) +public class EnturConfiguration {} diff --git a/src/main/java/no/entur/uttu/App.java b/src/main/java/no/entur/uttu/App.java index 129264a7..a377e216 100644 --- a/src/main/java/no/entur/uttu/App.java +++ b/src/main/java/no/entur/uttu/App.java @@ -28,7 +28,6 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication(exclude = { UserDetailsServiceAutoConfiguration.class }) -@Import(GooglePubSubConfig.class) @EnableJpaRepositories( basePackages = { "no.entur.uttu.repository" }, repositoryBaseClass = ProviderEntityRepositoryImpl.class diff --git a/src/test/java/no/entur/uttu/UttuTestApp.java b/src/test/java/no/entur/uttu/UttuTestApp.java index f49a3679..efc7e60c 100644 --- a/src/test/java/no/entur/uttu/UttuTestApp.java +++ b/src/test/java/no/entur/uttu/UttuTestApp.java @@ -26,7 +26,6 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication -@Import(GooglePubSubConfig.class) @EnableJpaRepositories( basePackages = { "no.entur.uttu.repository" }, repositoryBaseClass = ProviderEntityRepositoryImpl.class diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 8867fa16..2bedc279 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -30,8 +30,3 @@ blobstore.gcs.container.name=internal # Integrations with fixtures uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml - - -# Properties needed by pubsub-helper, set to dummy values -spring.cloud.gcp.project-id=test -spring.cloud.gcp.pubsub.project-id=test From b23b7b241dd644cd1c948ff84293a2371e7025fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 11:46:24 +0200 Subject: [PATCH 20/26] Remove unused imports --- src/main/java/no/entur/uttu/App.java | 2 -- src/test/java/no/entur/uttu/UttuTestApp.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/src/main/java/no/entur/uttu/App.java b/src/main/java/no/entur/uttu/App.java index a377e216..363e090d 100644 --- a/src/main/java/no/entur/uttu/App.java +++ b/src/main/java/no/entur/uttu/App.java @@ -17,13 +17,11 @@ import no.entur.uttu.model.Provider; import no.entur.uttu.repository.generic.ProviderEntityRepositoryImpl; -import org.entur.pubsub.base.config.GooglePubSubConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.context.annotation.Import; import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; diff --git a/src/test/java/no/entur/uttu/UttuTestApp.java b/src/test/java/no/entur/uttu/UttuTestApp.java index efc7e60c..c49152d0 100644 --- a/src/test/java/no/entur/uttu/UttuTestApp.java +++ b/src/test/java/no/entur/uttu/UttuTestApp.java @@ -17,12 +17,10 @@ import no.entur.uttu.repository.generic.ProviderEntityRepositoryImpl; import no.entur.uttu.security.UttuSecurityConfiguration; -import org.entur.pubsub.base.config.GooglePubSubConfig; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.FilterType; -import org.springframework.context.annotation.Import; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication From c70dd66764ff9757afad1f9b9d6360b8a2ccfae5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 11:49:38 +0200 Subject: [PATCH 21/26] Disable spring cloud config ? --- src/test/resources/application-test.properties | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 2bedc279..f696e345 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -30,3 +30,6 @@ blobstore.gcs.container.name=internal # Integrations with fixtures uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml + + +spring.cloud.config.enabled=false From aea69bb60839be71215b2db379c25cb450375369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 11:57:22 +0200 Subject: [PATCH 22/26] Disable gcp pubsub --- src/test/resources/application-test.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index f696e345..6260af88 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -32,4 +32,4 @@ uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml -spring.cloud.config.enabled=false +spring.cloud.gcp.pubsub.enabled=false From 4779f61b958e8f8c81db5470296f9bfda984b210 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 12:16:17 +0200 Subject: [PATCH 23/26] Use defaultProperties to disable gcp pubsub --- .../messaging/EnturPubSubMessagingServiceTest.java | 1 + src/main/java/no/entur/uttu/App.java | 9 ++++++++- src/test/java/no/entur/uttu/UttuTestApp.java | 9 ++++++++- src/test/resources/application-test.properties | 3 --- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java index 6a41e8a6..c4044066 100644 --- a/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java +++ b/src/ext-test/java/no/entur/uttu/ext/entur/export/messaging/EnturPubSubMessagingServiceTest.java @@ -68,6 +68,7 @@ static void emulatorProperties(DynamicPropertyRegistry registry) { "spring.cloud.gcp.pubsub.emulator-host", pubsubEmulator::getEmulatorEndpoint ); + registry.add("spring.cloud.gcp.pubsub.enabled", () -> true); registry.add("spring.cloud.gcp.project-id", () -> "uttu-gcp-test-project"); registry.add("spring.cloud.gcp.pubsub.project-id", () -> "uttu-gcp-test-project"); registry.add("export.notify.enabled", () -> true); diff --git a/src/main/java/no/entur/uttu/App.java b/src/main/java/no/entur/uttu/App.java index 363e090d..4f3e29f0 100644 --- a/src/main/java/no/entur/uttu/App.java +++ b/src/main/java/no/entur/uttu/App.java @@ -15,6 +15,7 @@ package no.entur.uttu; +import java.util.Map; import no.entur.uttu.model.Provider; import no.entur.uttu.repository.generic.ProviderEntityRepositoryImpl; import org.springframework.boot.SpringApplication; @@ -32,9 +33,15 @@ ) @EntityScan(basePackageClasses = { Provider.class, Jsr310JpaConverters.class }) @EnableCaching -public class App { +public class App extends SpringApplication { public static void main(String[] args) { SpringApplication.run(App.class, args); } + + @Override + public void setDefaultProperties(Map defaultProperties) { + defaultProperties.put("spring.cloud.gcp.pubsub.enabled", false); + super.setDefaultProperties(defaultProperties); + } } diff --git a/src/test/java/no/entur/uttu/UttuTestApp.java b/src/test/java/no/entur/uttu/UttuTestApp.java index c49152d0..c4ad56b6 100644 --- a/src/test/java/no/entur/uttu/UttuTestApp.java +++ b/src/test/java/no/entur/uttu/UttuTestApp.java @@ -15,6 +15,7 @@ package no.entur.uttu; +import java.util.Map; import no.entur.uttu.repository.generic.ProviderEntityRepositoryImpl; import no.entur.uttu.security.UttuSecurityConfiguration; import org.springframework.boot.SpringApplication; @@ -37,9 +38,15 @@ @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = App.class), } ) -public class UttuTestApp { +public class UttuTestApp extends SpringApplication { public static void main(String[] args) { SpringApplication.run(UttuTestApp.class, args); } + + @Override + public void setDefaultProperties(Map defaultProperties) { + defaultProperties.put("spring.cloud.gcp.pubsub.enabled", false); + super.setDefaultProperties(defaultProperties); + } } diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 6260af88..2bedc279 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -30,6 +30,3 @@ blobstore.gcs.container.name=internal # Integrations with fixtures uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml - - -spring.cloud.gcp.pubsub.enabled=false From b59795b6355fba35d21993aec351bb5eec64e11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 13:40:18 +0200 Subject: [PATCH 24/26] Default properties did not work --- src/main/java/no/entur/uttu/App.java | 9 +-------- src/test/java/no/entur/uttu/UttuTestApp.java | 8 +------- src/test/resources/application-test.properties | 2 ++ 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/src/main/java/no/entur/uttu/App.java b/src/main/java/no/entur/uttu/App.java index 4f3e29f0..363e090d 100644 --- a/src/main/java/no/entur/uttu/App.java +++ b/src/main/java/no/entur/uttu/App.java @@ -15,7 +15,6 @@ package no.entur.uttu; -import java.util.Map; import no.entur.uttu.model.Provider; import no.entur.uttu.repository.generic.ProviderEntityRepositoryImpl; import org.springframework.boot.SpringApplication; @@ -33,15 +32,9 @@ ) @EntityScan(basePackageClasses = { Provider.class, Jsr310JpaConverters.class }) @EnableCaching -public class App extends SpringApplication { +public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } - - @Override - public void setDefaultProperties(Map defaultProperties) { - defaultProperties.put("spring.cloud.gcp.pubsub.enabled", false); - super.setDefaultProperties(defaultProperties); - } } diff --git a/src/test/java/no/entur/uttu/UttuTestApp.java b/src/test/java/no/entur/uttu/UttuTestApp.java index c4ad56b6..81825610 100644 --- a/src/test/java/no/entur/uttu/UttuTestApp.java +++ b/src/test/java/no/entur/uttu/UttuTestApp.java @@ -38,15 +38,9 @@ @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = App.class), } ) -public class UttuTestApp extends SpringApplication { +public class UttuTestApp { public static void main(String[] args) { SpringApplication.run(UttuTestApp.class, args); } - - @Override - public void setDefaultProperties(Map defaultProperties) { - defaultProperties.put("spring.cloud.gcp.pubsub.enabled", false); - super.setDefaultProperties(defaultProperties); - } } diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 2bedc279..dab91654 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -30,3 +30,5 @@ blobstore.gcs.container.name=internal # Integrations with fixtures uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml + +spring.cloud.gcp.pubsub.enabled=false From 2176c63a0593efde00c4bb6bca227097a16ef63a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 13:48:58 +0200 Subject: [PATCH 25/26] Remove unused import --- src/test/java/no/entur/uttu/UttuTestApp.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/no/entur/uttu/UttuTestApp.java b/src/test/java/no/entur/uttu/UttuTestApp.java index 81825610..c49152d0 100644 --- a/src/test/java/no/entur/uttu/UttuTestApp.java +++ b/src/test/java/no/entur/uttu/UttuTestApp.java @@ -15,7 +15,6 @@ package no.entur.uttu; -import java.util.Map; import no.entur.uttu.repository.generic.ProviderEntityRepositoryImpl; import no.entur.uttu.security.UttuSecurityConfiguration; import org.springframework.boot.SpringApplication; From 648a6acc8ba845676d4e65bb60fba526d8a35f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Erik=20St=C3=B8wer?= Date: Thu, 23 May 2024 13:50:25 +0200 Subject: [PATCH 26/26] Document the need to disable google pubsub autoconfiguration --- README.md | 7 +++++++ src/test/resources/application-test.properties | 1 + 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index a1fc9bf1..168f98df 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,13 @@ provide an implementation of the `MessagingService` interface –– see The default MessagingService implementation is a noop. +## Disable Google PubSub autoconfiguration + +If you don't use Google PubSub, sett this property: + + # This property is needed to avoid pubsub autoconfiguration + spring.cloud.gcp.pubsub.enabled=false + ## Running locally ### Build To build the project from source, you need Java 21 and Maven 3. diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index dab91654..4aee3026 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -31,4 +31,5 @@ blobstore.gcs.container.name=internal uttu.organisations.netex-file-uri=src/test/resources/fixtures/organisations.xml uttu.stopplace.netex-file-uri=src/test/resources/fixtures/stopplaces.xml +# This property is needed to avoid pubsub autoconfiguration spring.cloud.gcp.pubsub.enabled=false