use of org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl in project GeoGig by boundlessgeo.
the class ApplyPatchOpTest method testPartialApplication.
@Test
public void testPartialApplication() throws Exception {
insert(points1, points2);
Patch patch = new Patch();
String pathRemove = NodeRef.appendChild(pointsName, points2.getIdentifier().getID());
patch.addRemovedFeature(pathRemove, points2, RevFeatureTypeImpl.build(pointsType));
String pathModify = NodeRef.appendChild(pointsName, points1B.getIdentifier().getID());
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
Optional<?> oldValue = Optional.fromNullable(points1B.getProperty("extra").getValue());
GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, null);
map.put(modifiedPointsType.getDescriptor("extra"), diff);
FeatureDiff featureDiff = new FeatureDiff(pathModify, map, RevFeatureTypeImpl.build(modifiedPointsType), RevFeatureTypeImpl.build(pointsType));
patch.addModifiedFeature(featureDiff);
Patch rejected = geogig.command(ApplyPatchOp.class).setPatch(patch).setApplyPartial(true).call();
assertFalse(rejected.isEmpty());
RevTree root = repo.workingTree().getTree();
assertNotNull(root);
Optional<Node> featureBlobId = findTreeChild(root, pathRemove);
assertFalse(featureBlobId.isPresent());
// now we take the rejected patch and apply it, and the new rejected should be identical to
// it
Patch newRejected = geogig.command(ApplyPatchOp.class).setPatch(rejected).setApplyPartial(true).call();
assertEquals(rejected, newRejected);
}
use of org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl in project GeoGig by boundlessgeo.
the class ApplyPatchOpTest method testModifiedFeatureDoesNotExists.
@Test
public void testModifiedFeatureDoesNotExists() throws Exception {
Patch patch = new Patch();
String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
map.put(pointsType.getDescriptor("sp"), diff);
FeatureDiff featureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
patch.addModifiedFeature(featureDiff);
try {
geogig.command(ApplyPatchOp.class).setPatch(patch).call();
fail();
} catch (CannotApplyPatchException e) {
assertTrue(true);
}
}
use of org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl in project GeoGig by boundlessgeo.
the class ApplyPatchOpTest method testModifyFeatureAttributeOutdatedPatch.
@Test
public void testModifyFeatureAttributeOutdatedPatch() throws Exception {
insert(points1_modified);
Patch patch = new Patch();
String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
map.put(pointsType.getDescriptor("sp"), diff);
FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
patch.addModifiedFeature(feaureDiff);
try {
geogig.command(ApplyPatchOp.class).setPatch(patch).call();
fail();
} catch (CannotApplyPatchException e) {
assertTrue(true);
}
}
use of org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl in project GeoGig by boundlessgeo.
the class ApplyPatchOpTest method testRemoveFeatureAttributeOutdatedPatch.
@Test
public void testRemoveFeatureAttributeOutdatedPatch() throws Exception {
insert(points1B_modified);
Patch patch = new Patch();
String path = NodeRef.appendChild(pointsName, points1B.getIdentifier().getID());
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
Optional<?> oldValue = Optional.fromNullable(points1B.getProperty("extra").getValue());
GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, null);
map.put(modifiedPointsType.getDescriptor("extra"), diff);
FeatureDiff featureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(modifiedPointsType), RevFeatureTypeImpl.build(pointsType));
patch.addModifiedFeature(featureDiff);
try {
geogig.command(ApplyPatchOp.class).setPatch(patch).call();
fail();
} catch (CannotApplyPatchException e) {
assertTrue(true);
}
}
use of org.locationtech.geogig.api.plumbing.diff.GenericAttributeDiffImpl in project GeoGig by boundlessgeo.
the class DefaultStepDefinitions method I_have_a_patch_file.
@Given("^I have a patch file$")
public void I_have_a_patch_file() throws Throwable {
Patch patch = new Patch();
String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID());
Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap();
Optional<?> oldValue = Optional.fromNullable(points1.getProperty("sp").getValue());
GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(oldValue, Optional.of("new"));
map.put(pointsType.getDescriptor("sp"), diff);
FeatureDiff feaureDiff = new FeatureDiff(path, map, RevFeatureTypeImpl.build(pointsType), RevFeatureTypeImpl.build(pointsType));
patch.addModifiedFeature(feaureDiff);
File file = new File(platform.pwd(), "test.patch");
BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
PatchSerializer.write(writer, patch);
writer.flush();
writer.close();
}
Aggregations