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();
}
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();
}
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();
}
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.");
}
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));
}
Aggregations