use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnAllRevisions.
@Test
public void publishCommentsOnPushPublishesDraftsOnAllRevisions() throws Exception {
PushOneCommit.Result r = createChange();
String rev1 = r.getCommit().name();
CommentInfo c1 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment1"));
CommentInfo c2 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment2"));
r = amendChange(r.getChangeId());
String rev2 = r.getCommit().name();
CommentInfo c3 = addDraft(r.getChangeId(), rev2, newDraft(FILE_NAME, 1, "comment3"));
assertThat(getPublishedComments(r.getChangeId())).isEmpty();
gApi.changes().id(r.getChangeId()).addReviewer(user.email());
sender.clear();
amendChange(r.getChangeId(), "refs/for/master%publish-comments");
Collection<CommentInfo> comments = getPublishedComments(r.getChangeId());
assertThat(comments.stream().map(c -> c.id)).containsExactly(c1.id, c2.id, c3.id);
assertThat(comments.stream().map(c -> c.message)).containsExactly("comment1", "comment2", "comment3");
/* Assert the correctness of the API messages */
List<ChangeMessageInfo> allMessages = getMessages(r.getChangeId());
List<String> messagesText = allMessages.stream().map(m -> m.message).collect(toList());
assertThat(messagesText).containsExactly("Uploaded patch set 1.", "Uploaded patch set 2.", "Uploaded patch set 3.", "Patch Set 3:\n\n(3 comments)").inOrder();
/* Assert the tags - PS#2 comments do not have tags, PS#3 upload is autogenerated */
List<String> messagesTags = allMessages.stream().map(m -> m.tag).collect(toList());
assertThat(messagesTags.get(2)).isEqualTo("autogenerated:gerrit:newPatchSet");
assertThat(messagesTags.get(3)).isNull();
/* Assert the correctness of the emails sent */
List<String> emailMessages = sender.getMessages().stream().map(Message::body).sorted(Comparator.comparingInt(m -> m.contains("reexamine") ? 0 : 1)).collect(toList());
assertThat(emailMessages).hasSize(2);
assertThat(emailMessages.get(0)).contains("Gerrit-MessageType: newpatchset");
assertThat(emailMessages.get(0)).contains("I'd like you to reexamine a change");
assertThat(emailMessages.get(0)).doesNotContain("Uploaded patch set 3");
assertThat(emailMessages.get(1)).contains("Gerrit-MessageType: comment");
assertThat(emailMessages.get(1)).contains("Patch Set 3:\n\n(3 comments)");
assertThat(emailMessages.get(1)).contains("PS1, Line 1:");
assertThat(emailMessages.get(1)).contains("PS2, Line 1:");
/* Assert the correctness of the NoteDb change meta commits */
List<RevCommit> commitMessages = getChangeMetaCommitsInReverseOrder(r.getChange().getId());
assertThat(commitMessages).hasSize(5);
assertThat(commitMessages.get(0).getShortMessage()).isEqualTo("Create change");
assertThat(commitMessages.get(1).getShortMessage()).isEqualTo("Create patch set 2");
assertThat(commitMessages.get(2).getShortMessage()).isEqualTo("Update patch set 2");
assertThat(commitMessages.get(3).getShortMessage()).isEqualTo("Create patch set 3");
assertThat(commitMessages.get(4).getFullMessage()).isEqualTo("Update patch set 3\n" + "\n" + "Patch Set 3:\n" + "\n" + "(3 comments)\n" + "\n" + "Patch-set: 3\n");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchProject.
@Test
public void watchProject() throws Exception {
// watch project
String watchedProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
watch(watchedProject);
// push a change to watched project -> should trigger email notification
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");
r.assertOkStatus();
// push a change to non-watched project -> should not trigger email
// notification
String notWatchedProject = projectOperations.newProject().create().get();
TestRepository<InMemoryRepository> notWatchedRepo = cloneProject(Project.nameKey(notWatchedProject), admin);
r = pushFactory.create(admin.newIdent(), notWatchedRepo, "DONT_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 ProjectWatchIT method watchFileAllProjects.
@Test
public void watchFileAllProjects() throws Exception {
String anyProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
// watch file in All-Projects project as user to watch the file in all
// projects
watch(allProjects.get(), "file:a.txt");
// push a change to watched file in any project -> should trigger email
// notification for user
requestScopeOperations.setApiUser(admin.id());
TestRepository<InMemoryRepository> anyRepo = cloneProject(Project.nameKey(anyProject), admin);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), anyRepo, "TRIGGER", "a.txt", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification for user
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");
sender.clear();
// watch project as user2
TestAccount user2 = accountCreator.create("user2", "user2@example.com", "User2", null);
requestScopeOperations.setApiUser(user2.id());
watch(anyProject);
// push a change to non-watched file in any project -> should not trigger
// email notification for user, only for user2
r = pushFactory.create(admin.newIdent(), anyRepo, "TRIGGER_USER2", "b.txt", "b1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
messages = sender.getMessages();
assertThat(messages).hasSize(1);
m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user2.getNameEmail());
assertThat(m.body()).contains("Change subject: TRIGGER_USER2\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchKeywordAllProjects.
@Test
public void watchKeywordAllProjects() throws Exception {
String anyProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
// watch keyword in project as user
watch(allProjects.get(), "multiprimary");
// push a change with keyword 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, "Document multiprimary setup", "a.txt", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification for user
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: Document multiprimary setup\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
sender.clear();
// push a change without keyword to any project -> should not trigger email
// notification
r = pushFactory.create(admin.newIdent(), anyRepo, "Cleanup cache implementation", "b.txt", "b1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
assertThat(sender.getMessages()).isEmpty();
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchFile.
@Test
public void watchFile() throws Exception {
String watchedProject = projectOperations.newProject().create().get();
String otherWatchedProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
// watch file in project as user
watch(watchedProject, "file:a.txt");
// watch other project as user
watch(otherWatchedProject);
// push a change to watched file -> should trigger email notification for
// user
requestScopeOperations.setApiUser(admin.id());
TestRepository<InMemoryRepository> watchedRepo = cloneProject(Project.nameKey(watchedProject), admin);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), watchedRepo, "TRIGGER", "a.txt", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification for user
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");
sender.clear();
// watch project as user2
TestAccount user2 = accountCreator.create("user2", "user2@example.com", "User2", null);
requestScopeOperations.setApiUser(user2.id());
watch(watchedProject);
// push a change to non-watched file -> should not trigger email
// notification for user, only for user2
r = pushFactory.create(admin.newIdent(), watchedRepo, "TRIGGER_USER2", "b.txt", "b1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
messages = sender.getMessages();
assertThat(messages).hasSize(1);
m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user2.getNameEmail());
assertThat(m.body()).contains("Change subject: TRIGGER_USER2\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Aggregations