Skip to content

Commit

Permalink
chore: include test cases for emitting local geoserver lifecycle events
Browse files Browse the repository at this point in the history
  • Loading branch information
dnlkoch committed Oct 1, 2024
1 parent e037e9a commit 7ed8cff
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;

import lombok.NonNull;

Expand All @@ -21,26 +18,20 @@
import org.geoserver.catalog.plugin.Patch;
import org.geoserver.catalog.plugin.Patch.Property;
import org.geoserver.catalog.plugin.PropertyDiff;
import org.geoserver.cloud.event.GeoServerEvent;
import org.geoserver.cloud.event.catalog.CatalogInfoAdded;
import org.geoserver.cloud.event.catalog.CatalogInfoModified;
import org.geoserver.cloud.event.catalog.CatalogInfoRemoved;
import org.geoserver.cloud.event.config.ConfigInfoAdded;
import org.geoserver.cloud.event.config.ConfigInfoModified;
import org.geoserver.cloud.event.config.ServiceRemoved;
import org.geoserver.cloud.event.info.ConfigInfoType;
import org.geoserver.cloud.event.info.InfoAdded;
import org.geoserver.cloud.event.info.InfoEvent;
import org.geoserver.cloud.event.info.InfoModified;
import org.geoserver.cloud.event.info.InfoRemoved;
import org.geoserver.cloud.event.info.*;
import org.geoserver.cloud.event.lifecycle.LifecycleEvent;
import org.geoserver.cloud.event.lifecycle.ReloadEvent;
import org.geoserver.cloud.event.lifecycle.ResetEvent;
import org.geoserver.cloud.test.ApplicationEventCapturingListener;
import org.geoserver.config.ConfigurationListener;
import org.geoserver.config.CoverageAccessInfo;
import org.geoserver.config.*;
import org.geoserver.config.CoverageAccessInfo.QueueType;
import org.geoserver.config.GeoServer;
import org.geoserver.config.GeoServerInfo;
import org.geoserver.config.LoggingInfo;
import org.geoserver.config.ServiceInfo;
import org.geoserver.config.SettingsInfo;
import org.geoserver.config.impl.CoverageAccessInfoImpl;
import org.geoserver.config.impl.SettingsInfoImpl;
import org.geoserver.wms.WMSInfoImpl;
Expand Down Expand Up @@ -71,7 +62,7 @@ class CatalogApplicationEventsConfigurationTest {
private CatalogTestData testData;

public @BeforeEach void before() {
listener.setCapureEventsOf(InfoEvent.class);
listener.setCapureEventsOf(GeoServerEvent.class);
catalog.dispose();
listener.clear();
testData = CatalogTestData.empty(() -> catalog, () -> geoserver).initialize();
Expand All @@ -83,7 +74,7 @@ class CatalogApplicationEventsConfigurationTest {

@Test
void testCatalogEventBroadcasterHasSetUpItself() {
Optional<CatalogListener> publiherListener =
Optional<CatalogListener> publisherListener =
catalog.getListeners().stream()
.filter(
l ->
Expand All @@ -92,12 +83,49 @@ void testCatalogEventBroadcasterHasSetUpItself() {
CatalogApplicationEventPublisher
.LocalCatalogEventPublisher)
.findFirst();
assertTrue(publiherListener.isPresent());
assertTrue(publisherListener.isPresent());
}

@Test
void testGSLifeCycleDispatchOnReset() {
geoserver.reset();

// Check that there is no other event being triggered, we expect a single one.
List<LifecycleEvent> allEvents = listener.allOf(LifecycleEvent.class);
assertEquals(1, allEvents.size());

// And we expect it to be a (local) ResetEvent.
ResetEvent resetEvent = listener.expectOne(ResetEvent.class);
assertTrue(resetEvent.isLocal());
}

@Test
void testGSLifeCycleIgnoreOnDispose() {
geoserver.dispose();

// We don't expect any event on disposal.
List<LifecycleEvent> allEvents = listener.allOf(LifecycleEvent.class);
assertEquals(0, allEvents.size());
}

@Test
void testGSLifeCycleDispatchOnReload() throws Exception {
geoserver.reload();

// Check that there is no other event being triggered, we expect two ones.
List<LifecycleEvent> allEvents = listener.allOf(LifecycleEvent.class);
assertEquals(2, allEvents.size());

// And we expect them to be a (local) ResetEvent and a (local) ReloadEvent.
ReloadEvent reloadEvent = listener.expectOne(ReloadEvent.class);
assertTrue(reloadEvent.isLocal());
ResetEvent resetEvent = listener.expectOne(ResetEvent.class);
assertTrue(resetEvent.isLocal());
}

@Test
void testConfigEventBroadcasterHasSetUpItself() {
Optional<ConfigurationListener> publiherListener =
Optional<ConfigurationListener> publisherListener =
geoserver.getListeners().stream()
.filter(
l ->
Expand All @@ -106,7 +134,7 @@ void testConfigEventBroadcasterHasSetUpItself() {
CatalogApplicationEventPublisher
.LocalConfigEventPublisher)
.findFirst();
assertTrue(publiherListener.isPresent());
assertTrue(publisherListener.isPresent());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

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.GeoServerExtensions;
import org.geoserver.platform.GeoServerResourceLoader;
import org.geoserver.platform.config.DefaultUpdateSequence;
import org.geoserver.platform.config.UpdateSequence;
import org.springframework.beans.factory.annotation.Qualifier;
Expand Down Expand Up @@ -42,4 +46,23 @@ GeoServer geoServer(@Qualifier("catalog") Catalog catalog) {
gs.setCatalog(catalog);
return gs;
}

@Bean
GeoServerExtensions geoserverExtensions() {
return new GeoServerExtensions();
}

@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;
}
}

0 comments on commit 7ed8cff

Please sign in to comment.