public void testLayerGroupInfoStylesChanged() throws Exception { CatalogModifyEvent modifyEvent = mock(CatalogModifyEvent.class); when(modifyEvent.getSource()).thenReturn(mockLayerGroupInfo); when(modifyEvent.getPropertyNames()).thenReturn(Arrays.asList("styles")); List<StyleInfo> oldStyles = Collections.emptyList(); StyleInfo newStyle = mock(StyleInfo.class); List<StyleInfo> newStyles = Collections.singletonList(newStyle); when(modifyEvent.getOldValues()).thenReturn(Collections.singletonList((Object) oldStyles)); when(modifyEvent.getNewValues()).thenReturn(Collections.singletonList((Object) newStyles)); // the tile layer must exist on the layer metadata otherwise the event will be ignored GeoServerTileLayerInfo info = TileLayerInfoUtil.loadOrCreate(mockLayerGroupInfo, GWCConfig.getOldDefaults()); GeoServerTileLayer tileLayer = mock(GeoServerTileLayer.class); when(tileLayer.getInfo()).thenReturn(info); when(mockMediator.hasTileLayer(same(mockLayerGroupInfo))).thenReturn(true); when(mockMediator.getTileLayer(same(mockLayerGroupInfo))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent); CatalogPostModifyEvent postModifyEvent = mock(CatalogPostModifyEvent.class); when(postModifyEvent.getSource()).thenReturn(mockLayerGroupInfo); listener.handlePostModifyEvent(postModifyEvent); verify(mockMediator).truncate(eq(LAYER_GROUP_NAME)); }
public void testLayerGroupInfoLayersChanged() throws Exception { CatalogModifyEvent modifyEvent = mock(CatalogModifyEvent.class); when(modifyEvent.getSource()).thenReturn(mockLayerGroupInfo); when(modifyEvent.getPropertyNames()).thenReturn(Arrays.asList("layers")); List<LayerInfo> oldLayers = Collections.emptyList(); List<LayerInfo> newLayers = Collections.singletonList(mockLayerInfo); when(modifyEvent.getOldValues()).thenReturn(Collections.singletonList((Object) oldLayers)); when(modifyEvent.getNewValues()).thenReturn(Collections.singletonList((Object) newLayers)); // the tile layer must exist otherwise the event will be ignored GeoServerTileLayerInfo tileLayerInfo = TileLayerInfoUtil.loadOrCreate(mockLayerGroupInfo, mockMediator.getConfig()); GridSetBroker gridsets = new GridSetBroker(true, true); GeoServerTileLayer tileLayer = new GeoServerTileLayer(mockLayerGroupInfo, gridsets, tileLayerInfo); when(mockMediator.hasTileLayer(same(mockLayerGroupInfo))).thenReturn(true); when(mockMediator.getTileLayer(same(mockLayerGroupInfo))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent); CatalogPostModifyEvent postModifyEvent = mock(CatalogPostModifyEvent.class); when(postModifyEvent.getSource()).thenReturn(mockLayerGroupInfo); listener.handlePostModifyEvent(postModifyEvent); verify(mockMediator).truncate(eq(LAYER_GROUP_NAME)); }
public void testLayerInfoDefaultStyleChanged() throws Exception { final String oldName = "oldStyle"; final String newName = "newStyle"; StyleInfo oldStyle = mock(StyleInfo.class); when(oldStyle.getName()).thenReturn(oldName); StyleInfo newStyle = mock(StyleInfo.class); when(newStyle.getName()).thenReturn(newName); when(mockLayerInfo.getDefaultStyle()).thenReturn(newStyle); CatalogModifyEvent modifyEvent = mock(CatalogModifyEvent.class); when(modifyEvent.getSource()).thenReturn(mockLayerInfo); when(modifyEvent.getPropertyNames()).thenReturn(Arrays.asList("defaultStyle")); when(modifyEvent.getOldValues()).thenReturn(Collections.singletonList((Object) oldStyle)); when(modifyEvent.getNewValues()).thenReturn(Collections.singletonList((Object) newStyle)); GeoServerTileLayer tileLayer = mock(GeoServerTileLayer.class); when(mockMediator.getTileLayerByName(eq(PREFIXED_RESOURCE_NAME))).thenReturn(tileLayer); // the tile layer must exist on the layer metadata otherwise the event will be ignored GeoServerTileLayerInfo info = TileLayerInfoUtil.loadOrCreate(mockLayerInfo, GWCConfig.getOldDefaults()); when(tileLayer.getInfo()).thenReturn(info); when(mockMediator.hasTileLayer(same(mockLayerInfo))).thenReturn(true); when(mockMediator.getTileLayer(same(mockLayerInfo))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent); CatalogPostModifyEvent postModifyEvent = mock(CatalogPostModifyEvent.class); when(postModifyEvent.getSource()).thenReturn(mockLayerInfo); listener.handlePostModifyEvent(postModifyEvent); verify(mockMediator).truncateByLayerAndStyle(eq(PREFIXED_RESOURCE_NAME), eq(oldName)); verify(mockMediator).save(any(GeoServerTileLayer.class)); }
when(mockMediator.getTileLayer(any(CatalogInfo.class))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent);
listener.handleModifyEvent(modifyEvent);
when(mockMediator.getTileLayerByName(eq(oldTileLayerName))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent); verify(mockMediator, times(1)).hasTileLayer(same(mockResourceInfo));
when(mockMediator.getTileLayerByName(eq(oldPrefixedName))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent);
when(mockMediator.getTileLayerByName(eq(oldLayerName))).thenReturn(tileLayer); listener.handleModifyEvent(modifyEvent);