Commit 922dbe40 authored by Torben Barsbsballe's avatar Torben Barsbsballe Committed by Andrea Aime
Browse files

[GEOS-7008] fix cascading delete for duplicate layers in layer group

parent 3a9c21a0
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -118,8 +118,11 @@ public class CascadeDeleteVisitor implements CatalogVisitor {
if(group.getLayers().contains(layer)) {
// parallel remove of layer and styles
int index = group.getLayers().indexOf(layer);
group.getLayers().remove(index);
group.getStyles().remove(index);
while (index != -1) {
group.getLayers().remove(index);
group.getStyles().remove(index);
index = group.getLayers().indexOf(layer);
}
// either update or remove the group
if(group.getLayers().size() == 0) {
......
/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
......@@ -67,6 +67,37 @@ public class CascadeDeleteVisitorTest extends GeoServerMockTestSupport {
return lg;
}
LayerGroupInfo setUpMockLayerGroupDuplicateLayer(final Catalog catalog) {
LayerGroupInfo lg = createMock(LayerGroupInfo.class);
expect(lg.getName()).andReturn(LAKES_GROUP).anyTimes();
LayerInfo lakes = createNiceMock(LayerInfo.class);
expect(lakes.getResource()).andReturn(createNiceMock(ResourceInfo.class)).anyTimes();
expect(catalog.getLayerByName(toString(LAKES))).andReturn(lakes).anyTimes();
LayerInfo forests = createNiceMock(LayerInfo.class);
expect(forests.getResource()).andReturn(createNiceMock(ResourceInfo.class)).anyTimes();
expect(catalog.getLayerByName(toString(FORESTS))).andReturn(forests).anyTimes();
LayerInfo bridges = createNiceMock(LayerInfo.class);
expect(bridges.getResource()).andReturn(createNiceMock(ResourceInfo.class)).anyTimes();
expect(catalog.getLayerByName(toString(FORESTS))).andReturn(bridges).anyTimes();
expect(lg.getLayers()).andReturn(
new ArrayList(Arrays.asList(lakes, lakes, forests, bridges))).anyTimes();
expect(lg.getStyles()).andReturn(new ArrayList(Arrays.asList(null, null, null, null)))
.anyTimes();
expect(catalog.getLayerGroupByName(LAKES_GROUP)).andReturn(lg).anyTimes();
lg.accept((CatalogVisitor) anyObject());
expectLastCall().anyTimes();
replay(lakes, forests, bridges, lg);
expect(catalog.getLayerGroups()).andReturn(Arrays.asList(lg)).anyTimes();
return lg;
}
@Test
public void testCascadeLayer() {
Catalog catalog = createMock(Catalog.class);
......@@ -94,6 +125,34 @@ public class CascadeDeleteVisitorTest extends GeoServerMockTestSupport {
assertEquals(2, group.getLayers().size());
assertFalse(group.getLayers().contains(layer));
}
@Test
public void testCascadeLayerDuplicate() {
Catalog catalog = createMock(Catalog.class);
LayerGroupInfo lg = setUpMockLayerGroupDuplicateLayer(catalog);
catalog.save(lg);
expectLastCall();
catalog.remove((LayerInfo) lg.getLayers().get(0));
expectLastCall();
catalog.remove(((LayerInfo) lg.getLayers().get(0)).getResource());
expectLastCall();
replay(catalog);
String name = toString(LAKES);
LayerInfo layer = catalog.getLayerByName(name);
assertNotNull(layer);
CascadeDeleteVisitor visitor = new CascadeDeleteVisitor(catalog);
visitor.visit(layer);
verify(catalog);
LayerGroupInfo group = catalog.getLayerGroupByName(LAKES_GROUP);
assertEquals(2, group.getLayers().size());
assertFalse(group.getLayers().contains(layer));
}
@Test
public void testCascadeStore() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment