@Test public void testModifyFeatureAttributePatch() throws Exception { insert(points1); 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, RevFeatureType.build(pointsType), RevFeatureType.build(pointsType)); patch.addModifiedFeature(feaureDiff); geogit.command(ApplyPatchOp.class).setPatch(patch).call(); RevTree root = repo.getWorkingTree().getTree(); Optional<Node> featureBlobId = findTreeChild(root, path); assertTrue(featureBlobId.isPresent()); Iterator<DiffEntry> unstaged = repo.getWorkingTree().getUnstaged(pointsName); ArrayList<DiffEntry> diffs = Lists.newArrayList(unstaged); assertEquals(2, diffs.size()); Optional<RevFeature> feature = geogit.command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + path).call(RevFeature.class); assertTrue(feature.isPresent()); ImmutableList<Optional<Object>> values = feature.get().getValues(); assertEquals("new", values.get(0).get()); }
@Test public void testReversedPatch() throws Exception { insert(points1, points2); 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, RevFeatureType.build(pointsType), RevFeatureType.build(pointsType)); patch.addModifiedFeature(feaureDiff); String removedPath = NodeRef.appendChild(pointsName, points2.getIdentifier().getID()); patch.addRemovedFeature(removedPath, points2, RevFeatureType.build(pointsType)); String addedPath = NodeRef.appendChild(pointsName, points3.getIdentifier().getID()); patch.addAddedFeature(addedPath, points3, RevFeatureType.build(pointsType)); geogit.command(ApplyPatchOp.class).setPatch(patch).call(); geogit.command(ApplyPatchOp.class).setPatch(patch.reversed()).call(); RevTree root = repo.getWorkingTree().getTree(); Optional<Node> featureBlobId = findTreeChild(root, removedPath); assertTrue(featureBlobId.isPresent()); featureBlobId = findTreeChild(root, addedPath); assertFalse(featureBlobId.isPresent()); Optional<RevFeature> feature = geogit.command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + path).call(RevFeature.class); assertTrue(feature.isPresent()); assertEquals(oldValue, feature.get().getValues().get(0)); }
@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, RevFeatureType.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, RevFeatureType.build(modifiedPointsType), RevFeatureType.build(pointsType)); patch.addModifiedFeature(featureDiff); Patch rejected = geogit.command(ApplyPatchOp.class).setPatch(patch).setApplyPartial(true).call(); assertFalse(rejected.isEmpty()); RevTree root = repo.getWorkingTree().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 = geogit.command(ApplyPatchOp.class).setPatch(rejected).setApplyPartial(true).call(); assertEquals(rejected, newRejected); }
@Test public void testAddFeatureAttributePatch() throws Exception { insert(points1); Patch patch = new Patch(); String path = NodeRef.appendChild(pointsName, points1.getIdentifier().getID()); Map<PropertyDescriptor, AttributeDiff> map = Maps.newHashMap(); Optional<?> newValue = Optional.fromNullable(points1B.getProperty("extra").getValue()); GenericAttributeDiffImpl diff = new GenericAttributeDiffImpl(null, newValue); map.put(modifiedPointsType.getDescriptor("extra"), diff); FeatureDiff featureDiff = new FeatureDiff( path, map, RevFeatureType.build(pointsType), RevFeatureType.build(modifiedPointsType)); patch.addModifiedFeature(featureDiff); geogit.command(ApplyPatchOp.class).setPatch(patch).call(); // TODO }
@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, RevFeatureType.build(pointsType), RevFeatureType.build(pointsType)); patch.addModifiedFeature(featureDiff); try { geogit.command(ApplyPatchOp.class).setPatch(patch).call(); fail(); } catch (CannotApplyPatchException e) { assertTrue(true); } }
@Test public void testRemoveFeatureAttributePatch() throws Exception { insert(points1B); 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, RevFeatureType.build(modifiedPointsType), RevFeatureType.build(pointsType)); patch.addModifiedFeature(featureDiff); geogit.command(ApplyPatchOp.class).setPatch(patch).call(); Optional<RevFeature> feature = geogit.command(RevObjectParse.class).setRefSpec("WORK_HEAD:" + path).call(RevFeature.class); assertTrue(feature.isPresent()); ImmutableList<Optional<Object>> values = feature.get().getValues(); assertEquals(points1.getProperties().size(), values.size()); assertFalse(values.contains("ExtraString")); }