Search in sources :

Example 11 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method listReviewersByEmail.

@Test
public void listReviewersByEmail() throws Exception {
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        ReviewerInput input = new ReviewerInput();
        input.reviewer = toRfcAddressString(acc);
        input.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(input);
        RestResponse restResponse = adminRestSession.get("/changes/" + r.getChangeId() + "/reviewers/");
        restResponse.assertOK();
        Type type = new TypeToken<List<ReviewerInfo>>() {
        }.getType();
        List<ReviewerInfo> reviewers = newGson().fromJson(restResponse.getReader(), type);
        restResponse.consume();
        assertThat(reviewers).hasSize(1);
        ReviewerInfo reviewerInfo = Iterables.getOnlyElement(reviewers);
        assertThat(reviewerInfo._accountId).isNull();
        assertThat(reviewerInfo.name).isEqualTo(acc.name);
        assertThat(reviewerInfo.email).isEqualTo(acc.email);
    }
}
Also used : Type(java.lang.reflect.Type) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) RestResponse(com.google.gerrit.acceptance.RestResponse) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) ReviewerInfo(com.google.gerrit.extensions.api.changes.ReviewerInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 12 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method removingReviewerTriggersNotification.

@Test
public void removingReviewerTriggersNotification() throws Exception {
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        ReviewerInput addInput = new ReviewerInput();
        addInput.reviewer = toRfcAddressString(acc);
        addInput.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(addInput);
        // Review change as user
        ReviewInput reviewInput = new ReviewInput();
        reviewInput.message = "I have a comment";
        requestScopeOperations.setApiUser(user.id());
        revision(r).review(reviewInput);
        requestScopeOperations.setApiUser(admin.id());
        sender.clear();
        // Delete as admin
        gApi.changes().id(r.getChangeId()).reviewer(addInput.reviewer).remove();
        List<Message> messages = sender.getMessages();
        assertThat(messages).hasSize(1);
        assertThat(messages.get(0).rcpt()).containsExactly(Address.parse(addInput.reviewer), user.getNameEmail());
        sender.clear();
    }
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 13 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class Reviewers method display.

private void display(ChangeInfo info) {
    Map<ReviewerState, List<AccountInfo>> reviewers = info.reviewers();
    Map<Integer, AccountInfo> r = byAccount(reviewers, ReviewerState.REVIEWER);
    Map<Integer, AccountInfo> cc = byAccount(reviewers, ReviewerState.CC);
    for (Integer i : r.keySet()) {
        cc.remove(i);
    }
    cc.remove(info.owner()._accountId());
    Set<Integer> removable = info.removableReviewerIds();
    Map<Integer, VotableInfo> votable = votable(info);
    SafeHtml rHtml = Labels.formatUserList(style, r.values(), removable, null, votable);
    SafeHtml ccHtml = Labels.formatUserList(style, cc.values(), removable, null, votable);
    reviewersText.setInnerSafeHtml(rHtml);
    ccText.setInnerSafeHtml(ccHtml);
    if (Gerrit.isSignedIn()) {
        int currentUser = Gerrit.getUserAccount()._accountId();
        boolean showAddMeButton = info.owner()._accountId() != currentUser && !cc.containsKey(currentUser) && !r.containsKey(currentUser);
        addMe.setVisible(showAddMeButton);
    }
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) SafeHtml(com.google.gwtexpui.safehtml.client.SafeHtml) List(java.util.List) AccountInfo(com.google.gerrit.client.info.AccountInfo)

Example 14 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class PostReviewIT method votingMakesCallerReviewer.

@Test
public void votingMakesCallerReviewer() throws Exception {
    // Admin owns the change
    PushOneCommit.Result r = createChange();
    // User adds themselves and changes state
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 1);
    gApi.changes().id(r.getChangeId()).current().review(input);
    Map<ReviewerState, Collection<AccountInfo>> reviewers = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers).hasSize(1);
    AccountInfo reviewer = Iterables.getOnlyElement(reviewers.get(ReviewerState.REVIEWER));
    assertThat(reviewer._accountId).isEqualTo(user.id().get());
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with ReviewerState

use of com.google.gerrit.extensions.client.ReviewerState in project gerrit by GerritCodeReview.

the class PostReviewIT method reviewerToCc.

@Test
public void reviewerToCc() throws Exception {
    // Admin owns the change
    PushOneCommit.Result r = createChange();
    // User adds themselves and changes state
    requestScopeOperations.setApiUser(user.id());
    ReviewInput input = new ReviewInput().reviewer(user.id().toString());
    gApi.changes().id(r.getChangeId()).current().review(input);
    Map<ReviewerState, Collection<AccountInfo>> reviewers = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers).hasSize(1);
    AccountInfo reviewer = Iterables.getOnlyElement(reviewers.get(ReviewerState.REVIEWER));
    assertThat(reviewer._accountId).isEqualTo(user.id().get());
    // Reviewer -> CC
    ReviewInput input2 = new ReviewInput().reviewer(user.id().toString(), ReviewerState.CC, false);
    gApi.changes().id(r.getChangeId()).current().review(input2);
    Map<ReviewerState, Collection<AccountInfo>> reviewers2 = gApi.changes().id(r.getChangeId()).get().reviewers;
    assertThat(reviewers2).hasSize(1);
    AccountInfo reviewer2 = Iterables.getOnlyElement(reviewers2.get(ReviewerState.CC));
    assertThat(reviewer2._accountId).isEqualTo(user.id().get());
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ReviewerState (com.google.gerrit.extensions.client.ReviewerState)24 Test (org.junit.Test)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)19 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)18 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)10 Collection (java.util.Collection)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 List (java.util.List)7 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)4 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)4 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)4 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ImmutableList (com.google.common.collect.ImmutableList)3 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)3 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)3 RequestScopeOperations (com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations)3 BranchNameKey (com.google.gerrit.entities.BranchNameKey)3