From 9d1909585bedbfbbf5d258121901510ad0484ca3 Mon Sep 17 00:00:00 2001 From: Sascha Doemer Date: Mon, 23 Oct 2023 13:45:15 +0200 Subject: [PATCH] Feature/allow multiple notification urls (#90) --- src/main/java/de/app/fivegla/Application.java | 8 +++---- src/main/resources/application.yml | 2 +- ...plicationConfigurationIntegrationTest.java | 23 +++++++++++++++++++ src/test/resources/application.yml | 2 +- 4 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 src/test/java/de/app/fivegla/ApplicationConfigurationIntegrationTest.java diff --git a/src/main/java/de/app/fivegla/Application.java b/src/main/java/de/app/fivegla/Application.java index 3a54fb93..9d88439f 100644 --- a/src/main/java/de/app/fivegla/Application.java +++ b/src/main/java/de/app/fivegla/Application.java @@ -17,7 +17,7 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import java.util.Collections; +import java.util.List; /** * The main class of the application. @@ -56,8 +56,8 @@ public class Application { @Value("${app.fiware.contextBrokerUrl}") private String contextBrokerUrl; - @Value("${app.fiware.subscriptions.notificationUrl}") - private String notificationUrl; + @Value("${app.fiware.subscriptions.notificationUrls}") + private String[] notificationUrls; @Value("${app.fiware.tenant}") private String tenant; @@ -123,7 +123,7 @@ public StatusService statusService() { */ @Bean public SubscriptionService subscriptionService() { - return new SubscriptionService(contextBrokerUrl, tenant, Collections.singletonList(notificationUrl)); + return new SubscriptionService(contextBrokerUrl, tenant, List.of(notificationUrls)); } /** diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index bc8570e4..64623044 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -71,7 +71,7 @@ app: contextBrokerUrl: ${CONTEXT_BROKER_URL} subscriptions: enabled: true - notificationUrl: ${NOTIFICATION_URL} + notificationUrls: ${NOTIFICATION_URLS} tenant: ${FIWARE_TENANT} cors: allowed-origins: ${CORS_ALLOWED_ORIGINS} diff --git a/src/test/java/de/app/fivegla/ApplicationConfigurationIntegrationTest.java b/src/test/java/de/app/fivegla/ApplicationConfigurationIntegrationTest.java new file mode 100644 index 00000000..76e1752e --- /dev/null +++ b/src/test/java/de/app/fivegla/ApplicationConfigurationIntegrationTest.java @@ -0,0 +1,23 @@ +package de.app.fivegla; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +class ApplicationConfigurationIntegrationTest extends SpringBootIntegrationTestBase { + + @Value("${app.fiware.subscriptions.notificationUrls}") + private String[] notificationUrls; + + @Test + void givenValidConfigurationWhenResolvingNotificationUrlsThenReturnValidUrls() { + assertThat(notificationUrls).isNotEmpty(); + assertThat(notificationUrls.length).isEqualTo(2); + assertThat(notificationUrls[0]).isEqualTo("https://cygnus1.5gla.de"); + assertThat(notificationUrls[1]).isEqualTo("https://cygnus2.5gla.de"); + } + +} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 2624fabd..96d7a808 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -71,7 +71,7 @@ app: contextBrokerUrl: https://orion.5gla.de subscriptions: enabled: false - notificationUrl: https://cygnus.5gla.de + notificationUrls: https://cygnus1.5gla.de, https://cygnus2.5gla.de tenant: default cors: allowed-origins: "http://localhost:8080,https://app.5gla.de/"