@DirtiesContext
public void testSaveOrUpdateFeatureWritable() throws Exception {
Filter filter;
List<InternalFeature> oldFeatures;
List<InternalFeature> newFeatures;
InternalFeature feature;
CoordinateReferenceSystem crs = beanLayer.getCrs();
login("marino");
// should be able to update feature "1"
filter = filterService.createFidFilter(new String[]{"1"});
oldFeatures = layerService.getFeatures(LAYER_ID, crs, filter, null,
VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
Assert.assertEquals(1, oldFeatures.size());
feature = oldFeatures.get(0);
newFeatures = new ArrayList<InternalFeature>();
feature = feature.clone();
newFeatures.add(feature);
feature.getAttributes().put(STRING_ATTR, new StringAttribute("changed"));
layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
// should not able to update feature "3"
filter = filterService.createFidFilter(new String[]{"3"});
oldFeatures = layerService.getFeatures(LAYER_ID, crs, filter, null,
VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
Assert.assertEquals(1, oldFeatures.size());
feature = oldFeatures.get(0);
newFeatures = new ArrayList<InternalFeature>();
feature = feature.clone();
newFeatures.add(feature);
feature.getAttributes().put(STRING_ATTR, new StringAttribute("changed"));
try {
layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
Assert.fail("should have throw GeomajasSecurityException");
} catch (GeomajasSecurityException gse) {
Assert.assertEquals(ExceptionCode.FEATURE_UPDATE_PROHIBITED, gse.getExceptionCode());
}
login("luc");
// luc should be able to modify "3"
filter = filterService.createFidFilter(new String[]{"3"});
oldFeatures = layerService.getFeatures(LAYER_ID,
crs, filter, null, VectorLayerService.FEATURE_INCLUDE_ATTRIBUTES);
Assert.assertEquals(1, oldFeatures.size());
feature = oldFeatures.get(0);
newFeatures = new ArrayList<InternalFeature>();
feature = feature.clone();
newFeatures.add(feature);
feature.getAttributes().put(STRING_ATTR, new StringAttribute("changed"));
layerService.saveOrUpdate(LAYER_ID, crs, oldFeatures, newFeatures);
}