Search in sources :

Example 1 with DeletedDraftCommentInfo

use of com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo in project gerrit by GerritCodeReview.

the class AccountIT method deleteAllDraftComments.

@Test
@UseClockStep
public void deleteAllDraftComments() throws Exception {
    try {
        Project.NameKey project2 = projectOperations.newProject().create();
        PushOneCommit.Result r1 = createChange();
        TestRepository<?> tr2 = cloneProject(project2);
        PushOneCommit.Result r2 = createChange(tr2, "refs/heads/master", "Change in project2", PushOneCommit.FILE_NAME, "content2", null);
        // Create 2 drafts each on both changes for user.
        requestScopeOperations.setApiUser(user.id());
        createDraft(r1, PushOneCommit.FILE_NAME, "draft 1a");
        createDraft(r1, PushOneCommit.FILE_NAME, "draft 1b");
        createDraft(r2, PushOneCommit.FILE_NAME, "draft 2a");
        createDraft(r2, PushOneCommit.FILE_NAME, "draft 2b");
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(2);
        assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).hasSize(2);
        // Create 1 draft on first change for admin.
        requestScopeOperations.setApiUser(admin.id());
        createDraft(r1, PushOneCommit.FILE_NAME, "admin draft");
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(1);
        // Delete user's draft comments; leave admin's alone.
        requestScopeOperations.setApiUser(user.id());
        List<DeletedDraftCommentInfo> result = gApi.accounts().self().deleteDraftComments(new DeleteDraftCommentsInput());
        // Results are ordered according to the change search, most recently updated first.
        assertThat(result).hasSize(2);
        DeletedDraftCommentInfo del2 = result.get(0);
        assertThat(del2.change.changeId).isEqualTo(r2.getChangeId());
        assertThat(del2.deleted.stream().map(c -> c.message)).containsExactly("draft 2a", "draft 2b");
        DeletedDraftCommentInfo del1 = result.get(1);
        assertThat(del1.change.changeId).isEqualTo(r1.getChangeId());
        assertThat(del1.deleted.stream().map(c -> c.message)).containsExactly("draft 1a", "draft 1b");
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).isEmpty();
        assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).isEmpty();
        requestScopeOperations.setApiUser(admin.id());
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(1);
    } finally {
        cleanUpDrafts();
    }
}
Also used : DeletedDraftCommentInfo(com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo) Project(com.google.gerrit.entities.Project) DeleteDraftCommentsInput(com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 2 with DeletedDraftCommentInfo

use of com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo in project gerrit by GerritCodeReview.

the class AccountIT method deleteDraftCommentsByQuery.

@Test
public void deleteDraftCommentsByQuery() throws Exception {
    try {
        PushOneCommit.Result r1 = createChange();
        PushOneCommit.Result r2 = createChange();
        createDraft(r1, PushOneCommit.FILE_NAME, "draft a");
        createDraft(r2, PushOneCommit.FILE_NAME, "draft b");
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(1);
        assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).hasSize(1);
        List<DeletedDraftCommentInfo> result = gApi.accounts().self().deleteDraftComments(new DeleteDraftCommentsInput("change:" + r1.getChangeId()));
        assertThat(result).hasSize(1);
        assertThat(result.get(0).change.changeId).isEqualTo(r1.getChangeId());
        assertThat(result.get(0).deleted.stream().map(c -> c.message)).containsExactly("draft a");
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).isEmpty();
        assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).hasSize(1);
    } finally {
        cleanUpDrafts();
    }
}
Also used : DeletedDraftCommentInfo(com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo) DeleteDraftCommentsInput(com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with DeletedDraftCommentInfo

use of com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo in project gerrit by GerritCodeReview.

the class AccountIT method deleteDraftCommentsSkipsInvisibleChanges.

@Test
public void deleteDraftCommentsSkipsInvisibleChanges() throws Exception {
    try {
        createBranch(BranchNameKey.create(project, "secret"));
        PushOneCommit.Result r1 = createChange();
        PushOneCommit.Result r2 = createChange("refs/for/secret");
        requestScopeOperations.setApiUser(user.id());
        createDraft(r1, PushOneCommit.FILE_NAME, "draft a");
        createDraft(r2, PushOneCommit.FILE_NAME, "draft b");
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).hasSize(1);
        assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).hasSize(1);
        projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/heads/secret").group(REGISTERED_USERS)).update();
        List<DeletedDraftCommentInfo> result = gApi.accounts().self().deleteDraftComments(new DeleteDraftCommentsInput());
        assertThat(result).hasSize(1);
        assertThat(result.get(0).change.changeId).isEqualTo(r1.getChangeId());
        assertThat(result.get(0).deleted.stream().map(c -> c.message)).containsExactly("draft a");
        projectOperations.project(project).forUpdate().remove(permissionKey(Permission.READ).ref("refs/heads/secret")).update();
        assertThat(gApi.changes().id(r1.getChangeId()).current().draftsAsList()).isEmpty();
        // Draft still exists since change wasn't visible when drafts where deleted.
        assertThat(gApi.changes().id(r2.getChangeId()).current().draftsAsList()).hasSize(1);
    } finally {
        cleanUpDrafts();
    }
}
Also used : DeletedDraftCommentInfo(com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo) DeleteDraftCommentsInput(com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 DeleteDraftCommentsInput (com.google.gerrit.extensions.api.accounts.DeleteDraftCommentsInput)3 DeletedDraftCommentInfo (com.google.gerrit.extensions.api.accounts.DeletedDraftCommentInfo)3 Test (org.junit.Test)3 UseClockStep (com.google.gerrit.acceptance.UseClockStep)1 Project (com.google.gerrit.entities.Project)1