コード例 #1
0
ファイル: GWCTest.java プロジェクト: dwins/geoserver
  @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();
  }
コード例 #2
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");
          }
        }
      }
    }
コード例 #3
0
ファイル: GWCTest.java プロジェクト: dwins/geoserver
  @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));
  }
コード例 #4
0
ファイル: GWCTest.java プロジェクト: dwins/geoserver
  @Test
  public void testIsInternalGridset() {

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

    assertFalse(mediator.isInternalGridSet("somethingelse"));
  }
コード例 #5
0
ファイル: GWCTest.java プロジェクト: dwins/geoserver
  private GeoServerTileLayer mockTileLayer(String layerName, List<String> gridSetNames)
      throws Exception {

    GeoServerTileLayer tileLayer = mock(GeoServerTileLayer.class);
    when(tld.layerExists(eq(layerName))).thenReturn(true);
    when(tld.getTileLayer(eq(layerName))).thenReturn(tileLayer);
    when(tileLayer.getName()).thenReturn(layerName);
    when(tileLayer.isEnabled()).thenReturn(true);

    final MimeType mimeType1 = MimeType.createFromFormat("image/png");
    final MimeType mimeType2 = MimeType.createFromFormat("image/jpeg");
    when(tileLayer.getMimeTypes()).thenReturn(ImmutableList.of(mimeType1, mimeType2));

    Map<String, GridSubset> subsets = Maps.newHashMap();
    Multimap<SRS, GridSubset> bySrs = LinkedHashMultimap.create();

    GridSetBroker broker = gridSetBroker;

    for (String gsetName : gridSetNames) {
      GridSet gridSet = broker.get(gsetName);
      XMLGridSubset xmlGridSubset = new XMLGridSubset();
      String gridSetName = gridSet.getName();
      xmlGridSubset.setGridSetName(gridSetName);
      GridSubset gridSubSet = xmlGridSubset.getGridSubSet(broker);
      subsets.put(gsetName, gridSubSet);
      bySrs.put(gridSet.getSrs(), gridSubSet);

      when(tileLayer.getGridSubset(eq(gsetName))).thenReturn(gridSubSet);
    }
    for (SRS srs : bySrs.keySet()) {
      List<GridSubset> list = ImmutableList.copyOf(bySrs.get(srs));
      when(tileLayer.getGridSubsetsForSRS(eq(srs))).thenReturn(list);
    }
    when(tileLayer.getGridSubsets()).thenReturn(subsets.keySet());

    // sanity check
    for (String gsetName : gridSetNames) {
      assertTrue(tileLayer.getGridSubsets().contains(gsetName));
      assertNotNull(tileLayer.getGridSubset(gsetName));
    }

    return tileLayer;
  }
コード例 #6
0
ファイル: GWCTest.java プロジェクト: dwins/geoserver
  @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();
  }
コード例 #7
0
  private void contents(StringBuilder str) {
    str.append("<Contents>\n");
    Iterable<TileLayer> iter = tld.getLayerList();
    for (TileLayer layer : iter) {
      if (!layer.isEnabled()) {
        continue;
      }
      layer(str, layer, baseUrl);
    }

    for (GridSet gset : gsb.getGridSets()) {
      tileMatrixSet(str, gset);
    }

    str.append("</Contents>\n");
  }
コード例 #8
0
ファイル: GWCTest.java プロジェクト: dwins/geoserver
 @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"));
   }
 }
コード例 #9
0
  GridSubset findBestGridSubset(WMSMapContent map) {
    GetMapRequest req = map.getRequest();
    Map formatOpts = req.getFormatOptions();

    GridSetBroker gridSetBroker = gwc.getGridSetBroker();
    GridSet gridSet = null;

    // first check format options to see if explicitly specified
    if (formatOpts.containsKey("gridset")) {
      gridSet = gridSetBroker.get(formatOpts.get("gridset").toString());
    }

    // next check srs
    if (gridSet == null) {
      gridSet = gridSetBroker.get(req.getSRS().toUpperCase());
    }

    if (gridSet != null) {
      return GridSubsetFactory.createGridSubSet(gridSet);
    }

    CoordinateReferenceSystem crs = map.getCoordinateReferenceSystem();

    // look up epsg code
    Integer epsgCode = null;
    try {
      epsgCode = CRS.lookupEpsgCode(crs, false);
    } catch (Exception e) {
      throw new ServiceException("Unable to determine epsg code for " + crs, e);
    }
    if (epsgCode == null) {
      throw new ServiceException("Unable to determine epsg code for " + crs);
    }

    SRS srs = SRS.getSRS(epsgCode);

    // figure out the appropriate grid sub set
    Set<GridSubset> gridSubsets = new LinkedHashSet<GridSubset>();
    for (MapLayerInfo l : req.getLayers()) {
      TileLayer tl = gwc.getTileLayerByName(l.getName());
      if (tl == null) {
        throw new ServiceException("No tile layer for " + l.getName());
      }

      List<GridSubset> theseGridSubsets = tl.getGridSubsetsForSRS(srs);
      if (gridSubsets.isEmpty()) {
        gridSubsets.addAll(theseGridSubsets);
      } else {
        gridSubsets.retainAll(theseGridSubsets);
      }

      if (gridSubsets.isEmpty()) {
        throw new ServiceException(
            "No suitable " + epsgCode + " grid subset for " + req.getLayers());
      }
    }

    if (gridSubsets.size() > 1) {
      if (LOGGER.isLoggable(Level.WARNING)) {
        StringBuilder msg = new StringBuilder("Found multiple grid subsets: ");
        for (GridSubset gs : gridSubsets) {
          msg.append(gs.getName()).append(", ");
        }
        msg.setLength(msg.length() - 2);
        msg.append(". Choosing first.");
        LOGGER.warning(msg.toString());
      }
    }

    return gridSubsets.iterator().next();
  }