Search in sources :

Example 66 with ReviewInput

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

the class ChangeReviewersIT method addDuplicateReviewers.

@Test
public void addDuplicateReviewers() throws Exception {
    PushOneCommit.Result r = createChange();
    ReviewInput input = ReviewInput.approve().reviewer(user.email).reviewer(user.email);
    ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(1);
    AddReviewerResult reviewerResult = result.reviewers.get(user.email);
    assertThat(reviewerResult).isNotNull();
    assertThat(reviewerResult.confirm).isNull();
    assertThat(reviewerResult.error).isNull();
}
Also used : AddReviewerResult(com.google.gerrit.extensions.api.changes.AddReviewerResult) 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 67 with ReviewInput

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

the class ChangeReviewersIT method driveByComment.

@Test
public void driveByComment() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // Post drive-by message as user.
    ReviewInput input = new ReviewInput().message("hello");
    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).isNull();
    // Verify user is added to CC list.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    if (notesMigration.readChanges()) {
        assertReviewers(c, REVIEWER);
        assertReviewers(c, CC, user);
    } else {
        // If we aren't reading from NoteDb, the user will appear as a
        // reviewer.
        assertReviewers(c, REVIEWER, user);
        assertReviewers(c, CC);
    }
}
Also used : 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)

Example 68 with ReviewInput

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

the class ChangeReviewersIT method addSelfAsCc.

@Test
public void addSelfAsCc() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // user adds self as CC.
    ReviewInput input = new ReviewInput().reviewer(user.username, CC, false);
    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();
    if (notesMigration.readChanges()) {
        assertReviewers(c, REVIEWER);
        assertReviewers(c, CC, user);
        // Verify no approvals were added.
        assertThat(c.labels).isNotNull();
        LabelInfo label = c.labels.get("Code-Review");
        assertThat(label).isNotNull();
        assertThat(label.all).isNull();
    } else {
        // When approvals are stored in ReviewDb, we still create a label for
        // the reviewing user, and force them into the REVIEWER state.
        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)

Example 69 with ReviewInput

use of com.google.gerrit.extensions.api.changes.ReviewInput 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 70 with ReviewInput

use of com.google.gerrit.extensions.api.changes.ReviewInput 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)

Aggregations

ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)103 Test (org.junit.Test)85 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)77 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)70 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)25 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)20 Change (com.google.gerrit.reviewdb.client.Change)16 ArrayList (java.util.ArrayList)15 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)13 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)13 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)12 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)12 RevisionApi (com.google.gerrit.extensions.api.changes.RevisionApi)11 LabelType (com.google.gerrit.common.data.LabelType)10 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 RestResponse (com.google.gerrit.acceptance.RestResponse)8 TestAccount (com.google.gerrit.acceptance.TestAccount)8