/** * Runs the command and builds the appropriate response. * * @param context - the context to use for this command * * @throws CommandSpecException */ @Override protected void runInternal(CommandContext context) { final Context geogig = this.getRepositoryContext(context); NodeRef.checkValidPath(path); RemoveOp command = geogig.command(RemoveOp.class).setRecursive(recursive); command.addPathToRemove(path).call(); context.setResponseContent(new CommandResponse() { @Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeElement("Deleted", path); out.finish(); } }); }
@Test public void testTruncateAndRecursivePrecondition() { exception.expect(IllegalArgumentException.class); exception.expectMessage("recursive and truncate arguments are mutually exclusive"); geogig.command(RemoveOp.class).addPathToRemove("tree").setRecursive(true).setTruncate(true) .call(); }
@Test public void testTruncateAndRecursivePrecondition() { exception.expect(IllegalArgumentException.class); exception.expectMessage("recursive and truncate arguments are mutually exclusive"); geogig.command(RemoveOp.class).addPathToRemove("tree").setRecursive(true).setTruncate(true) .call(); }
@Ignore @Test public void testUnexistentPathRemoval() throws Exception { populate(false, points1, points2, points3); try { geogig.command(RemoveOp.class).addPathToRemove("wrong/wrong.1").call(); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertTrue(true); } }
@Ignore @Test public void testUnexistentPathRemoval() throws Exception { populate(false, points1, points2, points3); try { geogig.command(RemoveOp.class).addPathToRemove("wrong/wrong.1").call(); fail("expected IllegalArgumentException"); } catch (IllegalArgumentException e) { assertTrue(true); } }
@Test public void testTruncateOrRecursivePrecondition() throws Exception { insertAndAdd(points1); exception.expect(IllegalArgumentException.class); exception.expectMessage( "Cannot remove tree " + pointsName + " if recursive or truncate is not specified"); geogig.command(RemoveOp.class).addPathToRemove(pointsName).setRecursive(false) .setTruncate(false).call(); }
@Test public void testTruncateOrRecursivePrecondition() throws Exception { insertAndAdd(points1); exception.expect(IllegalArgumentException.class); exception.expectMessage( "Cannot remove tree " + pointsName + " if recursive or truncate is not specified"); geogig.command(RemoveOp.class).addPathToRemove(pointsName).setRecursive(false) .setTruncate(false).call(); }
@SuppressWarnings(value = { "unused" }) @Test public void testRemovalOfAllFeaturesOfAGivenType() throws Exception { List<RevCommit> commits = populate(false, points1, points2, points3, lines1, lines2); String featureId = lines1.getIdentifier().getID(); String path = NodeRef.appendChild(linesName, featureId); String featureId2 = lines2.getIdentifier().getID(); String path2 = NodeRef.appendChild(linesName, featureId2); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path) .addPathToRemove(path2).call(); assertEquals(2, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); RevCommit commit = geogig.command(CommitOp.class).setMessage("Removed lines").call(); Iterator<NodeRef> nodes = geogig.command(LsTreeOp.class).call(); while (nodes.hasNext()) { NodeRef node = nodes.next(); assertNotNull(node); } geogig.command(ResetOp.class).setMode(ResetMode.HARD).call(); nodes = geogig.command(LsTreeOp.class).call(); while (nodes.hasNext()) { NodeRef node = nodes.next(); assertNotNull(node); } }
@Test public void testMultipleRemoval() throws Exception { populate(false, points1, points2, points3); String featureId = points1.getIdentifier().getID(); String path = NodeRef.appendChild(pointsName, featureId); String featureId2 = points2.getIdentifier().getID(); String path2 = NodeRef.appendChild(pointsName, featureId2); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path) .addPathToRemove(path2).call(); assertEquals(2, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); Optional<ObjectId> id = geogig.command(RevParse.class) .setRefSpec(Ref.WORK_HEAD + ":" + path).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + path).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.WORK_HEAD + ":" + path2).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + path2).call(); assertFalse(id.isPresent()); }
@Test public void testTreeRemoval() throws Exception { populate(false, points1, points2, points3, lines1, lines2); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(pointsName) .setRecursive(true).call(); assertEquals(3, result.getFeaturesRemoved()); assertEquals(1, result.getTreesRemoved()); Optional<ObjectId> id = geogig.command(RevParse.class) .setRefSpec(Ref.WORK_HEAD + ":" + pointsName).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + pointsName).call(); List<DiffEntry> list = toList(repo.index().getStaged(null)); assertEquals(4, list.size()); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + linesName).call(); assertTrue(id.isPresent()); }
@Test public void testMultipleRemoval() throws Exception { populate(false, points1, points2, points3); String featureId = points1.getIdentifier().getID(); String path = NodeRef.appendChild(pointsName, featureId); String featureId2 = points2.getIdentifier().getID(); String path2 = NodeRef.appendChild(pointsName, featureId2); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path) .addPathToRemove(path2).call(); assertEquals(2, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); Optional<ObjectId> id = geogig.command(RevParse.class) .setRefSpec(Ref.WORK_HEAD + ":" + path).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + path).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.WORK_HEAD + ":" + path2).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + path2).call(); assertFalse(id.isPresent()); }
@Test public void testSingleFeatureRemoval() throws Exception { populate(false, points1, points2, points3); String featureId = points1.getIdentifier().getID(); String path = NodeRef.appendChild(pointsName, featureId); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path).call(); assertEquals(1, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); Optional<ObjectId> id = geogig.command(RevParse.class) .setRefSpec(Ref.WORK_HEAD + ":" + path).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + path).call(); assertFalse(id.isPresent()); }
@Test public void testUpdateIndexesHook() { IndexInfo indexInfo = createIndex(true, "x"); String fid = IndexTestSupport.getPointFid(5, 5); geogig.command(RemoveOp.class) .addPathToRemove(NodeRef.appendChild(worldPointsLayer.getName(), fid)).call(); add(); RevCommit commit = commit("deleted 5, 5"); NodeRef featureTree = IndexUtils.resolveTypeTreeRef(geogig.getContext(), commit.getId() + ":" + worldPointsLayer.getName()); // New index tree should be automatically created for pre-exising index. Optional<ObjectId> commitIndex = indexdb.resolveIndexedTree(indexInfo, featureTree.getObjectId()); assertTrue(commitIndex.isPresent()); IndexTestSupport.verifyIndex(geogig, commitIndex.get(), featureTree.getObjectId(), "x"); }
@Test public void testUpdateIndexesHook() { IndexInfo indexInfo = createIndex(true, "x"); String fid = IndexTestSupport.getPointFid(5, 5); geogig.command(RemoveOp.class) .addPathToRemove(NodeRef.appendChild(worldPointsLayer.getName(), fid)).call(); add(); RevCommit commit = commit("deleted 5, 5"); NodeRef featureTree = IndexUtils.resolveTypeTreeRef(geogig.getContext(), commit.getId() + ":" + worldPointsLayer.getName()); // New index tree should be automatically created for pre-exising index. Optional<ObjectId> commitIndex = indexdb.resolveIndexedTree(indexInfo, featureTree.getObjectId()); assertTrue(commitIndex.isPresent()); IndexTestSupport.verifyIndex(geogig, commitIndex.get(), featureTree.getObjectId(), "x"); }
@Test public void testSingleFeatureRemoval() throws Exception { populate(false, points1, points2, points3); String featureId = points1.getIdentifier().getID(); String path = NodeRef.appendChild(pointsName, featureId); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(path).call(); assertEquals(1, result.getFeaturesRemoved()); assertEquals(0, result.getTreesRemoved()); Optional<ObjectId> id = geogig.command(RevParse.class) .setRefSpec(Ref.WORK_HEAD + ":" + path).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + path).call(); assertFalse(id.isPresent()); }
@Test public void testTruncate() throws Exception { insert(points1, points2, points3); insert(lines1, lines2, lines3); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(linesName) .setTruncate(true).call(); assertEquals(0, result.getTreesRemoved()); assertEquals(1, result.getTreesChanged()); assertEquals(3, result.getFeaturesRemoved()); } }
@Test public void testTreeRemoval() throws Exception { populate(false, points1, points2, points3, lines1, lines2); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(pointsName) .setRecursive(true).call(); assertEquals(3, result.getFeaturesRemoved()); assertEquals(1, result.getTreesRemoved()); Optional<ObjectId> id = geogig.command(RevParse.class) .setRefSpec(Ref.WORK_HEAD + ":" + pointsName).call(); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + pointsName).call(); List<DiffEntry> list = toList(repo.index().getStaged(null)); assertFalse(id.isPresent()); id = geogig.command(RevParse.class).setRefSpec(Ref.STAGE_HEAD + ":" + linesName).call(); assertTrue(id.isPresent()); }
@Test public void testTruncate() throws Exception { insert(points1, points2, points3); insert(lines1, lines2, lines3); DiffObjectCount result = geogig.command(RemoveOp.class).addPathToRemove(linesName) .setTruncate(true).call(); assertEquals(0, result.getTreesRemoved()); assertEquals(1, result.getTreesChanged()); assertEquals(3, result.getFeaturesRemoved()); } }
@Test public void testRemovedTreeOnlyInOneBranch() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).call(); geogig.command(BranchCreateOp.class).setName("TestBranch").call(); insertAndAdd(points2); RevCommit masterCommit = geogig.command(CommitOp.class).call(); geogig.command(CheckoutOp.class).setSource("TestBranch").call(); geogig.command(RemoveOp.class).addPathToRemove(pointsName).setRecursive(true).call(); geogig.command(AddOp.class).call(); RevCommit branchCommit = geogig.command(CommitOp.class).call(); MergeScenarioReport conflicts = geogig.command(ReportMergeScenarioOp.class) .setMergeIntoCommit(masterCommit).setToMergeCommit(branchCommit) .setConsumer(new TestMergeScenarioConsumer()).call(); assertEquals(1, conflicts.getConflicts()); assertEquals(1, conflicts.getUnconflicted()); Boolean hasConflicts = geogig.command(CheckMergeScenarioOp.class) .setCommits(Lists.newArrayList(masterCommit, branchCommit)).call(); assertTrue(hasConflicts.booleanValue()); }
@Test public void testRemovedTreeOnlyInOneBranch() throws Exception { insertAndAdd(points1); geogig.command(CommitOp.class).call(); geogig.command(BranchCreateOp.class).setName("TestBranch").call(); insertAndAdd(points2); RevCommit masterCommit = geogig.command(CommitOp.class).call(); geogig.command(CheckoutOp.class).setSource("TestBranch").call(); geogig.command(RemoveOp.class).addPathToRemove(pointsName).setRecursive(true).call(); geogig.command(AddOp.class).call(); RevCommit branchCommit = geogig.command(CommitOp.class).call(); MergeScenarioReport conflicts = geogig.command(ReportMergeScenarioOp.class) .setMergeIntoCommit(masterCommit).setToMergeCommit(branchCommit) .setConsumer(new TestMergeScenarioConsumer()).call(); assertEquals(1, conflicts.getConflicts()); assertEquals(1, conflicts.getUnconflicted()); Boolean hasConflicts = geogig.command(CheckMergeScenarioOp.class) .setCommits(Lists.newArrayList(masterCommit, branchCommit)).call(); assertTrue(hasConflicts.booleanValue()); }