Search in sources :

Example 1 with ReviewerInput

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

the class ChangeReviewersIT method addReviewer.

private ReviewerResult addReviewer(String changeId, String reviewer, int expectedStatus) throws Exception {
    ReviewerInput in = new ReviewerInput();
    in.reviewer = reviewer;
    return addReviewer(changeId, in, expectedStatus);
}
Also used : ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput)

Example 2 with ReviewerInput

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

the class ChangeReviewersIT method addCcGroup.

@Test
public void addCcGroup() throws Exception {
    List<TestAccount> users = createAccounts(6, "addCcGroup");
    List<String> usernames = new ArrayList<>(6);
    for (TestAccount u : users) {
        usernames.add(u.username());
    }
    List<TestAccount> firstUsers = users.subList(0, 3);
    List<String> firstUsernames = usernames.subList(0, 3);
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = groupOperations.newGroup().name("cc1").create().get();
    in.state = CC;
    gApi.groups().id(in.reviewer).addMembers(firstUsernames.toArray(new String[firstUsernames.size()]));
    ReviewerResult result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(in.reviewer);
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    assertThat(result.reviewers).isNull();
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, CC, firstUsers);
    // Verify emails were sent to each of the group's accounts.
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    List<Address> expectedAddresses = new ArrayList<>(firstUsers.size());
    for (TestAccount u : firstUsers) {
        expectedAddresses.add(u.getNameEmail());
    }
    assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
    // CC a group that overlaps with some existing reviewers and CCed accounts.
    TestAccount reviewer = accountCreator.create(name("reviewer"), "addCcGroup-reviewer@example.com", "Reviewer", null);
    result = addReviewer(changeId, reviewer.username());
    assertThat(result.error).isNull();
    sender.clear();
    in.reviewer = groupOperations.newGroup().name("cc2").create().get();
    gApi.groups().id(in.reviewer).addMembers(usernames.toArray(new String[usernames.size()]));
    gApi.groups().id(in.reviewer).addMembers(reviewer.username());
    result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(in.reviewer);
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(result.ccs).hasSize(3);
    assertThat(result.reviewers).isNull();
    assertReviewers(c, REVIEWER, reviewer);
    assertReviewers(c, CC, users);
    messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    m = messages.get(0);
    expectedAddresses = new ArrayList<>(4);
    for (int i = 0; i < 3; i++) {
        expectedAddresses.add(users.get(users.size() - i - 1).getNameEmail());
    }
    expectedAddresses.add(reviewer.getNameEmail());
    assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) Address(com.google.gerrit.entities.Address) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) ArrayList(java.util.ArrayList) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with ReviewerInput

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

the class ChangeReviewersIT method addReviewerToReviewerChangeInfo.

@Test
public void addReviewerToReviewerChangeInfo() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    in.state = CC;
    addReviewer(changeId, in);
    in.state = REVIEWER;
    addReviewer(changeId, in);
    gApi.changes().id(changeId).current().review(ReviewInput.dislike());
    requestScopeOperations.setApiUser(user.id());
    // By posting a review the user is added as reviewer.
    gApi.changes().id(changeId).current().review(ReviewInput.dislike());
    deleteReviewer(changeId, user).assertNoContent();
    ChangeInfo c = gApi.changes().id(changeId).get();
    assertThat(c.reviewerUpdates).isNotNull();
    assertThat(c.reviewerUpdates).hasSize(3);
    Iterator<ReviewerUpdateInfo> it = c.reviewerUpdates.iterator();
    ReviewerUpdateInfo reviewerChange = it.next();
    assertThat(reviewerChange.state).isEqualTo(CC);
    assertThat(reviewerChange.reviewer._accountId).isEqualTo(user.id().get());
    assertThat(reviewerChange.updatedBy._accountId).isEqualTo(admin.id().get());
    reviewerChange = it.next();
    assertThat(reviewerChange.state).isEqualTo(REVIEWER);
    assertThat(reviewerChange.reviewer._accountId).isEqualTo(user.id().get());
    assertThat(reviewerChange.updatedBy._accountId).isEqualTo(admin.id().get());
    reviewerChange = it.next();
    assertThat(reviewerChange.state).isEqualTo(REMOVED);
    assertThat(reviewerChange.reviewer._accountId).isEqualTo(user.id().get());
    assertThat(reviewerChange.updatedBy._accountId).isEqualTo(admin.id().get());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerUpdateInfo(com.google.gerrit.extensions.common.ReviewerUpdateInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with ReviewerInput

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

the class ChangeReviewersIT method moveReviewerToCc.

@Test
public void moveReviewerToCc() throws Exception {
    // Allow everyone to approve changes.
    projectOperations.project(project).forUpdate().add(allowLabel(LabelId.CODE_REVIEW).ref("refs/heads/*").group(REGISTERED_USERS).range(-2, 2)).update();
    // Create a change and add 'user' as reviewer.
    String changeId = createChange().getChangeId();
    gApi.changes().id(changeId).addReviewer(user.id().toString());
    // Verify that 'user' is a reviewer on the change and that there are no CCs.
    ChangeInfo c = gApi.changes().id(changeId).get();
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
    assertThat(c.reviewers.get(CC)).isNull();
    // Let 'user' approve the change and verify that the change has the approval.
    requestScopeOperations.setApiUser(user.id());
    approve(changeId);
    c = gApi.changes().id(changeId).get();
    assertThat(c.labels.get(LabelId.CODE_REVIEW).approved._accountId).isEqualTo(user.id().get());
    // Move 'user' from reviewer to CC.
    requestScopeOperations.setApiUser(admin.id());
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = user.id().toString();
    reviewerInput.state = CC;
    gApi.changes().id(changeId).addReviewer(reviewerInput);
    // Verify that 'user' is a CC on the change now and that there are no reviewers.
    c = gApi.changes().id(changeId).get();
    Collection<AccountInfo> ccs = c.reviewers.get(CC);
    assertThat(ccs).isNotNull();
    assertThat(ccs).hasSize(1);
    assertThat(ccs.iterator().next()._accountId).isEqualTo(user.id().get());
    assertThat(c.reviewers.get(REVIEWER)).isNull();
    // Verify that the approval of 'user' is still there.
    assertThat(c.labels.get(LabelId.CODE_REVIEW).approved._accountId).isEqualTo(user.id().get());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with ReviewerInput

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

the class ChangeReviewersIT method notifyDetailsWorkOnPostReviewers.

@Test
public void notifyDetailsWorkOnPostReviewers() throws Exception {
    PushOneCommit.Result r = createChange();
    TestAccount userToNotify = createAccounts(1, "notify-details-post-reviewers").get(0);
    ReviewerInput addReviewer = new ReviewerInput();
    addReviewer.reviewer = user.email();
    addReviewer.notify = NotifyHandling.NONE;
    addReviewer.notifyDetails = ImmutableMap.of(RecipientType.TO, new NotifyInfo(ImmutableList.of(userToNotify.email())));
    sender.clear();
    gApi.changes().id(r.getChangeId()).addReviewer(addReviewer);
    assertThat(sender.getMessages()).hasSize(1);
    assertThat(sender.getMessages().get(0).rcpt()).containsExactly(userToNotify.getNameEmail());
}
Also used : NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)72 Test (org.junit.Test)67 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)60 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)46 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)25 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)22 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)20 TestAccount (com.google.gerrit.acceptance.TestAccount)14 Message (com.google.gerrit.testing.FakeEmailSender.Message)14 ReviewerResult (com.google.gerrit.extensions.api.changes.ReviewerResult)13 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)11 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 Account (com.google.gerrit.entities.Account)10 Change (com.google.gerrit.entities.Change)7 UseClockStep (com.google.gerrit.acceptance.UseClockStep)5 ReviewerInfo (com.google.gerrit.extensions.api.changes.ReviewerInfo)5 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)5 Instant (java.time.Instant)5 ArrayList (java.util.ArrayList)5