Search in sources :

Example 6 with ReviewResult

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

the class ChangeReviewersIT method addOverlappingGroups.

@Test
public void addOverlappingGroups() throws Exception {
    String emailPrefix = "addOverlappingGroups-";
    TestAccount user1 = accounts.create(name("user1"), emailPrefix + "user1@example.com", "User1");
    TestAccount user2 = accounts.create(name("user2"), emailPrefix + "user2@example.com", "User2");
    TestAccount user3 = accounts.create(name("user3"), emailPrefix + "user3@example.com", "User3");
    String group1 = createGroup("group1");
    String group2 = createGroup("group2");
    gApi.groups().id(group1).addMembers(user1.username, user2.username);
    gApi.groups().id(group2).addMembers(user2.username, user3.username);
    PushOneCommit.Result r = createChange();
    ReviewInput input = ReviewInput.approve().reviewer(group1).reviewer(group2);
    ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(2);
    AddReviewerResult reviewerResult = result.reviewers.get(group1);
    assertThat(reviewerResult.error).isNull();
    assertThat(reviewerResult.reviewers).hasSize(2);
    reviewerResult = result.reviewers.get(group2);
    assertThat(reviewerResult.error).isNull();
    assertThat(reviewerResult.reviewers).hasSize(1);
    // Repeat the above for CCs
    if (!notesMigration.readChanges()) {
        return;
    }
    r = createChange();
    input = ReviewInput.approve().reviewer(group1, CC, false).reviewer(group2, CC, false);
    result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(2);
    reviewerResult = result.reviewers.get(group1);
    assertThat(reviewerResult.error).isNull();
    assertThat(reviewerResult.ccs).hasSize(2);
    reviewerResult = result.reviewers.get(group2);
    assertThat(reviewerResult.error).isNull();
    assertThat(reviewerResult.ccs).hasSize(1);
    // Repeat again with one group REVIEWER, the other CC. The overlapping
    // member should end up as a REVIEWER.
    r = createChange();
    input = ReviewInput.approve().reviewer(group1, REVIEWER, false).reviewer(group2, CC, false);
    result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(2);
    reviewerResult = result.reviewers.get(group1);
    assertThat(reviewerResult.error).isNull();
    assertThat(reviewerResult.reviewers).hasSize(2);
    reviewerResult = result.reviewers.get(group2);
    assertThat(reviewerResult.error).isNull();
    assertThat(reviewerResult.reviewers).isNull();
    assertThat(reviewerResult.ccs).hasSize(1);
}
Also used : AddReviewerResult(com.google.gerrit.extensions.api.changes.AddReviewerResult) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 7 with ReviewResult

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

the class ChangeReviewersIT method reviewerReplyWithoutVote.

@Test
public void reviewerReplyWithoutVote() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // Verify reviewer state.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER);
    assertReviewers(c, CC);
    LabelInfo label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNull();
    // Add user as REVIEWER.
    ReviewInput input = new ReviewInput().reviewer(user.username);
    ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(1);
    // Verify reviewer state. Both admin and user should be REVIEWERs now,
    // because admin gets forced into REVIEWER state by virtue of being owner.
    c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, admin, user);
    assertReviewers(c, CC);
    label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(2);
    Map<Integer, Integer> approvals = new HashMap<>();
    for (ApprovalInfo approval : label.all) {
        approvals.put(approval._accountId, approval.value);
    }
    assertThat(approvals).containsEntry(admin.getId().get(), 0);
    assertThat(approvals).containsEntry(user.getId().get(), 0);
    // Comment as user without voting. This should delete the approval and
    // then replace it with the default value.
    input = new ReviewInput().message("hello");
    RestResponse resp = userRestSession.post("/changes/" + r.getChangeId() + "/revisions/" + r.getCommit().getName() + "/review", input);
    result = readContentFromJson(resp, 200, ReviewResult.class);
    assertThat(result.labels).isNull();
    // Verify reviewer state.
    c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, admin, user);
    assertReviewers(c, CC);
    label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(2);
    approvals.clear();
    for (ApprovalInfo approval : label.all) {
        approvals.put(approval._accountId, approval.value);
    }
    assertThat(approvals).containsEntry(admin.getId().get(), 0);
    assertThat(approvals).containsEntry(user.getId().get(), 0);
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) HashMap(java.util.HashMap) RestResponse(com.google.gerrit.acceptance.RestResponse) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with ReviewResult

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

the class ChangeReviewersIT method reviewAndAddGroupReviewers.

@Test
public void reviewAndAddGroupReviewers() throws Exception {
    int largeGroupSize = PostReviewers.DEFAULT_MAX_REVIEWERS + 1;
    int mediumGroupSize = PostReviewers.DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK + 1;
    List<TestAccount> users = createAccounts(largeGroupSize, "reviewAndAddGroupReviewers");
    List<String> usernames = new ArrayList<>(largeGroupSize);
    for (TestAccount u : users) {
        usernames.add(u.username);
    }
    String largeGroup = createGroup("largeGroup");
    String mediumGroup = createGroup("mediumGroup");
    gApi.groups().id(largeGroup).addMembers(usernames.toArray(new String[largeGroupSize]));
    gApi.groups().id(mediumGroup).addMembers(usernames.subList(0, mediumGroupSize).toArray(new String[mediumGroupSize]));
    TestAccount observer = accounts.user2();
    PushOneCommit.Result r = createChange();
    // Attempt to add overly large group as reviewers.
    ReviewInput input = ReviewInput.approve().reviewer(user.email).reviewer(observer.email, CC, false).reviewer(largeGroup);
    ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input, SC_BAD_REQUEST);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(3);
    AddReviewerResult reviewerResult = result.reviewers.get(largeGroup);
    assertThat(reviewerResult).isNotNull();
    assertThat(reviewerResult.confirm).isNull();
    assertThat(reviewerResult.error).isNotNull();
    assertThat(reviewerResult.error).contains("has too many members to add them all as reviewers");
    // No labels should have changed, and no reviewers/CCs should have been added.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.messages).hasSize(1);
    assertThat(c.reviewers.get(REVIEWER)).isNull();
    assertThat(c.reviewers.get(CC)).isNull();
    // Attempt to add group large enough to require confirmation, without
    // confirmation, as reviewers.
    input = ReviewInput.approve().reviewer(user.email).reviewer(observer.email, CC, false).reviewer(mediumGroup);
    result = review(r.getChangeId(), r.getCommit().name(), input, SC_BAD_REQUEST);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(3);
    reviewerResult = result.reviewers.get(mediumGroup);
    assertThat(reviewerResult).isNotNull();
    assertThat(reviewerResult.confirm).isTrue();
    assertThat(reviewerResult.error).contains("has " + mediumGroupSize + " members. Do you want to add them all as reviewers?");
    // No labels should have changed, and no reviewers/CCs should have been added.
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.messages).hasSize(1);
    assertThat(c.reviewers.get(REVIEWER)).isNull();
    assertThat(c.reviewers.get(CC)).isNull();
    // Retrying with confirmation should successfully approve and add reviewers/CCs.
    input = ReviewInput.approve().reviewer(user.email).reviewer(mediumGroup, CC, true);
    result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.labels).isNotNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(2);
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.messages).hasSize(2);
    if (notesMigration.readChanges()) {
        assertReviewers(c, REVIEWER, admin, user);
        assertReviewers(c, CC, users.subList(0, mediumGroupSize));
    } else {
        // If not in NoteDb mode, then everyone is a REVIEWER.
        List<TestAccount> expected = users.subList(0, mediumGroupSize);
        expected.add(admin);
        expected.add(user);
        assertReviewers(c, REVIEWER, expected);
        assertReviewers(c, CC);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AddReviewerResult(com.google.gerrit.extensions.api.changes.AddReviewerResult) ArrayList(java.util.ArrayList) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with ReviewResult

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

the class ChangeReviewersIT method reviewAndAddReviewers.

@Test
public void reviewAndAddReviewers() throws Exception {
    TestAccount observer = accounts.user2();
    PushOneCommit.Result r = createChange();
    ReviewInput input = ReviewInput.approve().reviewer(user.email).reviewer(observer.email, CC, false);
    ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.labels).isNotNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(2);
    // Verify reviewer and CC were added. If not in NoteDb read mode, both
    // parties will be returned as CCed.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    if (notesMigration.readChanges()) {
        assertReviewers(c, REVIEWER, admin, user);
        assertReviewers(c, CC, observer);
    } else {
        // In legacy mode, everyone should be a reviewer.
        assertReviewers(c, REVIEWER, admin, user, observer);
        assertReviewers(c, CC);
    }
    // Verify emails were sent to added reviewers.
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(2);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.emailAddress, observer.emailAddress);
    assertThat(m.body()).contains(admin.fullName + " has posted comments on this change.");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertThat(m.body()).contains("Patch Set 1: Code-Review+2");
    m = messages.get(1);
    assertThat(m.rcpt()).containsExactly(user.emailAddress, observer.emailAddress);
    assertThat(m.body()).contains("Hello " + user.fullName + ",\n");
    assertThat(m.body()).contains("I'd like you to do a code review.");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testutil.FakeEmailSender.Message) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 10 with ReviewResult

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

the class ChangeReviewersIT method addSelfAsReviewer.

@Test
public void addSelfAsReviewer() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // user adds self as REVIEWER.
    ReviewInput input = new ReviewInput().reviewer(user.username);
    RestResponse resp = userRestSession.post("/changes/" + r.getChangeId() + "/revisions/" + r.getCommit().getName() + "/review", input);
    ReviewResult result = readContentFromJson(resp, 200, ReviewResult.class);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(1);
    // Verify reviewer state.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, user);
    assertReviewers(c, CC);
    LabelInfo label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(1);
    ApprovalInfo approval = label.all.get(0);
    assertThat(approval._accountId).isEqualTo(user.getId().get());
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)10 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)9 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)9 Test (org.junit.Test)8 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 RestResponse (com.google.gerrit.acceptance.RestResponse)5 AddReviewerResult (com.google.gerrit.extensions.api.changes.AddReviewerResult)4 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)4 TestAccount (com.google.gerrit.acceptance.TestAccount)3 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)3 AutoValue (com.google.auto.value.AutoValue)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Strings (com.google.common.base.Strings)1 ListMultimap (com.google.common.collect.ListMultimap)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Ordering (com.google.common.collect.Ordering)1