Esempio n. 1
0
  @Test
  public void testRemoveTileLayers() throws Exception {
    try {
      mediator.removeTileLayers(null);
    } catch (NullPointerException e) {
      assertTrue(true);
    }

    when(tld.removeLayer(eq(tileLayer.getName()))).thenReturn(config);
    when(tld.removeLayer(eq(tileLayerGroup.getName()))).thenReturn(config);

    List<String> layerNames = Arrays.asList(tileLayer.getName(), tileLayerGroup.getName());
    mediator.removeTileLayers(layerNames);
    verify(tld, times(1)).removeLayer(eq(tileLayer.getName()));
    verify(tld, times(1)).removeLayer(eq(tileLayerGroup.getName()));
    verify(config, times(1)).save();
  }
  /**
   * @see
   *     org.geoserver.catalog.event.CatalogListener#handleRemoveEvent(org.geoserver.catalog.event.CatalogRemoveEvent)
   * @see GWC#removeTileLayers(List)
   */
  public void handleRemoveEvent(CatalogRemoveEvent event) throws CatalogException {
    CatalogInfo obj = event.getSource();
    if (!(obj instanceof LayerInfo || obj instanceof LayerGroupInfo)) {
      return;
    }
    if (!mediator.hasTileLayer(obj)) {
      return;
    }

    String prefixedName = null;

    if (obj instanceof LayerGroupInfo) {
      LayerGroupInfo lgInfo = (LayerGroupInfo) obj;
      prefixedName = tileLayerName(lgInfo);
    } else if (obj instanceof LayerInfo) {
      LayerInfo layerInfo = (LayerInfo) obj;
      prefixedName = tileLayerName(layerInfo);
    }

    if (null != prefixedName) {
      // notify the layer has been removed
      mediator.removeTileLayers(Arrays.asList(prefixedName));
    }
  }