Search in sources :

Example 11 with ReviewResult

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

the class ChangeIT method reviewAndMoveToWorkInProgress.

@Test
public void reviewAndMoveToWorkInProgress() throws Exception {
    PushOneCommit.Result r = createChange();
    assertThat(r.getChange().change().isWorkInProgress()).isFalse();
    ReviewInput in = ReviewInput.noScore().setWorkInProgress(true);
    ReviewResult result = gApi.changes().id(r.getChangeId()).current().review(in);
    assertThat(result.ready).isNull();
    ChangeInfo info = gApi.changes().id(r.getChangeId()).get();
    assertThat(info.workInProgress).isTrue();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) 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 12 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 = ReviewerModifier.DEFAULT_MAX_REVIEWERS + 1;
    int mediumGroupSize = ReviewerModifier.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 = groupOperations.newGroup().name("largeGroup").create().get();
    String mediumGroup = groupOperations.newGroup().name("mediumGroup").create().get();
    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 = accountCreator.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);
    ReviewerResult 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);
    assertReviewers(c, REVIEWER, admin, user);
    assertReviewers(c, CC, users.subList(0, mediumGroupSize));
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) 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) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 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(LabelId.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.
    c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, user);
    assertReviewers(c, CC);
    label = c.labels.get(LabelId.CODE_REVIEW);
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(1);
    Map<Integer, Integer> approvals = new HashMap<>();
    for (ApprovalInfo approval : label.all) {
        approvals.put(approval._accountId, approval.value);
    }
    assertThat(approvals).containsEntry(user.id().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, user);
    assertReviewers(c, CC);
    label = c.labels.get(LabelId.CODE_REVIEW);
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(1);
    approvals.clear();
    for (ApprovalInfo approval : label.all) {
        approvals.put(approval._accountId, approval.value);
    }
    assertThat(approvals).containsEntry(user.id().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) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 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 = accountCreator.create(name("user1"), emailPrefix + "user1@example.com", "User1", null);
    TestAccount user2 = accountCreator.create(name("user2"), emailPrefix + "user2@example.com", "User2", null);
    TestAccount user3 = accountCreator.create(name("user3"), emailPrefix + "user3@example.com", "User3", null);
    String group1 = groupOperations.newGroup().name("group1").create().get();
    String group2 = groupOperations.newGroup().name("group2").create().get();
    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);
    ReviewerResult 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
    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 : ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) 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) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with ReviewResult

use of com.google.gerrit.extensions.api.changes.ReviewResult 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);
    ReviewerResult reviewerResult = result.reviewers.get(user.email());
    assertThat(reviewerResult).isNotNull();
    assertThat(reviewerResult.confirm).isNull();
    assertThat(reviewerResult.error).isNull();
}
Also used : ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)19 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)17 Test (org.junit.Test)17 TestAccount (com.google.gerrit.acceptance.TestAccount)7 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)7 ArrayList (java.util.ArrayList)7 DraftHandling (com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling)6 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)6 Side (com.google.gerrit.extensions.client.Side)6 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)6 ChangeData (com.google.gerrit.server.query.change.ChangeData)6 Inject (com.google.inject.Inject)6 Timestamp (java.sql.Timestamp)6 Collection (java.util.Collection)6 List (java.util.List)6 Map (java.util.Map)6 Collectors.toList (java.util.stream.Collectors.toList)6