Esempio n. 1
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());
  }
Esempio n. 2
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));
  }
Esempio n. 3
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());
  }
Esempio n. 4
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());
  }
Esempio n. 5
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();
  }
Esempio n. 6
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);
  }
Esempio n. 7
0
  @Test
  public void testDispatchGetMapDoesntMatchTileCache() throws Exception {
    GetMapRequest request = new GetMapRequest();

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

    rawKvp.put("layers", "more,than,one,layer");
    assertDispatchMismatch(request, "more than one layer requested");

    rawKvp.put("layers", "SomeNonCachedLayer");
    when(tld.getTileLayer(eq("SomeNonCachedLayer")))
        .thenThrow(new GeoWebCacheException("layer not found"));
    assertDispatchMismatch(request, "not a tile layer");

    rawKvp.put("layers", tileLayer.getName());

    request.setFormat("badFormat");
    assertDispatchMismatch(request, "not a GWC supported format");

    request.setFormat("image/gif");
    assertDispatchMismatch(request, "no tile cache for requested format");
    request.setFormat(tileLayer.getMimeTypes().get(0).getMimeType());

    request.setSRS("EPSG:4326");
    request.setBbox(new Envelope(10, 10, 20, 20));
    assertDispatchMismatch(request, "request does not align to grid");

    request.setSRS("EPSG:23036");
    assertDispatchMismatch(request, "no cache exists for requested CRS");

    request.setSRS("badCRS");
    assertDispatchMismatch(request, "exception occurred");
    request.setSRS("EPSG:4326");

    request.setWidth(128);
    request.setHeight(256);
    assertDispatchMismatch(request, "request does not align to grid");

    request.setWidth(256);
    request.setHeight(128);
    assertDispatchMismatch(request, "request does not align to grid");

    request.setSRS("EPSG:4326");
    request.setWidth(256);
    request.setHeight(256);
    assertDispatchMismatch(request, "request does not align to grid");
  }
Esempio n. 8
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));
  }
Esempio n. 9
0
  private void mockTileLayerDispatcher() throws Exception {
    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    when(tld.getConfiguration(eq(tileLayer.getName()))).thenReturn(config);
    when(tld.getConfiguration(eq(tileLayerGroup.getName()))).thenReturn(config);

    when(tld.getTileLayer(eq(tileLayer.getName()))).thenReturn(tileLayer);
    when(tld.getTileLayer(eq(tileLayerGroup.getName()))).thenReturn(tileLayerGroup);

    when(tld.getLayerNames())
        .thenReturn(ImmutableSet.of(tileLayer.getName(), tileLayerGroup.getName()));
    Iterable<TileLayer> tileLayers =
        ImmutableList.of((TileLayer) tileLayer, (TileLayer) tileLayerGroup);
    when(tld.getLayerList()).thenReturn(tileLayers);

    when(tld.layerExists(eq(tileLayer.getName()))).thenReturn(true);
    when(tld.layerExists(eq(tileLayerGroup.getName()))).thenReturn(true);
  }
Esempio n. 10
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");
  }
Esempio n. 11
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;
  }
Esempio n. 12
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));
  }
Esempio n. 13
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();
  }
Esempio n. 14
0
  @Test
  public void testDispatchGetMapNonMatchingParameterFilter() throws Exception {
    GetMapRequest request = new GetMapRequest();

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

    rawKvp.put("layers", tileLayer.getName());
    tileLayer.setEnabled(false);
    assertDispatchMismatch(request, "tile layer disabled");

    tileLayer.setEnabled(true);
    assertTrue(layer.enabled());

    request.setRemoteOwsURL(new URL("http://example.com"));
    assertDispatchMismatch(request, "remote OWS");
    request.setRemoteOwsURL(null);

    request.setRemoteOwsType("WFS");
    assertDispatchMismatch(request, "remote OWS");
    request.setRemoteOwsType(null);

    request.setEnv(ImmutableMap.of("envVar", "envValue"));
    assertDispatchMismatch(request, "no parameter filter exists for ENV");
    request.setEnv(null);

    request.setFormatOptions(ImmutableMap.of("optKey", "optVal"));
    assertDispatchMismatch(request, "no parameter filter exists for FORMAT_OPTIONS");
    request.setFormatOptions(null);

    request.setAngle(45);
    assertDispatchMismatch(request, "no parameter filter exists for ANGLE");
    request.setAngle(0);

    rawKvp.put("BGCOLOR", "0xAA0000");
    assertDispatchMismatch(request, "no parameter filter exists for BGCOLOR");
    rawKvp.remove("BGCOLOR");

    request.setBuffer(10);
    assertDispatchMismatch(request, "no parameter filter exists for BUFFER");
    request.setBuffer(0);

    request.setCQLFilter(Arrays.asList(CQL.toFilter("ATT = 1")));
    assertDispatchMismatch(request, "no parameter filter exists for CQL_FILTER");
    request.setCQLFilter(null);

    request.setElevation(10D);
    assertDispatchMismatch(request, "no parameter filter exists for ELEVATION");
    request.setElevation(Collections.emptyList());

    request.setFeatureId(Arrays.asList(new FeatureIdImpl("someid")));
    assertDispatchMismatch(request, "no parameter filter exists for FEATUREID");
    request.setFeatureId(null);

    request.setFilter(Arrays.asList(CQL.toFilter("ATT = 1")));
    assertDispatchMismatch(request, "no parameter filter exists for FILTER");
    request.setFilter(null);

    request.setPalette(PaletteManager.getPalette("SAFE"));
    assertDispatchMismatch(request, "no parameter filter exists for PALETTE");
    request.setPalette(null);

    request.setStartIndex(10);
    assertDispatchMismatch(request, "no parameter filter exists for STARTINDEX");
    request.setStartIndex(null);

    request.setMaxFeatures(1);
    assertDispatchMismatch(request, "no parameter filter exists for MAXFEATURES");
    request.setMaxFeatures(null);

    request.setTime(Arrays.asList((Object) 1, (Object) 2));
    assertDispatchMismatch(request, "no parameter filter exists for TIME");
    request.setTime(Collections.emptyList());

    List<Map<String, String>> viewParams =
        ImmutableList.of((Map<String, String>) ImmutableMap.of("paramKey", "paramVal"));
    request.setViewParams(viewParams);
    assertDispatchMismatch(request, "no parameter filter exists for VIEWPARAMS");
    request.setViewParams(null);

    request.setFeatureVersion("@version");
    assertDispatchMismatch(request, "no parameter filter exists for FEATUREVERSION");
    request.setFeatureVersion(null);
  }