use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method validateChangeMessage_rejected.
@Test
public void validateChangeMessage_rejected() 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")));
setupFailValidation(CommentForValidation.CommentType.CHANGE_MESSAGE, changeInfo.project, changeInfo._number);
MailMessage.Builder b = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", COMMENT_TEXT, null, null);
b.textContent(txt + textFooterForChange(changeInfo._number, ts));
List<CommentInfo> commentsBefore = testCommentHelper.getPublishedComments(changeId);
mailProcessor.process(b.build());
assertThat(testCommentHelper.getPublishedComments(changeId)).isEqualTo(commentsBefore);
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("rejected one or more comments");
// ensure the message header contains a valid message id.
assertThat(((StringEmailHeader) message.headers().get("Message-ID")).getString()).containsMatch("<someid-REJECTION-HTML@" + new URL(canonicalWebUrl.get()).getHost() + ">");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchAllProjects.
@Test
public void watchAllProjects() throws Exception {
String anyProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
// watch the All-Projects project to watch all projects
watch(allProjects.get());
// push a change to any project -> should trigger email notification
requestScopeOperations.setApiUser(admin.id());
TestRepository<InMemoryRepository> anyRepo = cloneProject(Project.nameKey(anyProject), admin);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), anyRepo, "TRIGGER", "a", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class AccountIT method addEmailSendsConfirmationEmail.
@Test
@GerritConfig(name = "auth.registerEmailPrivateKey", value = "HsOc6l_2lhS9G7sE_RsnS7Z6GJjdRDX14co=")
public void addEmailSendsConfirmationEmail() throws Exception {
String email = "new.email@example.com";
EmailInput input = newEmailInput(email, false);
gApi.accounts().self().addEmail(input);
assertThat(sender.getMessages()).hasSize(1);
Message m = sender.getMessages().get(0);
assertThat(m.rcpt()).containsExactly(Address.create(email));
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class AccountIT method addExistingReviewersUsingAddReviewer.
@Test
public void addExistingReviewersUsingAddReviewer() throws Exception {
PushOneCommit.Result r = createChange();
// First reviewer added to the change
ReviewerInput reviewerInput = new ReviewerInput();
reviewerInput.reviewer = user.email();
gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput);
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message message = messages.get(0);
assertThat(message.rcpt()).containsExactly(user.getNameEmail());
assertMailReplyTo(message, admin.email());
sender.clear();
// Second reviewer added to the change
TestAccount user2 = accountCreator.user2();
ReviewerInput reviewerInput2 = new ReviewerInput();
reviewerInput2.reviewer = user2.email();
gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput2);
List<Message> messages2 = sender.getMessages();
assertThat(messages2).hasSize(1);
Message message2 = messages2.get(0);
assertThat(message2.rcpt()).containsExactly(user.getNameEmail(), user2.getNameEmail());
assertMailReplyTo(message2, admin.email());
sender.clear();
// Exiting reviewer re-added to the change: no notifications
ReviewerInput reviewerInput3 = new ReviewerInput();
reviewerInput3.reviewer = user2.email();
gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput3);
List<Message> messages3 = sender.getMessages();
assertThat(messages3).isEmpty();
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class AccountIT method addReviewerToIgnoredChange.
@Test
public void addReviewerToIgnoredChange() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).ignore(true);
sender.clear();
requestScopeOperations.setApiUser(admin.id());
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
gApi.changes().id(r.getChangeId()).addReviewer(in);
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(0);
}
}
Aggregations