use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class PostReviewIT method addingReviewers.
@Test
public void addingReviewers() throws Exception {
PushOneCommit.Result r = createChange();
TestAccount user2 = accountCreator.user2();
TestReviewerAddedListener testReviewerAddedListener = new TestReviewerAddedListener();
try (Registration registration = extensionRegistry.newRegistration().add(testReviewerAddedListener)) {
// add user and user2
ReviewResult reviewResult = gApi.changes().id(r.getChangeId()).current().review(ReviewInput.create().reviewer(user.email()).reviewer(user2.email()));
assertThat(reviewResult.reviewers.values().stream().filter(a -> a.reviewers != null).map(a -> Iterables.getOnlyElement(a.reviewers).name).collect(toImmutableSet())).containsExactly(user.fullName(), user2.fullName());
}
assertThat(gApi.changes().id(r.getChangeId()).reviewers().stream().map(a -> a.name).collect(toImmutableSet())).containsExactly(user.fullName(), user2.fullName());
// Ensure only one batch email was sent for this operation
FakeEmailSender.Message message = Iterables.getOnlyElement(sender.getMessages());
assertThat(message.body()).containsMatch(Pattern.quote("Hello ") + "(" + Pattern.quote(String.format("%s, %s", user.fullName(), user2.fullName())) + "|" + Pattern.quote(String.format("%s, %s", user2.fullName(), user.fullName())) + ")");
assertThat(message.htmlBody()).containsMatch("(" + Pattern.quote(String.format("%s and %s", user.fullName(), user2.fullName())) + "|" + Pattern.quote(String.format("%s and %s", user2.fullName(), user.fullName())) + ")" + Pattern.quote(" to <strong>review</strong> this change"));
// Ensure that a batch event has been sent:
// * 1 batch event for adding user and user2 as reviewers
assertThat(testReviewerAddedListener.receivedEvents).hasSize(1);
assertThat(testReviewerAddedListener.getReviewerIds()).containsExactly(user.id(), user2.id());
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method stickyOnCopyValues.
@Test
public void stickyOnCopyValues() throws Exception {
TestAccount user2 = accountCreator.user2();
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().updateLabelType(LabelId.CODE_REVIEW, b -> b.setCopyValues(ImmutableList.of((short) -1, (short) 1)));
u.save();
}
for (ChangeKind changeKind : EnumSet.of(REWORK, TRIVIAL_REBASE, NO_CODE_CHANGE, MERGE_FIRST_PARENT_UPDATE, NO_CHANGE)) {
testRepo.reset(projectOperations.project(project).getHead("master"));
String changeId = changeKindCreator.createChange(changeKind, testRepo, admin);
vote(admin, changeId, -1, 1);
vote(user, changeId, -2, -1);
vote(user2, changeId, 1, -1);
changeKindCreator.updateChange(changeId, changeKind, testRepo, admin, project);
ChangeInfo c = detailedChange(changeId);
assertVotes(c, admin, -1, 0, changeKind);
assertVotes(c, user, 0, 0, changeKind);
assertVotes(c, user2, 1, 0, changeKind);
}
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithReviewerGroup.
@Test
public void pushForMasterWithReviewerGroup() throws Exception {
TestAccount user2 = accountCreator.user2();
String group = name("group");
GroupInput gin = new GroupInput();
gin.name = group;
gin.members = ImmutableList.of(user.username(), user2.username());
// TODO(dborowitz): Shouldn't be necessary; see ReviewerModifier.
gin.visibleToAll = true;
gApi.groups().create(gin);
PushOneCommit.Result r = pushTo("refs/for/master%r=" + group);
r.assertOkStatus();
r.assertChange(Change.Status.NEW, null, ImmutableList.of(user, user2), ImmutableList.of());
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithNotify.
@Test
public void pushForMasterWithNotify() throws Exception {
// create a user that watches the project
TestAccount user3 = accountCreator.create("user3", "user3@example.com", "User3", null);
List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
ProjectWatchInfo pwi = new ProjectWatchInfo();
pwi.project = project.get();
pwi.filter = "*";
pwi.notifyNewChanges = true;
projectsToWatch.add(pwi);
requestScopeOperations.setApiUser(user3.id());
gApi.accounts().self().setWatchedProjects(projectsToWatch);
TestAccount user2 = accountCreator.user2();
String pushSpec = "refs/for/master%reviewer=" + user.email() + ",cc=" + user2.email();
sender.clear();
PushOneCommit.Result r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE);
r.assertOkStatus();
assertThat(sender.getMessages()).isEmpty();
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.OWNER);
r.assertOkStatus();
// no email notification about own changes
assertThat(sender.getMessages()).isEmpty();
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.OWNER_REVIEWERS);
r.assertOkStatus();
assertThat(sender.getMessages()).hasSize(1);
Message m = sender.getMessages().get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.ALL);
r.assertOkStatus();
assertThat(sender.getMessages()).hasSize(1);
m = sender.getMessages().get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail(), user2.getNameEmail(), user3.getNameEmail());
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-to=" + user3.email());
r.assertOkStatus();
assertNotifyTo(user3);
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-cc=" + user3.email());
r.assertOkStatus();
assertNotifyCc(user3);
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-bcc=" + user3.email());
r.assertOkStatus();
assertNotifyBcc(user3);
// request that sender gets notified as TO, CC and BCC, email should be sent
// even if the sender is the only recipient
sender.clear();
pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-to=" + admin.email());
assertNotifyTo(admin);
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-cc=" + admin.email());
r.assertOkStatus();
assertNotifyCc(admin);
sender.clear();
r = pushTo(pushSpec + ",notify=" + NotifyHandling.NONE + ",notify-bcc=" + admin.email());
r.assertOkStatus();
assertNotifyBcc(admin);
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class AbstractPushForReview method pushForMasterWithReviewer.
@Test
public void pushForMasterWithReviewer() throws Exception {
// add one reviewer
String topic = "my/topic";
PushOneCommit.Result r = pushTo("refs/for/master%topic=" + topic + ",r=" + user.email());
r.assertOkStatus();
r.assertChange(Change.Status.NEW, topic, user);
// add several reviewers
TestAccount user2 = accountCreator.create("another-user", "another.user@example.com", "Another User", null);
r = pushTo("refs/for/master%topic=" + topic + ",r=" + admin.email() + ",r=" + user.email() + ",r=" + user2.email());
r.assertOkStatus();
// admin is the owner of the change and should not appear as reviewer
r.assertChange(Change.Status.NEW, topic, user, user2);
// add non-existing user as reviewer
String nonExistingEmail = "non.existing@example.com";
r = pushTo("refs/for/master%topic=" + topic + ",r=" + admin.email() + ",r=" + nonExistingEmail + ",r=" + user.email());
r.assertErrorStatus(nonExistingEmail + " does not identify a registered user or group");
}
Aggregations