Search in sources :

Example 1 with ReviewerResult

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

the class ChangeReviewersByEmailIT method addExistingReviewerByEmailShortCircuits.

@Test
public void addExistingReviewerByEmailShortCircuits() throws Exception {
    PushOneCommit.Result r = createChange();
    ReviewerInput input = new ReviewerInput();
    input.reviewer = "nonexisting@example.com";
    input.state = ReviewerState.REVIEWER;
    ReviewerResult result = gApi.changes().id(r.getChangeId()).addReviewer(input);
    assertThat(result.reviewers).hasSize(1);
    ReviewerInfo info = result.reviewers.get(0);
    assertThat(info._accountId).isNull();
    assertThat(info.email).isEqualTo(input.reviewer);
    assertThat(gApi.changes().id(r.getChangeId()).addReviewer(input).reviewers).isEmpty();
}
Also used : ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) 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 2 with ReviewerResult

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

the class ChangeReviewersByEmailIT method addExistingCcByEmailShortCircuits.

@Test
public void addExistingCcByEmailShortCircuits() throws Exception {
    PushOneCommit.Result r = createChange();
    ReviewerInput input = new ReviewerInput();
    input.reviewer = "nonexisting@example.com";
    input.state = ReviewerState.CC;
    ReviewerResult result = gApi.changes().id(r.getChangeId()).addReviewer(input);
    assertThat(result.ccs).hasSize(1);
    AccountInfo info = result.ccs.get(0);
    assertThat(info._accountId).isNull();
    assertThat(info.email).isEqualTo(input.reviewer);
    assertThat(gApi.changes().id(r.getChangeId()).addReviewer(input).ccs).isEmpty();
}
Also used : ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with ReviewerResult

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

the class ChangeReviewersByEmailIT method rejectMalformedEmail.

@Test
public void rejectMalformedEmail() throws Exception {
    PushOneCommit.Result r = createChange();
    ReviewerResult result = gApi.changes().id(r.getChangeId()).addReviewer("Foo Bar <foo.bar@");
    assertThat(result.error).isEqualTo("Foo Bar <foo.bar@ is not a valid user identifier");
    assertThat(result.reviewers).isNull();
}
Also used : ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with ReviewerResult

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

the class ChangeReviewersIT method addCcAccount.

@Test
public void addCcAccount() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    in.state = CC;
    ReviewerResult result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(user.email());
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertThat(result.reviewers).isNull();
    assertThat(result.ccs).hasSize(1);
    AccountInfo ai = result.ccs.get(0);
    assertThat(ai._accountId).isEqualTo(user.id().get());
    assertReviewers(c, CC, user);
    // Verify email was sent to CCed account.
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    assertThat(m.body()).contains(admin.fullName() + " has uploaded this change for review.");
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) 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 ReviewerResult

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

the class ChangeReviewersIT method addGroupAsReviewer.

@Test
public void addGroupAsReviewer() throws Exception {
    // Set up two groups, one that is too large too add as reviewer, and one
    // that is too large to add without confirmation.
    String largeGroup = groupOperations.newGroup().name("largeGroup").create().get();
    String mediumGroup = groupOperations.newGroup().name("mediumGroup").create().get();
    int largeGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS + 1;
    int mediumGroupSize = ReviewerModifier.DEFAULT_MAX_REVIEWERS_WITHOUT_CHECK + 1;
    List<TestAccount> users = createAccounts(largeGroupSize, "addGroupAsReviewer");
    List<String> largeGroupUsernames = new ArrayList<>(mediumGroupSize);
    for (TestAccount u : users) {
        largeGroupUsernames.add(u.username());
    }
    List<String> mediumGroupUsernames = largeGroupUsernames.subList(0, mediumGroupSize);
    gApi.groups().id(largeGroup).addMembers(largeGroupUsernames.toArray(new String[largeGroupSize]));
    gApi.groups().id(mediumGroup).addMembers(mediumGroupUsernames.toArray(new String[mediumGroupSize]));
    // Attempt to add overly large group as reviewers.
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ReviewerResult result = addReviewer(changeId, largeGroup);
    assertThat(result.input).isEqualTo(largeGroup);
    assertThat(result.confirm).isNull();
    assertThat(result.error).contains("has too many members to add them all as reviewers");
    assertThat(result.reviewers).isNull();
    // Attempt to add medium group without confirmation.
    result = addReviewer(changeId, mediumGroup);
    assertThat(result.input).isEqualTo(mediumGroup);
    assertThat(result.confirm).isTrue();
    assertThat(result.error).contains("has " + mediumGroupSize + " members. Do you want to add them all as reviewers?");
    assertThat(result.reviewers).isNull();
    // Add medium group with confirmation.
    ReviewerInput in = new ReviewerInput();
    in.reviewer = mediumGroup;
    in.confirmed = true;
    result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(mediumGroup);
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    assertThat(result.reviewers).hasSize(mediumGroupSize);
    // Verify that group members were added as reviewers.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, 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) 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

ReviewerResult (com.google.gerrit.extensions.api.changes.ReviewerResult)19 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)18 Test (org.junit.Test)18 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)13 TestAccount (com.google.gerrit.acceptance.TestAccount)7 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)5 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)5 Account (com.google.gerrit.entities.Account)4 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)4 ReviewerInfo (com.google.gerrit.extensions.api.changes.ReviewerInfo)4 ArrayList (java.util.ArrayList)4 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)3 Address (com.google.gerrit.entities.Address)2 Message (com.google.gerrit.testing.FakeEmailSender.Message)2 AutoValue (com.google.auto.value.AutoValue)1 Joiner (com.google.common.base.Joiner)1 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 Strings (com.google.common.base.Strings)1