use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeIT method removeCC.
@Test
public void removeCC() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
// Add a cc
ReviewerInput reviewerInput = new ReviewerInput();
reviewerInput.state = CC;
reviewerInput.reviewer = user.id().toString();
gApi.changes().id(changeId).addReviewer(reviewerInput);
// Remove a cc
sender.clear();
gApi.changes().id(changeId).reviewer(user.id().toString()).remove();
assertThat(gApi.changes().id(changeId).get().reviewers).isEmpty();
// Make sure the email for removing a cc is correct.
assertThat(sender.getMessages()).hasSize(1);
Message message = sender.getMessages().get(0);
assertThat(message.body()).contains("Removed cc " + user.getNameEmail() + ".");
// Make sure the change message for removing a reviewer is correct.
assertThat(Iterables.getLast(gApi.changes().id(changeId).messages()).message).isEqualTo("Removed cc " + user.getNameEmail() + ".");
ChangeMessageInfo changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).get().messages);
assertThat(changeMessageInfo.message).isEqualTo("Removed cc " + AccountTemplateUtil.getAccountTemplate(user.id()) + ".");
assertThat(changeMessageInfo.accountsInMessage).containsExactly(getAccountInfo(user.id()));
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeIT method implicitlyAddReviewerOnVotingReview.
@Test
public void implicitlyAddReviewerOnVotingReview() throws Exception {
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.recommend().message("LGTM"));
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.reviewers.get(REVIEWER).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id().get());
// Further test: remove the vote, then comment again. The user should be
// implicitly re-added to the ReviewerSet, as a CC.
requestScopeOperations.setApiUser(admin.id());
gApi.changes().id(r.getChangeId()).reviewer(user.id().toString()).remove();
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.reviewers.values()).isEmpty();
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(new ReviewInput().message("hi"));
c = gApi.changes().id(r.getChangeId()).get();
assertThat(c.reviewers.get(CC).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id().get());
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeIT method removeReviewerNoVotes.
@Test
public void removeReviewerNoVotes() throws Exception {
LabelType verified = label(LabelId.VERIFIED, value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(verified);
u.save();
}
projectOperations.project(project).forUpdate().add(allowLabel(verified.getName()).ref(RefNames.REFS_HEADS + "*").group(REGISTERED_USERS).range(-1, 1)).update();
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
gApi.changes().id(changeId).addReviewer(user.id().toString());
ChangeInfo c = gApi.changes().id(changeId).get(ListChangesOption.DETAILED_LABELS);
assertThat(getReviewers(c.reviewers.get(CC))).isEmpty();
assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactly(user.id());
sender.clear();
gApi.changes().id(changeId).reviewer(user.id().toString()).remove();
assertThat(gApi.changes().id(changeId).get().reviewers).isEmpty();
assertThat(sender.getMessages()).hasSize(1);
Message message = sender.getMessages().get(0);
assertThat(message.body()).contains("Removed reviewer " + user.getNameEmail() + ".");
assertThat(message.body()).doesNotContain("with the following votes");
// Make sure the change message for removing a reviewer is correct.
assertThat(Iterables.getLast(gApi.changes().id(changeId).messages()).message).isEqualTo("Removed reviewer " + user.getNameEmail() + ".");
ChangeMessageInfo changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).get().messages);
assertThat(changeMessageInfo.message).isEqualTo("Removed reviewer " + AccountTemplateUtil.getAccountTemplate(user.id()) + ".");
assertThat(changeMessageInfo.accountsInMessage).containsExactly(getAccountInfo(user.id()));
// Make sure the reviewer can still be added again.
gApi.changes().id(changeId).addReviewer(user.id().toString());
c = gApi.changes().id(changeId).get();
assertThat(getReviewers(c.reviewers.get(CC))).isEmpty();
assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactly(user.id());
// Remove again, and then try to remove once more to verify 404 is
// returned.
gApi.changes().id(changeId).reviewer(user.id().toString()).remove();
assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeId).reviewer(user.id().toString()).remove());
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeIT method emailNotificationForFileLevelComment.
@Test
public void emailNotificationForFileLevelComment() throws Exception {
String changeId = createChange().getChangeId();
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
gApi.changes().id(changeId).addReviewer(in);
sender.clear();
ReviewInput review = new ReviewInput();
ReviewInput.CommentInput comment = new ReviewInput.CommentInput();
comment.path = PushOneCommit.FILE_NAME;
comment.side = Side.REVISION;
comment.message = "comment 1";
review.comments = new HashMap<>();
review.comments.put(comment.path, Lists.newArrayList(comment));
gApi.changes().id(changeId).current().review(review);
assertThat(sender.getMessages()).hasSize(1);
Message m = sender.getMessages().get(0);
assertThat(m.rcpt()).containsExactly(user.getNameEmail());
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class ChangeIT method ignore.
@Test
public void ignore() throws Exception {
String email = "user2@example.com";
String fullname = "User2";
accountOperations.newAccount().username("user2").preferredEmail(email).fullname(fullname).create();
PushOneCommit.Result r = createChange();
ReviewerInput in = new ReviewerInput();
in.reviewer = user.email();
gApi.changes().id(r.getChangeId()).addReviewer(in);
in = new ReviewerInput();
in.reviewer = email;
gApi.changes().id(r.getChangeId()).addReviewer(in);
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).ignore(true);
assertThat(gApi.changes().id(r.getChangeId()).ignored()).isTrue();
// New patch set notification is not sent to users ignoring the change
sender.clear();
requestScopeOperations.setApiUser(admin.id());
amendChange(r.getChangeId());
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Address address = Address.create(fullname, email);
assertThat(messages.get(0).rcpt()).containsExactly(address);
// Review notification is not sent to users ignoring the change
sender.clear();
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
messages = sender.getMessages();
assertThat(messages).hasSize(1);
assertThat(messages.get(0).rcpt()).containsExactly(address);
// Abandoned notification is not sent to users ignoring the change
sender.clear();
gApi.changes().id(r.getChangeId()).abandon();
messages = sender.getMessages();
assertThat(messages).hasSize(1);
assertThat(messages.get(0).rcpt()).containsExactly(address);
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).ignore(false);
assertThat(gApi.changes().id(r.getChangeId()).ignored()).isFalse();
}
Aggregations