use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class CommentsIT method publishCommentsAllRevisions.
@Test
public void publishCommentsAllRevisions() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "initial content\n", changeId).to("refs/heads/master");
PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "old boring content\n").to("refs/for/master");
PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "new interesting\ncntent\n", r1.getChangeId()).to("refs/for/master");
addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "Is it that bad?"));
addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, createLineRange(0, 7), "what happened to this?"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 15), "better now"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "typo: content"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 1, "comment 1 on base"));
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 2, "comment 2 on base"));
PushOneCommit.Result other = createChange();
// Drafts on other changes aren't returned.
addDraft(other.getChangeId(), other.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 1, "unrelated comment"));
requestScopeOperations.setApiUser(admin.id());
// Drafts by other users aren't returned.
addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "oops"));
requestScopeOperations.setApiUser(user.id());
ReviewInput reviewInput = new ReviewInput();
reviewInput.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
reviewInput.message = "comments";
gApi.changes().id(r2.getChangeId()).current().review(reviewInput);
assertThat(gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).drafts()).isEmpty();
Map<String, List<CommentInfo>> ps1Map = gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).comments();
assertThat(ps1Map.keySet()).containsExactly(FILE_NAME);
List<CommentInfo> ps1List = ps1Map.get(FILE_NAME);
assertThat(ps1List).hasSize(2);
assertThat(ps1List.get(0).message).isEqualTo("what happened to this?");
assertThat(ps1List.get(0).side).isEqualTo(Side.PARENT);
assertThat(ps1List.get(1).message).isEqualTo("Is it that bad?");
assertThat(ps1List.get(1).side).isNull();
assertThat(gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).drafts()).isEmpty();
Map<String, List<CommentInfo>> ps2Map = gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).comments();
assertThat(ps2Map.keySet()).containsExactly(FILE_NAME);
List<CommentInfo> ps2List = ps2Map.get(FILE_NAME);
assertThat(ps2List).hasSize(4);
assertThat(ps2List.get(0).message).isEqualTo("comment 1 on base");
assertThat(ps2List.get(1).message).isEqualTo("comment 2 on base");
assertThat(ps2List.get(2).message).isEqualTo("better now");
assertThat(ps2List.get(3).message).isEqualTo("typo: content");
List<Message> messages = email.getMessages(r2.getChangeId(), "comment");
assertThat(messages).hasSize(1);
String url = canonicalWebUrl.get();
int c = r1.getChange().getId().get();
assertThat(extractComments(messages.get(0).body())).isEqualTo("Patch Set 2:\n" + "\n" + "(6 comments)\n" + "\n" + "comments\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(0).id + " \n" + "PS1, Line 1: initial\n" + "what happened to this?\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(1).id + " \n" + "PS1, Line 1: boring\n" + "Is it that bad?\n" + "\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(0).id + " \n" + "PS2, Line 1: initial content\n" + "comment 1 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(1).id + " \n" + "PS2, Line 2: \n" + "comment 2 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(2).id + " \n" + "PS2, Line 1: interesting\n" + "better now\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(3).id + " \n" + "PS2, Line 2: cntent\n" + "typo: content\n" + "\n" + "\n");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class RevertIT method revertSubmissionPreservesReviewersAndCcs.
@Test
public void revertSubmissionPreservesReviewersAndCcs() throws Exception {
String change = createChange("first change", "a.txt", "message").getChangeId();
ReviewInput in = ReviewInput.approve();
in.reviewer(user.email());
in.reviewer(accountCreator.user2().email(), ReviewerState.CC, true);
// Add user as reviewer that will create the revert
in.reviewer(accountCreator.admin2().email());
gApi.changes().id(change).current().review(in);
gApi.changes().id(change).current().submit();
// expect both the original reviewers and CCs to be preserved
// original owner should be added as reviewer, user requesting the revert (new owner) removed
requestScopeOperations.setApiUser(accountCreator.admin2().id());
Map<ReviewerState, Collection<AccountInfo>> result = getChangeApis(gApi.changes().id(change).revertSubmission()).get(0).get().reviewers;
assertThat(result).containsKey(ReviewerState.REVIEWER);
List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
assertThat(result).containsKey(ReviewerState.CC);
List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
assertThat(ccs).containsExactly(accountCreator.user2().id().get());
assertThat(reviewers).containsExactly(user.id().get(), admin.id().get());
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class RevertIT method revertNotifications.
@Test
public void revertNotifications() throws Exception {
PushOneCommit.Result r = createChange();
gApi.changes().id(r.getChangeId()).addReviewer(user.email());
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).submit();
sender.clear();
ChangeInfo revertChange = gApi.changes().id(r.getChangeId()).revert().get();
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(2);
assertThat(sender.getMessages(revertChange.changeId, "newchange")).hasSize(1);
assertThat(sender.getMessages(r.getChangeId(), "revert")).hasSize(1);
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method addCcGroup.
@Test
public void addCcGroup() throws Exception {
List<TestAccount> users = createAccounts(6, "addCcGroup");
List<String> usernames = new ArrayList<>(6);
for (TestAccount u : users) {
usernames.add(u.username());
}
List<TestAccount> firstUsers = users.subList(0, 3);
List<String> firstUsernames = usernames.subList(0, 3);
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
ReviewerInput in = new ReviewerInput();
in.reviewer = groupOperations.newGroup().name("cc1").create().get();
in.state = CC;
gApi.groups().id(in.reviewer).addMembers(firstUsernames.toArray(new String[firstUsernames.size()]));
ReviewerResult result = addReviewer(changeId, in);
assertThat(result.input).isEqualTo(in.reviewer);
assertThat(result.confirm).isNull();
assertThat(result.error).isNull();
assertThat(result.reviewers).isNull();
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
assertReviewers(c, CC, firstUsers);
// Verify emails were sent to each of the group's accounts.
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
List<Address> expectedAddresses = new ArrayList<>(firstUsers.size());
for (TestAccount u : firstUsers) {
expectedAddresses.add(u.getNameEmail());
}
assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
// CC a group that overlaps with some existing reviewers and CCed accounts.
TestAccount reviewer = accountCreator.create(name("reviewer"), "addCcGroup-reviewer@example.com", "Reviewer", null);
result = addReviewer(changeId, reviewer.username());
assertThat(result.error).isNull();
sender.clear();
in.reviewer = groupOperations.newGroup().name("cc2").create().get();
gApi.groups().id(in.reviewer).addMembers(usernames.toArray(new String[usernames.size()]));
gApi.groups().id(in.reviewer).addMembers(reviewer.username());
result = addReviewer(changeId, in);
assertThat(result.input).isEqualTo(in.reviewer);
assertThat(result.confirm).isNull();
assertThat(result.error).isNull();
c = gApi.changes().id(r.getChangeId()).get();
assertThat(result.ccs).hasSize(3);
assertThat(result.reviewers).isNull();
assertReviewers(c, REVIEWER, reviewer);
assertReviewers(c, CC, users);
messages = sender.getMessages();
assertThat(messages).hasSize(1);
m = messages.get(0);
expectedAddresses = new ArrayList<>(4);
for (int i = 0; i < 3; i++) {
expectedAddresses.add(users.get(users.size() - i - 1).getNameEmail());
}
expectedAddresses.add(reviewer.getNameEmail());
assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class CreateChangeIT method notificationsOnChangeCreation.
@Test
public void notificationsOnChangeCreation() throws Exception {
requestScopeOperations.setApiUser(user.id());
watch(project.get());
// check that watcher is notified
requestScopeOperations.setApiUser(admin.id());
assertCreateSucceeds(newChangeInput(ChangeStatus.NEW));
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
assertThat(m.body()).contains(admin.fullName() + " has uploaded this change for review.");
// check that watcher is not notified if notify=NONE
sender.clear();
ChangeInput input = newChangeInput(ChangeStatus.NEW);
input.notify = NotifyHandling.NONE;
assertCreateSucceeds(input);
assertThat(sender.getMessages()).isEmpty();
}
Aggregations