Example #1
0
  @Test
  public void testModifyTileLayer() throws Exception {
    try {
      mediator.save(null);
      fail();
    } catch (NullPointerException e) {
      assertTrue(true);
    }

    when(tld.modify(same(tileLayer))).thenThrow(new IllegalArgumentException());
    try {
      mediator.save(tileLayer);
      fail();
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    when(tld.modify(same(tileLayerGroup))).thenReturn(config);
    mediator.save(tileLayerGroup);
    verify(config, times(1)).save();

    when(tld.modify(same(tileLayer))).thenReturn(config);
    doThrow(new IOException()).when(config).save();
    try {
      mediator.save(tileLayer);
    } catch (RuntimeException e) {
      assertTrue(true);
    }
  }
Example #2
0
  /** See GEOS-5003 */
  @Test
  public void testNullsInDimensionAndTimeParameters() throws Exception {
    TileLayerInfoUtil.updateAcceptAllFloatParameterFilter(tileLayerInfo, "ELEVATION", true);
    TileLayerInfoUtil.updateAcceptAllRegExParameterFilter(tileLayerInfo, "TIME", true);
    tileLayer = new GeoServerTileLayer(layer, gridSetBroker, tileLayerInfo);

    GetMapRequest request = new GetMapRequest();
    @SuppressWarnings("unchecked")
    Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>());
    request.setRawKvp(rawKvp);

    StringBuilder target = new StringBuilder();

    boolean cachingPossible;

    request.setElevation(Arrays.asList((Object) null));
    cachingPossible = mediator.isCachingPossible(tileLayer, request, target);
    assertTrue(cachingPossible);
    assertEquals(0, target.length());
    request.setElevation(Collections.emptyList());

    request.setTime(Arrays.asList((Object) null));
    cachingPossible = mediator.isCachingPossible(tileLayer, request, target);
    assertTrue(cachingPossible);
    assertEquals(0, target.length());
  }
Example #3
0
  @Test
  public void testModifyGridsetTruncates() throws Exception {
    final String oldName = "EPSG:4326";
    final String newName = "MyEPSG:4326";

    final GridSet oldGridset = gridSetBroker.get(oldName);
    final GridSet newGridset;
    {
      XMLGridSet xmlGridSet = new XMLGridSet(oldGridset);
      xmlGridSet.setName(newName);

      // make it so the gridset forces truncation
      xmlGridSet.setAlignTopLeft(!xmlGridSet.getAlignTopLeft());
      newGridset = xmlGridSet.makeGridSet();
    }

    XMLConfiguration xmlConfig = mock(XMLConfiguration.class);
    mediator = spy(mediator);
    when(mediator.getXmlConfiguration()).thenReturn(xmlConfig);
    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);

    mediator.modifyGridSet(oldName, newGridset);

    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq(oldName));
    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayerGroup.getName()), eq(oldName));
  }
 /**
  * LayerInfo has been created, add a matching {@link GeoServerTileLayer}
  *
  * @see CatalogLayerEventListener#handleAddEvent
  * @see GWC#add(GeoServerTileLayer)
  */
 void createTileLayer(final LayerInfo layerInfo) {
   GWCConfig defaults = mediator.getConfig();
   if (defaults.isSane() && defaults.isCacheLayersByDefault()) {
     GridSetBroker gridSetBroker = mediator.getGridSetBroker();
     GeoServerTileLayer tileLayer = new GeoServerTileLayer(layerInfo, defaults, gridSetBroker);
     mediator.add(tileLayer);
   }
 }
Example #5
0
  @Test
  public void testIsInternalGridset() {

    Set<String> embeddedNames = gridSetBroker.getEmbeddedNames();
    for (String name : embeddedNames) {
      assertTrue(mediator.isInternalGridSet(name));
    }

    assertFalse(mediator.isInternalGridSet("somethingelse"));
  }
Example #6
0
  /**
   * Creates the {@link RenderedImage} corresponding to the tile at index {@code tileIdx} and uses a
   * {@link RenderedImageMapResponse} to encode it into the {@link #getResponseFormat() response
   * format}.
   *
   * @see org.geowebcache.layer.MetaTile#writeTileToStream(int, org.geowebcache.io.Resource)
   * @see RenderedImageMapResponse#write
   */
  @Override
  public boolean writeTileToStream(final int tileIdx, Resource target) throws IOException {

    checkNotNull(metaTileMap, "webMap is not set");
    if (!(metaTileMap instanceof RenderedImageMap)) {
      throw new IllegalArgumentException(
          "Only RenderedImageMaps are supported so far: " + metaTileMap.getClass().getName());
    }
    final RenderedImageMapResponse mapEncoder;
    {
      final GWC mediator = GWC.get();
      final Response responseEncoder = mediator.getResponseEncoder(responseFormat, metaTileMap);
      mapEncoder = (RenderedImageMapResponse) responseEncoder;
    }

    RenderedImage tile = metaTileMap.getImage();
    WMSMapContent tileContext = metaTileMap.getMapContext();

    if (this.tiles.length > 1 || (this.tiles.length == 1 && metaHasGutter())) {
      final Rectangle tileDim = this.tiles[tileIdx];
      tile = createTile(tileDim.x, tileDim.y, tileDim.width, tileDim.height);
      disposeLater(tile);
      {
        final WMSMapContent metaTileContext = metaTileMap.getMapContext();
        // do not create tileContext with metaTileContext.getLayers() as the layer list.
        // It is not needed at this stage and the constructor would force a
        // MapLayer.getBounds() that might fail
        tileContext = new WMSMapContent();
        tileContext.setRequest(metaTileContext.getRequest());
        tileContext.setBgColor(metaTileContext.getBgColor());
        tileContext.setMapWidth(tileDim.width);
        tileContext.setMapHeight(tileDim.height);
        tileContext.setPalette(metaTileContext.getPalette());
        tileContext.setTransparent(tileContext.isTransparent());
        long[][] tileIndexes = getTilesGridPositions();
        BoundingBox tileBounds = gridSubset.boundsFromIndex(tileIndexes[tileIdx]);
        ReferencedEnvelope tilebbox =
            new ReferencedEnvelope(metaTileContext.getCoordinateReferenceSystem());
        tilebbox.init(
            tileBounds.getMinX(), tileBounds.getMaxX(), tileBounds.getMinY(), tileBounds.getMaxY());
        tileContext.getViewport().setBounds(tilebbox);
      }
    }

    OutputStream outStream = target.getOutputStream();
    try {
      // call formatImageOuputStream instead of write to avoid disposition of rendered images
      // when processing a tile from a metatile and instead defer it to this class' dispose()
      // method
      mapEncoder.formatImageOutputStream(tile, outStream, tileContext);
      return true;
    } finally {
      outStream.close();
    }
  }
Example #7
0
 @Test
 public void testReload() throws Exception {
   mediator.reload();
   verify(tld, times(1)).reInit();
   doThrow(new RuntimeException("fake")).when(tld).reInit();
   try {
     mediator.reload();
     fail("Expected RTE");
   } catch (RuntimeException e) {
     assertTrue(true);
   }
 }
Example #8
0
  @Test
  public void testTruncateLayerFully() throws Exception {

    when(tld.getTileLayer(eq(tileLayerGroup.getName())))
        .thenThrow(new GeoWebCacheException("fake"));

    mediator.truncate(tileLayerGroup.getName());
    verify(storageBroker, never()).deleteByGridSetId(anyString(), anyString());

    mediator.truncate(tileLayer.getName());
    verify(storageBroker, times(tileLayer.getGridSubsets().size()))
        .deleteByGridSetId(anyString(), anyString());
  }
Example #9
0
  @Test
  public void testLayerRemoved() throws Exception {
    mediator.layerRemoved("someLayer");
    verify(storageBroker, times(1)).delete(eq("someLayer"));

    doThrow(new StorageException("fake")).when(storageBroker).delete(eq("anotherLayer"));
    try {
      mediator.layerRemoved("anotherLayer");
      fail("Expected RTE");
    } catch (RuntimeException e) {
      assertTrue(e.getCause() instanceof StorageException);
    }
  }
Example #10
0
    @Override
    public void validate(IValidatable<Set<XMLGridSubset>> validatable) {
      if (!validate) {
        return;
      }
      Set<XMLGridSubset> gridSubsets = validatable.getValue();
      if (gridSubsets == null || gridSubsets.size() == 0) {
        error(validatable, "GridSubsetsEditor.validation.empty");
        return;
      }

      final GWC gwc = GWC.get();
      for (XMLGridSubset subset : gridSubsets) {
        final String gridSetName = subset.getGridSetName();
        final Integer zoomStart = subset.getZoomStart();
        final Integer zoomStop = subset.getZoomStop();
        final BoundingBox extent = subset.getExtent();

        if (gridSetName == null) {
          throw new IllegalStateException("GridSet name is null");
        }

        if (zoomStart != null && zoomStop != null) {
          if (zoomStart.intValue() > zoomStop.intValue()) {
            error(validatable, "GridSubsetsEditor.validation.zoomLevelsError");
            return;
          }
        }

        final GridSetBroker gridSetBroker = gwc.getGridSetBroker();
        final GridSet gridSet = gridSetBroker.get(gridSetName);

        if (null == gridSet) {
          error(validatable, "GridSubsetsEditor.validation.gridSetNotFound", gridSetName);
          return;
        }

        if (extent != null) {
          if (extent.isNull() || !extent.isSane()) {
            error(validatable, "GridSubsetsEditor.validation.invalidBounds");
          }
          final BoundingBox fullBounds = gridSet.getOriginalExtent();
          final boolean intersects = fullBounds.intersects(extent);
          if (!intersects) {
            error(validatable, "GridSubsetsEditor.validation.boundsOutsideCoverage");
          }
        }
      }
    }
Example #11
0
  @Test
  public void testRemoveGridsets() throws Exception {
    try {
      mediator.removeGridSets(null);
      fail();
    } catch (NullPointerException e) {
      assertTrue(true);
    }

    {
      final GridSet oldGridset = gridSetBroker.get("EPSG:4326");
      final GridSet newGridset;
      XMLGridSet xmlGridSet = new XMLGridSet(oldGridset);
      xmlGridSet.setName("My4326");
      // make it a bit different
      xmlGridSet.setAlignTopLeft(!xmlGridSet.getAlignTopLeft());
      newGridset = xmlGridSet.makeGridSet();
      gridSetBroker.put(newGridset);
    }

    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    when(tld.modify(same(tileLayer))).thenReturn(config);
    when(tld.modify(same(tileLayerGroup))).thenReturn(config);
    when(tld.removeGridset(eq("EPSG:4326"))).thenReturn(config);
    when(tld.removeGridset(eq("My4326"))).thenReturn(config);

    mediator.removeGridSets(ImmutableSet.of("My4326", "EPSG:4326"));

    assertEquals(ImmutableSet.of("EPSG:900913"), tileLayer.getGridSubsets());
    assertEquals(ImmutableSet.of("EPSG:900913"), tileLayerGroup.getGridSubsets());

    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326"));
    verify(storageBroker, times(1))
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:4326"));

    verify(storageBroker, never()).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:900913"));
    verify(storageBroker, never()).deleteByGridSetId(eq(tileLayer.getName()), eq("My4326"));
    verify(storageBroker, never())
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913"));
    verify(storageBroker, never()).deleteByGridSetId(eq(tileLayerGroup.getName()), eq("My4326"));

    verify(tld, times(1)).modify(same(tileLayer));
    verify(tld, times(1)).modify(same(tileLayerGroup));
    verify(tld, times(1)).removeGridset(eq("EPSG:4326"));
    verify(tld, times(1)).removeGridset(eq("My4326"));
    // all these modifications, and a single save()
    verify(config, times(1)).save();
  }
Example #12
0
  @Test
  public void testDeleteCacheByGridSetId() throws Exception {

    when(storageBroker.deleteByGridSetId(eq("layer"), eq("gset1")))
        .thenThrow(new StorageException("fake"));

    try {
      mediator.deleteCacheByGridSetId("layer", "gset1");
      fail();
    } catch (RuntimeException e) {
      assertTrue(true);
    }
    mediator.deleteCacheByGridSetId("layer", "gset2");
    verify(storageBroker, times(1)).deleteByGridSetId(eq("layer"), eq("gset2"));
  }
Example #13
0
  public void testAddTileLayer() throws Exception {

    when(tld.addLayer(same(tileLayer))).thenThrow(new IllegalArgumentException("fake"));
    when(tld.addLayer(same(tileLayerGroup))).thenReturn(config);

    try {
      mediator.add(tileLayer);
      fail("Expected IAE");
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    mediator.add(tileLayerGroup);
    verify(config, times(1)).save();
  }
Example #14
0
  @Test
  public void testTruncateByLayerAndStyle() throws Exception {

    String layerName = tileLayer.getName();
    String styleName = "notACachedStyle";

    mediator.truncateByLayerAndStyle(layerName, styleName);
    verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class));

    styleName = layer.getDefaultStyle().getName();
    mediator.truncateByLayerAndStyle(layerName, styleName);

    int expected = tileLayer.getGridSubsets().size() * tileLayer.getMimeTypes().size();
    verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class));
  }
Example #15
0
  @Test
  public void testAutoConfigureLayers() throws Exception {
    {
      GWCConfig insaneDefaults = new GWCConfig();
      insaneDefaults.setMetaTilingX(-1);
      assertFalse(insaneDefaults.isSane());
      try {
        mediator.autoConfigureLayers(Arrays.asList(tileLayer.getName()), insaneDefaults);
      } catch (IllegalArgumentException e) {
        assertTrue(true);
      }
    }

    try {
      mediator.autoConfigureLayers(Arrays.asList(tileLayer.getName()), defaults);
      fail("expected IAE, layer exists");
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    LayerInfo layer2 = mockLayer("layer2", new String[] {}, PublishedType.RASTER);
    LayerGroupInfo group2 = mockGroup("group2", layer, layer2);

    when(catalog.getLayerByName(eq(tileLayerName(layer2)))).thenReturn(layer2);
    when(catalog.getLayerGroupByName(eq(tileLayerName(group2)))).thenReturn(group2);

    List<String> layerNames = Arrays.asList(tileLayerName(layer2), tileLayerName(group2));

    when(tld.addLayer(any(GeoServerTileLayer.class))).thenReturn(config);
    mediator.autoConfigureLayers(layerNames, defaults);

    GeoServerTileLayerInfo expected1 =
        new GeoServerTileLayer(layer2, defaults, gridSetBroker).getInfo();
    GeoServerTileLayerInfo expected2 =
        new GeoServerTileLayer(group2, defaults, gridSetBroker).getInfo();

    ArgumentCaptor<GeoServerTileLayer> addCaptor =
        ArgumentCaptor.forClass(GeoServerTileLayer.class);

    verify(tld, times(2)).addLayer(addCaptor.capture());
    verify(config, times(2)).save();

    GeoServerTileLayerInfo actual1 = addCaptor.getAllValues().get(0).getInfo();
    GeoServerTileLayerInfo actual2 = addCaptor.getAllValues().get(1).getInfo();

    assertEquals(expected1, actual1);
    assertEquals(expected2, actual2);
  }
Example #16
0
  @Test
  public void testRemoveAllLayerGridsetsDisablesLayer() throws Exception {

    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    when(tld.modify(same(tileLayer))).thenReturn(config);
    when(tld.modify(same(tileLayerGroup))).thenReturn(config);
    when(tld.removeGridset(eq("EPSG:4326"))).thenReturn(config);
    when(tld.removeGridset(eq("EPSG:900913"))).thenReturn(config);

    // sanity check before modification
    assertTrue(tileLayer.getInfo().isEnabled());
    assertTrue(tileLayer.getInfo().isEnabled());

    mediator.removeGridSets(ImmutableSet.of("EPSG:900913", "EPSG:4326"));

    verify(config, times(1)).save(); // all other checks are in testRemoveGridsets
    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326"));
    verify(storageBroker, times(1))
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913"));
    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326"));
    verify(storageBroker, times(1))
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913"));

    assertTrue(tileLayer.getGridSubsets().isEmpty());
    assertTrue(tileLayerGroup.getGridSubsets().isEmpty());

    // layers ended up with no gridsubsets, shall have been disabled
    assertFalse(tileLayer.getInfo().isEnabled());
    assertFalse(tileLayerGroup.getInfo().isEnabled());
  }
  private void handleLayerGroupInfoChange(
      final List<String> changedProperties,
      final List<Object> oldValues,
      final List<Object> newValues,
      final LayerGroupInfo lgInfo,
      final GeoServerTileLayerInfo tileLayerInfo) {

    checkNotNull(lgInfo);
    checkNotNull(tileLayerInfo);

    final String layerName = tileLayerName(lgInfo);

    boolean truncate = false;
    if (changedProperties.contains("layers")) {
      final int layersIndex = changedProperties.indexOf("layers");
      Object oldLayers = oldValues.get(layersIndex);
      Object newLayers = newValues.get(layersIndex);
      truncate = !oldLayers.equals(newLayers);
    }

    if (!truncate && changedProperties.contains("styles")) {
      final int stylesIndex = changedProperties.indexOf("styles");
      Object oldStyles = oldValues.get(stylesIndex);
      Object newStyles = newValues.get(stylesIndex);
      truncate = !oldStyles.equals(newStyles);
    }
    if (truncate) {
      log.info(
          "Truncating TileLayer for layer group '"
              + layerName
              + "' due to a change in its layers or styles");
      mediator.truncate(layerName);
    }
  }
Example #18
0
  @Test
  public void testReloadAndLayerRemovedExternally() throws Exception {

    final String removedLayer = tileLayer.getName();
    final String remainingLayer = tileLayerGroup.getName();

    final Set<String> layerNames = Sets.newHashSet(removedLayer, remainingLayer);

    when(tld.getLayerNames()).thenReturn(layerNames);
    doAnswer(
            new Answer<Void>() {

              @Override
              public Void answer(InvocationOnMock invocation) throws Throwable {
                layerNames.remove(removedLayer);
                return null;
              }
            })
        .when(tld)
        .reInit();

    ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);

    mediator = spy(mediator);
    doReturn(true).when(mediator).layerRemoved(argCaptor.capture());

    mediator.reload();

    verify(tld, times(1)).reInit();
    assertEquals(1, argCaptor.getAllValues().size());
    assertEquals(removedLayer, argCaptor.getValue());
  }
Example #19
0
  @Test
  public void testLayerRenamed() throws Exception {

    mediator.layerRenamed("old", "new");
    verify(storageBroker, times(1)).rename(eq("old"), eq("new"));

    doThrow(new StorageException("target directory already exists"))
        .when(storageBroker)
        .rename(eq("old"), eq("new"));
    try {
      mediator.layerRenamed("old", "new");
      fail("Expected RTE");
    } catch (RuntimeException e) {
      assertTrue(e.getCause() instanceof StorageException);
    }
  }
Example #20
0
  private void assertDispatchMismatch(GetMapRequest request, String expectedReason) {

    StringBuilder target = new StringBuilder();
    assertNull(mediator.dispatch(request, target));
    assertTrue(
        "mismatch reason '" + target + "' does not contain '" + expectedReason + "'",
        target.toString().contains(expectedReason));
  }
Example #21
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();
  }
Example #22
0
  @Test
  public void testIsServiceEnabled() {
    Service service = mock(Service.class);

    when(service.getPathName()).thenReturn("wms");
    defaults.setWMSCEnabled(true);
    assertTrue(mediator.isServiceEnabled(service));
    defaults.setWMSCEnabled(false);
    assertFalse(mediator.isServiceEnabled(service));

    when(service.getPathName()).thenReturn("tms");
    defaults.setTMSEnabled(true);
    assertTrue(mediator.isServiceEnabled(service));
    defaults.setTMSEnabled(false);
    assertFalse(mediator.isServiceEnabled(service));

    when(service.getPathName()).thenReturn("wmts");
    defaults.setWMTSEnabled(true);
    assertTrue(mediator.isServiceEnabled(service));
    defaults.setWMTSEnabled(false);
    assertFalse(mediator.isServiceEnabled(service));

    when(service.getPathName()).thenReturn("somethingElse");
    assertTrue(mediator.isServiceEnabled(service));
  }
Example #23
0
  @Test
  public void testLayerAdded() throws Exception {

    when(diskQuotaMonitor.isEnabled()).thenReturn(false);
    mediator.layerAdded("someLayer");
    verify(quotaStore, never()).createLayer(anyString());

    when(diskQuotaMonitor.isEnabled()).thenReturn(true);

    mediator.layerAdded("someLayer");
    verify(quotaStore, times(1)).createLayer(eq("someLayer"));

    doThrow(new InterruptedException("fake")).when(quotaStore).createLayer(eq("someLayer"));
    try {
      mediator.layerAdded("someLayer");
      fail("Expected RTE");
    } catch (RuntimeException e) {
      assertTrue(e.getCause() instanceof InterruptedException);
    }
  }
Example #24
0
 @Test
 public void testAddGridset() throws Exception {
   try {
     mediator.addGridSet(null);
     fail();
   } catch (NullPointerException e) {
     assertTrue(true);
   }
   GridSet gset = mock(GridSet.class);
   GridSet gset2 = mock(GridSet.class);
   doThrow(new IOException("fake")).when(tld).addGridSet(same(gset));
   try {
     mediator.addGridSet(gset);
     fail();
   } catch (IOException e) {
     assertEquals("fake", e.getMessage());
   }
   mediator.addGridSet(gset2);
   verify(tld, times(1)).addGridSet(same(gset2));
 }
  /**
   * @see
   *     org.geoserver.catalog.event.CatalogListener#handleModifyEvent(org.geoserver.catalog.event.CatalogModifyEvent)
   * @see #handlePostModifyEvent
   */
  public void handleModifyEvent(CatalogModifyEvent event) throws CatalogException {
    CatalogInfo source = event.getSource();
    if (source instanceof LayerInfo
        || source instanceof LayerGroupInfo
        || source instanceof FeatureTypeInfo
        || source instanceof CoverageInfo
        || source instanceof WMSLayerInfo) {
      PRE_MODIFY_EVENT.set(event);

      if (mediator.hasTileLayer(source)) {
        try {
          GeoServerTileLayer tileLayer = mediator.getTileLayer(source);
          GeoServerTileLayerInfo tileLayerInfo = tileLayer.getInfo();
          PRE_MODIFY_TILELAYER.set(tileLayerInfo);
        } catch (RuntimeException e) {
          log.info("Ignoring misconfigured tile layer info for " + source);
        }
      }
    }
  }
Example #26
0
 @Test
 public void testModifyGridsetPreconditions() throws Exception {
   GridSet oldGridset = gridSetBroker.get("EPSG:4326");
   try {
     mediator.modifyGridSet(null, oldGridset);
     fail();
   } catch (NullPointerException e) {
     assertTrue(true);
   }
   try {
     mediator.modifyGridSet("oldname", null);
     fail();
   } catch (NullPointerException e) {
     assertTrue(true);
   }
   try {
     mediator.modifyGridSet("wrongOldName", oldGridset);
     fail();
   } catch (IllegalArgumentException e) {
     assertTrue(e.getMessage().contains("does not exist"));
   }
 }
Example #27
0
  @Test
  public void testDestroy() throws Exception {

    mediator.destroy();

    ArgumentCaptor<CatalogListener> captor = ArgumentCaptor.forClass(CatalogListener.class);
    verify(catalog, times(2)).removeListener(captor.capture());
    for (CatalogListener captured : captor.getAllValues()) {
      assertTrue(
          captured instanceof CatalogLayerEventListener
              || captured instanceof CatalogStyleChangeListener);
    }
  }
Example #28
0
  @Test
  public void testModifyGridsetNoNeedToTruncate() throws Exception {
    final String oldName = "EPSG:4326";
    final String newName = "MyEPSG:4326";

    final GridSet oldGridset = gridSetBroker.get(oldName);
    final GridSet newGridset;
    {
      XMLGridSet xmlGridSet = new XMLGridSet(oldGridset);
      xmlGridSet.setName(newName);
      newGridset = xmlGridSet.makeGridSet();
    }

    XMLConfiguration xmlConfig = mock(XMLConfiguration.class);
    mediator = spy(mediator);
    when(mediator.getXmlConfiguration()).thenReturn(xmlConfig);

    assertNotNull(tileLayer.getGridSubset(oldName));
    assertNotNull(tileLayerGroup.getGridSubset(oldName));

    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    mediator.modifyGridSet(oldName, newGridset);

    assertNull(tileLayer.getGridSubset(oldName));
    assertNull(tileLayerGroup.getGridSubset(oldName));
    assertNotNull(tileLayer.getGridSubset(newName));
    assertNotNull(tileLayerGroup.getGridSubset(newName));

    verify(xmlConfig, times(1)).removeGridset(eq(oldName));
    verify(xmlConfig, times(1)).addOrReplaceGridSet(eq(new XMLGridSet(newGridset)));
    verify(xmlConfig, times(1)).save();

    assertNull(gridSetBroker.get(oldName));
    assertEquals(newGridset, gridSetBroker.get(newName));

    verify(config, times(1)).save();
  }
Example #29
0
  @Before
  public void setUp() throws Exception {
    catalog = mock(Catalog.class);
    layer = mockLayer("testLayer", new String[] {"style1", "style2"}, PublishedType.RASTER);
    layerGroup = mockGroup("testGroup", layer);
    mockCatalog();

    defaults = GWCConfig.getOldDefaults();

    gwcConfigPersister = mock(GWCConfigPersister.class);
    when(gwcConfigPersister.getConfig()).thenReturn(defaults);

    storageBroker = mock(StorageBroker.class);
    gridSetBroker = new GridSetBroker(true, true);

    tileLayerInfo = TileLayerInfoUtil.loadOrCreate(layer, defaults);
    tileLayerGroupInfo = TileLayerInfoUtil.loadOrCreate(layerGroup, defaults);

    tileLayer = new GeoServerTileLayer(layer, gridSetBroker, tileLayerInfo);
    tileLayerGroup = new GeoServerTileLayer(layerGroup, gridSetBroker, tileLayerGroupInfo);

    tld = mock(TileLayerDispatcher.class);
    mockTileLayerDispatcher();

    config = mock(Configuration.class);
    tileBreeder = mock(TileBreeder.class);
    quotaStore = mock(QuotaStore.class);
    diskQuotaMonitor = mock(DiskQuotaMonitor.class);
    when(diskQuotaMonitor.getQuotaStore()).thenReturn(quotaStore);
    owsDispatcher = mock(Dispatcher.class);

    storageFinder = mock(DefaultStorageFinder.class);
    jdbcStorage = mock(JDBCConfigurationStorage.class);

    mediator =
        new GWC(
            gwcConfigPersister,
            storageBroker,
            tld,
            gridSetBroker,
            tileBreeder,
            diskQuotaMonitor,
            owsDispatcher,
            catalog,
            storageFinder,
            jdbcStorage);

    GWC.set(mediator);
  }
  /**
   * @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));
    }
  }