From 219e86fd04f2feb2bf8e7b0df2ea5fc91312d6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20B=C3=BChner?= Date: Mon, 21 Oct 2024 17:59:07 +0200 Subject: [PATCH] test: fix sonarqube issues and add reload integration test --- .../event/bus/BusAmqpIntegrationTests.java | 1 + .../LifecycleRemoteApplicationEventsIT.java | 29 ++++++++++++++++--- .../TestConfigurationAutoConfiguration.java | 17 +++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java index c20c6d925..4f78075aa 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/BusAmqpIntegrationTests.java @@ -114,6 +114,7 @@ static void properties(DynamicPropertyRegistry registry) { @BeforeAll static void setUpRemoteApplicationContext() { + remoteAppContext = new SpringApplicationBuilder( TestConfigurationAutoConfiguration.class, BusEventCollector.class) diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/LifecycleRemoteApplicationEventsIT.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/LifecycleRemoteApplicationEventsIT.java index c29fca33a..269619710 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/LifecycleRemoteApplicationEventsIT.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/LifecycleRemoteApplicationEventsIT.java @@ -5,6 +5,7 @@ package org.geoserver.cloud.event.bus; import org.geoserver.cloud.event.lifecycle.LifecycleEvent; +import org.geoserver.cloud.event.lifecycle.ReloadEvent; import org.geoserver.cloud.event.lifecycle.ResetEvent; import org.geoserver.config.GeoServer; import org.geoserver.platform.GeoServerExtensions; @@ -29,9 +30,29 @@ void testGeoServerHasExecutedReset() { Consumer modifier = GeoServer::reset; modifier.accept(geoserver); - RemoteGeoServerEvent localRemoteEvent = - eventsCaptor.local().expectOneLifecycleEvent(ResetEvent.class); - RemoteGeoServerEvent sentEvent = - eventsCaptor.remote().expectOneLifecycleEvent(ResetEvent.class); + eventsCaptor.local().expectOneLifecycleEvent(ResetEvent.class); + eventsCaptor.remote().expectOneLifecycleEvent(ResetEvent.class); + } + + @Test + void testGeoServerHasExecutedReload() { + + this.eventsCaptor.stop().clear().captureLifecycleEventsOf(LifecycleEvent.class).start(); + + Consumer modifier = + geoServer -> { + try { + geoServer.reload(); + } catch (Exception e) { + throw new RuntimeException(e); + } + }; + modifier.accept(geoserver); + + // reload also triggers reset! + eventsCaptor.local().expectOneLifecycleEvent(ReloadEvent.class); + eventsCaptor.local().expectOneLifecycleEvent(ResetEvent.class); + eventsCaptor.remote().expectOneLifecycleEvent(ReloadEvent.class); + eventsCaptor.remote().expectOneLifecycleEvent(ResetEvent.class); } } diff --git a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/TestConfigurationAutoConfiguration.java b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/TestConfigurationAutoConfiguration.java index 7042d0b80..adc5e45ff 100644 --- a/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/TestConfigurationAutoConfiguration.java +++ b/src/catalog/event-bus/src/test/java/org/geoserver/cloud/event/bus/TestConfigurationAutoConfiguration.java @@ -6,9 +6,12 @@ import org.geoserver.catalog.Catalog; import org.geoserver.catalog.plugin.CatalogPlugin; +import org.geoserver.config.DefaultGeoServerLoader; import org.geoserver.config.GeoServer; +import org.geoserver.config.GeoServerLoader; import org.geoserver.config.plugin.GeoServerImpl; import org.geoserver.config.util.XStreamPersisterFactory; +import org.geoserver.platform.GeoServerResourceLoader; import org.geoserver.platform.config.DefaultUpdateSequence; import org.geoserver.platform.config.UpdateSequence; import org.springframework.beans.factory.annotation.Qualifier; @@ -41,4 +44,18 @@ GeoServer geoServer(@Qualifier("catalog") Catalog catalog) { gs.setCatalog(catalog); return gs; } + + @Bean + GeoServerResourceLoader geoServerResourceLoader() { + return new GeoServerResourceLoader(); + } + + @Bean + GeoServerLoader geoserverLoader( + @Qualifier("geoServer") GeoServer geoServer, + @Qualifier("geoServerResourceLoader") GeoServerResourceLoader geoServerResourceLoader) { + DefaultGeoServerLoader loader = new DefaultGeoServerLoader(geoServerResourceLoader); + loader.postProcessBeforeInitialization(geoServer, "geoserver"); + return loader; + } }