use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method sendNotificationOnMissingMetadatas.
@Test
public void sendNotificationOnMissingMetadatas() throws Exception {
String changeId = createChangeWithReview();
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
List<CommentInfo> comments = gApi.changes().id(changeId).current().commentsAsList();
assertThat(comments).hasSize(2);
// Erroneous timestamp to be used in erroneous metadatas
String ts = "null";
// 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("was unable to parse your email");
assertThat(message.headers()).containsKey("Subject");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method validateInlineComment_rejected.
@Test
public void validateInlineComment_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.INLINE_COMMENT, changeInfo.project, changeInfo._number);
MailMessage.Builder b = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", null, COMMENT_TEXT, 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");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method validateFileComment_rejected.
@Test
public void validateFileComment_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.FILE_COMMENT, changeInfo.project, changeInfo._number);
MailMessage.Builder b = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", null, null, COMMENT_TEXT);
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");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ProjectWatchIT method newPatchSetsNotifyConfig.
@Test
public void newPatchSetsNotifyConfig() throws Exception {
ImmutableList<String> messageFilters = ImmutableList.of("message:subject-with-tokens", "message:subject-with-tokens=secret");
ImmutableList.Builder<Address> watchers = ImmutableList.builder();
try (ProjectConfigUpdate u = updateProject(project)) {
for (int i = 0; i < messageFilters.size(); i++) {
Address addr = Address.create("Watcher#" + i, String.format("watcher-%s@example.com", i));
watchers.add(addr);
NotifyConfig.Builder nc = NotifyConfig.builder();
nc.addAddress(addr);
nc.setName("new-patch-set" + i);
nc.setHeader(NotifyConfig.Header.CC);
nc.setNotify(EnumSet.of(NotifyType.NEW_PATCHSETS));
nc.setFilter(messageFilters.get(i));
u.getConfig().putNotifyConfig("watch" + i, nc.build());
}
u.save();
}
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), testRepo, "original subject", "a", "a1").to("refs/for/master");
r.assertOkStatus();
r = pushFactory.create(admin.newIdent(), testRepo, "super sekret subject\n\nsubject-with-tokens=secret subject", "a", "a2", r.getChangeId()).to("refs/for/master");
r.assertOkStatus();
r = pushFactory.create(admin.newIdent(), testRepo, "back to original subject", "a", "a3").to("refs/for/master");
r.assertOkStatus();
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactlyElementsIn(watchers.build());
assertThat(m.body()).contains("Change subject: super sekret subject\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 2\n");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchProjectNotifyOnPrivateChange.
@Test
public void watchProjectNotifyOnPrivateChange() throws Exception {
String watchedProject = projectOperations.newProject().create().get();
// create group that can view all private changes
GroupInfo groupThatCanViewPrivateChanges = gApi.groups().create("groupThatCanViewPrivateChanges").get();
projectOperations.project(Project.nameKey(watchedProject)).forUpdate().add(allow(Permission.VIEW_PRIVATE_CHANGES).ref("refs/*").group(AccountGroup.uuid(groupThatCanViewPrivateChanges.id))).update();
// watch project as user that can't view private changes
requestScopeOperations.setApiUser(user.id());
watch(watchedProject);
// watch project as user that can view all private change
TestAccount userThatCanViewPrivateChanges = accountCreator.create("user2", "user2@example.com", "User2", null, groupThatCanViewPrivateChanges.name);
requestScopeOperations.setApiUser(userThatCanViewPrivateChanges.id());
watch(watchedProject);
// push a private change to watched project -> should trigger email notification for
// userThatCanViewPrivateChanges, but not for user
requestScopeOperations.setApiUser(admin.id());
TestRepository<InMemoryRepository> watchedRepo = cloneProject(Project.nameKey(watchedProject), admin);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), watchedRepo, "TRIGGER", "a", "a1").to("refs/for/master%private");
r.assertOkStatus();
// assert email notification
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(userThatCanViewPrivateChanges.getNameEmail());
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Aggregations