use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeIT method testAddReviewerViaPostReview.
private void testAddReviewerViaPostReview(AddReviewerCaller addReviewer) throws Exception {
PushOneCommit.Result r = createChange();
ChangeResource rsrc = parseResource(r);
String oldETag = rsrc.getETag();
Instant oldTs = rsrc.getChange().getLastUpdatedOn();
addReviewer.call(r.getChangeId(), user.email());
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains("Hello " + user.fullName() + ",\n");
assertThat(m.body()).contains("I'd like you to do a code review.");
assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
assertMailReplyTo(m, admin.email());
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
// Adding a reviewer records that user as reviewer.
Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
assertThat(reviewers).isNotNull();
assertThat(reviewers).hasSize(1);
assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
// Nobody was added as CC.
assertThat(c.reviewers.get(CC)).isNull();
// Ensure ETag and lastUpdatedOn are updated.
rsrc = parseResource(r);
assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
// Change status of reviewer and ensure ETag is updated.
oldETag = rsrc.getETag();
accountOperations.account(user.id()).forUpdate().status("new status").update();
rsrc = parseResource(r);
assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeIT method pushCommitOfOtherUser.
@Test
public void pushCommitOfOtherUser() throws Exception {
// admin pushes commit of user
PushOneCommit push = pushFactory.create(user.newIdent(), testRepo);
PushOneCommit.Result result = push.to("refs/for/master");
result.assertOkStatus();
ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
assertThat(change.owner._accountId).isEqualTo(admin.id().get());
CommitInfo commit = change.revisions.get(change.currentRevision).commit;
assertThat(commit.author.email).isEqualTo(user.email());
assertThat(commit.committer.email).isEqualTo(user.email());
// check that the author/committer was added as cc
Collection<AccountInfo> reviewers = change.reviewers.get(CC);
assertThat(reviewers).isNotNull();
assertThat(reviewers).hasSize(1);
assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
assertThat(change.reviewers.get(REVIEWER)).isNull();
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.from().name()).isEqualTo("Administrator (Code Review)");
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains("has uploaded this change for review");
assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
assertMailReplyTo(m, admin.email());
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionNotifications.
@Test
public void revertSubmissionNotifications() throws Exception {
String firstResult = createChange("first change", "a.txt", "message").getChangeId();
approve(firstResult);
gApi.changes().id(firstResult).addReviewer(user.email());
String secondResult = createChange("second change", "b.txt", "other").getChangeId();
approve(secondResult);
gApi.changes().id(secondResult).addReviewer(user.email());
gApi.changes().id(secondResult).current().submit();
sender.clear();
RevertInput revertInput = new RevertInput();
revertInput.notify = NotifyHandling.ALL;
RevertSubmissionInfo revertChanges = gApi.changes().id(secondResult).revertSubmission(revertInput);
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(4);
assertThat(sender.getMessages(revertChanges.revertChanges.get(0).changeId, "newchange")).hasSize(1);
assertThat(sender.getMessages(firstResult, "revert")).hasSize(1);
assertThat(sender.getMessages(revertChanges.revertChanges.get(1).changeId, "newchange")).hasSize(1);
assertThat(sender.getMessages(secondResult, "revert")).hasSize(1);
}
use of com.google.gerrit.testing.FakeEmailSender.Message 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.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class AccountIT method adminCanAddOrRemoveSshKeyOnOtherAccount.
@Test
@UseSsh
public void adminCanAddOrRemoveSshKeyOnOtherAccount() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
// The test account should initially have exactly one ssh key
List<SshKeyInfo> info = gApi.accounts().self().listSshKeys();
assertThat(info).hasSize(1);
assertSequenceNumbers(info);
SshKeyInfo key = info.get(0);
KeyPair keyPair = sshKeys.getKeyPair(admin);
String initial = TestSshKeys.publicKey(keyPair, admin.email());
assertThat(key.sshPublicKey).isEqualTo(initial);
accountIndexedCounter.assertNoReindex();
// Add a new key
sender.clear();
String newKey = TestSshKeys.publicKey(SshSessionFactory.genSshKey(), user.email());
gApi.accounts().id(user.username()).addSshKey(newKey);
info = gApi.accounts().id(user.username()).listSshKeys();
assertThat(info).hasSize(2);
assertSequenceNumbers(info);
accountIndexedCounter.assertReindexOf(user);
assertThat(sender.getMessages()).hasSize(1);
Message message = sender.getMessages().get(0);
assertThat(message.rcpt()).containsExactly(user.getNameEmail());
assertThat(message.body()).contains("new SSH keys have been added");
// Delete key
sender.clear();
gApi.accounts().id(user.username()).deleteSshKey(1);
info = gApi.accounts().id(user.username()).listSshKeys();
assertThat(info).hasSize(1);
accountIndexedCounter.assertReindexOf(user);
assertThat(sender.getMessages()).hasSize(1);
message = sender.getMessages().get(0);
assertThat(message.rcpt()).containsExactly(user.getNameEmail());
assertThat(message.body()).contains("SSH keys have been deleted");
}
}
Aggregations