Search in sources :

Example 6 with DeleteReviewerInput

use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.

the class ChangeIT method testRemoveReviewer.

private void testRemoveReviewer(boolean notify) throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    gApi.changes().id(changeId).revision(r.getCommit().name()).review(ReviewInput.approve());
    requestScopeOperations.setApiUser(user.id());
    gApi.changes().id(changeId).revision(r.getCommit().name()).review(ReviewInput.recommend());
    Collection<AccountInfo> reviewers = gApi.changes().id(changeId).get().reviewers.get(REVIEWER);
    assertThat(reviewers).hasSize(2);
    Iterator<AccountInfo> reviewerIt = reviewers.iterator();
    assertThat(reviewerIt.next()._accountId).isEqualTo(admin.id().get());
    assertThat(reviewerIt.next()._accountId).isEqualTo(user.id().get());
    sender.clear();
    requestScopeOperations.setApiUser(admin.id());
    DeleteReviewerInput input = new DeleteReviewerInput();
    if (!notify) {
        input.notify = NotifyHandling.NONE;
    }
    gApi.changes().id(changeId).reviewer(user.id().toString()).remove(input);
    if (notify) {
        assertThat(sender.getMessages()).hasSize(1);
        Message message = sender.getMessages().get(0);
        assertThat(message.body()).contains("Removed reviewer " + user.getNameEmail() + " with the following votes");
        assertThat(message.body()).contains("* Code-Review+1 by " + user.getNameEmail());
        ChangeMessageInfo changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).messages());
        assertThat(changeMessageInfo.message).contains("Removed reviewer " + user.getNameEmail() + " with the following votes");
        assertThat(changeMessageInfo.message).contains("* Code-Review+1 by " + user.getNameEmail());
        changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).get().messages);
        assertThat(changeMessageInfo.message).contains("Removed reviewer " + AccountTemplateUtil.getAccountTemplate(user.id()) + " with the following votes");
        assertThat(changeMessageInfo.message).contains("* Code-Review+1 by " + AccountTemplateUtil.getAccountTemplate(user.id()));
        assertThat(changeMessageInfo.accountsInMessage).containsExactly(getAccountInfo(user.id()));
    } else {
        assertThat(sender.getMessages()).isEmpty();
    }
    reviewers = gApi.changes().id(changeId).get().reviewers.get(REVIEWER);
    assertThat(reviewers).hasSize(1);
    reviewerIt = reviewers.iterator();
    assertThat(reviewerIt.next()._accountId).isEqualTo(admin.id().get());
    eventRecorder.assertReviewerDeletedEvents(changeId, user.email());
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 7 with DeleteReviewerInput

use of com.google.gerrit.extensions.api.changes.DeleteReviewerInput in project gerrit by GerritCodeReview.

the class AttentionSetIT method reviewDoesNotAddUsersInACommentThreadThatAreNotActiveInTheChange.

@Test
public void reviewDoesNotAddUsersInACommentThreadThatAreNotActiveInTheChange() throws Exception {
    PushOneCommit.Result r = createChange();
    requestScopeOperations.setApiUser(user.id());
    change(r).current().review(reviewWithComment());
    change(r).reviewer(user.id().toString()).remove(new DeleteReviewerInput());
    requestScopeOperations.setApiUser(admin.id());
    change(r).current().review(reviewInReplyToComment(Iterables.getOnlyElement(gApi.changes().id(r.getChangeId()).current().commentsAsList()).id));
    // The user was to be added, but was not added since that user is no longer a
    // reviewer/cc/owner/uploader.
    assertThat(getAttentionSetUpdatesForUser(r, user)).isEmpty();
}
Also used : DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)7 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)2 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)2 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 Account (com.google.gerrit.entities.Account)1 Address (com.google.gerrit.entities.Address)1 StorageException (com.google.gerrit.exceptions.StorageException)1 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)1 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)1 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)1 AuthException (com.google.gerrit.extensions.restapi.AuthException)1 AccountResolver (com.google.gerrit.server.account.AccountResolver)1 ReviewerResource (com.google.gerrit.server.change.ReviewerResource)1 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)1 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)1 Message (com.google.gerrit.testing.FakeEmailSender.Message)1 Test (org.junit.Test)1