Example #1
0
  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;
  }
Example #2
0
  private void testMultipleCrsMatchingGridSubsets(
      final String srs, final String expectedGridset, long[] tileIndex) throws Exception {
    GetMapRequest request = new GetMapRequest();

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

    request.setSRS(srs);

    request.setWidth(256);
    request.setHeight(256);
    rawKvp.put("layers", "mockLayer");
    List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326");
    tileLayer = mockTileLayer("mockLayer", gridSetNames);

    // make the request match a tile in the expected gridset
    BoundingBox bounds;
    bounds = tileLayer.getGridSubset(expectedGridset).boundsFromIndex(tileIndex);

    Envelope reqBbox =
        new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY());
    request.setBbox(reqBbox);

    ArgumentCaptor<ConveyorTile> captor = ArgumentCaptor.forClass(ConveyorTile.class);
    StringBuilder errors = new StringBuilder();

    mediator.dispatch(request, errors);

    assertTrue(errors.toString(), errors.length() == 0);

    verify(tileLayer, times(1)).getTile(captor.capture());

    ConveyorTile tileRequest = captor.getValue();

    assertEquals(expectedGridset, tileRequest.getGridSetId());
    assertEquals("image/png", tileRequest.getMimeType().getMimeType());
    assertTrue(
        "Expected "
            + Arrays.toString(tileIndex)
            + " got "
            + Arrays.toString(tileRequest.getTileIndex()),
        Arrays.equals(tileIndex, tileRequest.getTileIndex()));
  }
Example #3
0
  @Test
  public void testDispatchGetMapWithMatchingParameterFilters() throws Exception {
    GetMapRequest request = new GetMapRequest();

    @SuppressWarnings("unchecked")
    Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>());
    request.setRawKvp(rawKvp);
    request.setFormat("image/png");
    request.setSRS("EPSG:900913");
    request.setWidth(256);
    request.setHeight(256);
    rawKvp.put("layers", tileLayer.getName());

    // tileLayer = mockTileLayer("mockLayer", ImmutableList.of("EPSG:900913", "EPSG:4326"));

    // make the request match a tile in the expected gridset
    BoundingBox bounds;
    bounds = tileLayer.getGridSubset("EPSG:900913").boundsFromIndex(new long[] {0, 0, 1});

    Envelope reqBbox =
        new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY());
    request.setBbox(reqBbox);

    assertTrue(tileLayer.getInfo().cachedStyles().size() > 0);

    for (String style : tileLayer.getInfo().cachedStyles()) {

      String rawKvpParamName = "styles";
      String rawKvpParamValue = style;

      testParameterFilter(request, rawKvp, rawKvpParamName, rawKvpParamValue);
    }

    request.setEnv(ImmutableMap.of("envKey", "envValue"));
    updateStringParameterFilter(
        tileLayerInfo, "ENV", true, "def:devVal", "envKey:envValue", "envKey2:envValue2");
    testParameterFilter(request, rawKvp, "env", "envKey:envValue");

    updateAcceptAllFloatParameterFilter(tileLayerInfo, "ANGLE", true);
    request.setAngle(60);
    testParameterFilter(request, rawKvp, "angle", "60.0");

    request.setAngle(61.1);
    testParameterFilter(request, rawKvp, "angle", "61.1");
  }
Example #4
0
  @Test
  public void testTruncateByBounds() throws Exception {

    String layerName = tileLayer.getName();
    ReferencedEnvelope bounds;
    // bounds outside layer bounds (which are -180,0,0,90)
    bounds = new ReferencedEnvelope(10, 20, 10, 20, DefaultGeographicCRS.WGS84);
    BoundingBox layerBounds = tileLayer.getGridSubset("EPSG:4326").getGridSet().getOriginalExtent();

    assertFalse(bounds.intersects(layerBounds.getMinX(), layerBounds.getMinY()));
    assertFalse(bounds.intersects(layerBounds.getMaxX(), layerBounds.getMaxY()));

    mediator.truncate(layerName, bounds);

    verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class));

    // bounds intersecting layer bounds
    bounds = new ReferencedEnvelope(-10, -10, 10, 10, DefaultGeographicCRS.WGS84);

    mediator.truncate(layerName, bounds);

    int numGridsets = tileLayer.getGridSubsets().size();
    int numFormats = tileLayer.getMimeTypes().size();
    int numStyles = 1 /* default */ + tileLayer.getInfo().cachedStyles().size();
    final int expected = numGridsets * numFormats * numStyles;
    verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class));

    reset(tileBreeder);
    bounds = bounds.transform(CRS.decode("EPSG:900913"), true);
    mediator.truncate(layerName, bounds);
    verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class));

    reset(tileBreeder);
    bounds = mediator.getAreaOfValidity(CRS.decode("EPSG:2083")); // Terra del Fuego
    mediator.truncate(layerName, bounds);
    verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class));

    reset(tileBreeder);
    bounds = mediator.getAreaOfValidity(CRS.decode("EPSG:26986")); // Massachussets
    mediator.truncate(layerName, bounds);
    verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class));
  }
Example #5
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();
  }