/** * @see org.geoserver.config.GeoServerInitializer#initialize(org.geoserver.config.GeoServer) */ public void initialize(final GeoServer geoServer) throws Exception { LOGGER.info("Initializing GeoServer specific GWC configuration from " + GWCConfigPersister.GWC_CONFIG_FILE); final Version currentVersion = new Version("1.0.0"); final File configFile = configPersister.findConfigFile(); if (configFile == null) { LOGGER.fine("GWC's GeoServer specific configuration not found, creating with old defaults"); GWCConfig oldDefaults = GWCConfig.getOldDefaults(); oldDefaults.setVersion(currentVersion.toString()); upgradeWMSIntegrationConfig(geoServer, oldDefaults); createDefaultTileLayerInfos(oldDefaults); configPersister.save(oldDefaults); } final GWCConfig config = configPersister.getConfig(); final Version version = new Version(config.getVersion()); if (currentVersion.compareTo(version) > 0) { // got the global config file, so old defaults are already in place if need be. Now // check whether we need to migrate the configuration from the Layer/GroupInfo metadata // maps to the tile layer catalog store moveTileLayerInfosToTileLayerCatalog(); config.setVersion(currentVersion.toString()); configPersister.save(config); } final GWCConfig gwcConfig = configPersister.getConfig(); checkNotNull(gwcConfig); }
@Override protected void setUp() throws Exception { configPersister = mock(GWCConfigPersister.class); when(configPersister.getConfig()).thenReturn(GWCConfig.getOldDefaults()); rawCatalog = mock(Catalog.class); tileLayerCatalog = mock(TileLayerCatalog.class); initializer = new GWCInitializer(configPersister, rawCatalog, tileLayerCatalog); geoServer = mock(GeoServer.class); }
GWCConfig oldDefaults = GWCConfig.getOldDefaults(); oldDefaults.setVersion(currentVersion.toString()); upgradeWMSIntegrationConfig(geoServer, oldDefaults); createDefaultTileLayerInfos(oldDefaults); configPersister.save(oldDefaults); moveTileLayerInfosToTileLayerCatalog(); config.setVersion(currentVersion.toString()); configPersister.save(config); CacheProvider cache = blobStore.getCache(); addLayersToNotCache(cache, gwcConfig);
public void testInitializeLayersToOldDefaults() throws Exception { // no gwc-gs.xml exists when(configPersister.findConfigFile()).thenReturn(null); // ignore the upgrade of the direct wms integration flag on this test when(geoServer.getService(eq(WMSInfo.class))).thenReturn(null); // let the catalog have something to initialize LayerInfo layer = mockLayer("testLayer", new String[]{}, LayerInfo.Type.RASTER); LayerGroupInfo group = mockGroup("testGroup", layer); when(rawCatalog.getLayers()).thenReturn(Lists.newArrayList(layer)); when(rawCatalog.getLayerGroups()).thenReturn(Lists.newArrayList(group)); // run layer initialization initializer.initialize(geoServer); // make sure default tile layers were created GWCConfig oldDefaults = GWCConfig.getOldDefaults(); GeoServerTileLayerInfo tileLayer = TileLayerInfoUtil.loadOrCreate(layer, oldDefaults); GeoServerTileLayerInfo tileLayerGroup = TileLayerInfoUtil.loadOrCreate(group, oldDefaults); verify(tileLayerCatalog, times(1)).save(eq(tileLayer)); verify(tileLayerCatalog, times(1)).save(eq(tileLayerGroup)); }
public void testUpgradeDirectWMSIntegrationFlag() throws Exception { // no gwc-gs.xml exists, so that initialization runs when(configPersister.findConfigFile()).thenReturn(null); // no catalog layers for this test List<LayerInfo> layers = ImmutableList.of(); List<LayerGroupInfo> groups = ImmutableList.of(); when(rawCatalog.getLayers()).thenReturn(layers); when(rawCatalog.getLayerGroups()).thenReturn(groups); WMSInfoImpl wmsInfo = new WMSInfoImpl(); // initialize wmsInfo with a value for the old direct wms integration flag wmsInfo.getMetadata().put(GWCInitializer.WMS_INTEGRATION_ENABLED_KEY, Boolean.TRUE); // make sure WMSInfo exists when(geoServer.getService(eq(WMSInfo.class))).thenReturn(wmsInfo); ArgumentCaptor<GWCConfig> captor = ArgumentCaptor.forClass(GWCConfig.class); // run layer initialization initializer.initialize(geoServer); verify(configPersister, times(2)).save(captor.capture()); assertTrue(captor.getAllValues().get(0).isDirectWMSIntegrationEnabled()); assertFalse(wmsInfo.getMetadata().containsKey(GWCInitializer.WMS_INTEGRATION_ENABLED_KEY)); verify(geoServer).save(same(wmsInfo)); }
initializer.initialize(geoServer);