use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class AbstractSubmitOnPush method assertThatEmailsForChangeCreationAndSubmitWereSent.
/**
* Makes sure that two emails are sent: one for the change creation, and one for the submit.
*
* @param expected The account expected to receive message.
* @param expectedRecipientType The notification's type: To/Cc/Bcc. if {@code null} then it is not
* needed to check the recipientType. It is meant for -notify without other flags like
* notify-cc, notify-to, and notify-bcc. With the -notify flag, the message can sometimes be
* sent as "To" and sometimes can be sent as "Cc".
*/
private void assertThatEmailsForChangeCreationAndSubmitWereSent(TestAccount expected, @Nullable RecipientType expectedRecipientType) {
String expectedEmail = expected.email();
String expectedFullName = expected.fullName();
Address expectedAddress = Address.create(expectedFullName, expectedEmail);
assertThat(sender.getMessages()).hasSize(2);
Message message = sender.getMessages().get(0);
assertThat(message.body().contains("review")).isTrue();
assertAddress(message, expectedAddress, expectedRecipientType);
message = sender.getMessages().get(1);
assertThat(message.rcpt()).containsExactly(expectedAddress);
assertAddress(message, expectedAddress, expectedRecipientType);
assertThat(message.body().contains("submitted")).isTrue();
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeReviewersByEmailIT method addedReviewersGetNotified.
@Test
public void addedReviewersGetNotified() 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);
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
assertThat(messages.get(0).rcpt()).containsExactly(Address.parse(input.reviewer));
sender.clear();
}
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method reviewAndAddReviewers.
@Test
public void reviewAndAddReviewers() throws Exception {
TestAccount observer = accountCreator.user2();
PushOneCommit.Result r = createChange();
ReviewInput input = ReviewInput.approve().reviewer(user.email()).reviewer(observer.email(), CC, false);
ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(result.labels).isNotNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(2);
// Verify reviewer and CC were added.
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
assertReviewers(c, REVIEWER, admin, user);
assertReviewers(c, CC, observer);
// Verify emails were sent to added reviewers.
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(2);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail(), observer.getNameEmail());
assertThat(m.body()).contains(admin.fullName() + " has posted comments on this change.");
assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
assertThat(m.body()).contains("Patch Set 1: Code-Review+2");
m = messages.get(1);
assertThat(m.rcpt()).containsExactly(user.getNameEmail(), observer.getNameEmail());
assertThat(m.body()).contains("Hello " + user.fullName() + ",\n");
assertThat(m.body()).contains("I'd like you to do a code review.");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class CommentsIT method commentsOnRootCommitsAreIncludedInEmails.
@Test
public void commentsOnRootCommitsAreIncludedInEmails() throws Exception {
// Create a change in a new branch, making the patch-set commit a root commit.
ChangeInfo changeInfo = createChangeInNewBranch("newBranch");
Change.Id changeId = Change.Id.tryParse(Integer.toString(changeInfo._number)).get();
// Add a file.
gApi.changes().id(changeId.get()).edit().modifyFile("f1.txt", RawInputUtil.create("content"));
gApi.changes().id(changeId.get()).edit().publish();
email.clear();
ReviewerInput reviewerInput = new ReviewerInput();
reviewerInput.reviewer = admin.email();
gApi.changes().id(changeId.get()).addReviewer(reviewerInput);
changeInfo = gApi.changes().id(changeId.get()).get();
assertThat(email.getMessages()).hasSize(1);
Message message = email.getMessages().get(0);
assertThat(message.body()).contains("f1.txt");
email.clear();
// Send a comment. Make sure the email that is sent includes the comment text.
CommentInput c1 = CommentsUtil.newComment("f1.txt", Side.REVISION, /* line= */
1, /* message= */
"Comment text", /* unresolved= */
false);
CommentsUtil.addComments(gApi, changeId.toString(), changeInfo.currentRevision, c1);
assertThat(email.getMessages()).hasSize(1);
Message commentMessage = email.getMessages().get(0);
assertThat(commentMessage.body()).contains("Patch Set 2:\n" + "\n" + "(1 comment)\n" + "\n" + "File f1.txt:");
assertThat(commentMessage.body()).contains("PS2, Line 1: content\n" + "Comment text");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method sendNotificationOnChangeNotVisible.
@Test
public void sendNotificationOnChangeNotVisible() throws Exception {
String changeId = createChangeWithReview();
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
// Make change private so that it's no visible to user.
gApi.changes().id(changeId).setPrivate(true);
// Build Message
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "Test Message", null, null);
MailMessage.Builder b = messageBuilderWithDefaultFields().from(user.getNameEmail()).textContent(txt + textFooterForChange(changeInfo._number, ts));
sender.clear();
mailProcessor.process(b.build());
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("Gerrit Code Review was unable to process your email because the change was not" + " found.");
assertThat(message.headers()).containsKey("Subject");
}
Aggregations