Пример #1
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());
  }
Пример #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));
  }
Пример #3
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();
  }
Пример #4
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);
  }
Пример #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();
  }