use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method sendNotificationOnProjectNotFound.
@Test
public void sendNotificationOnProjectNotFound() throws Exception {
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(TimeUtil.now(), ZoneId.of("UTC")));
String changeUrl = canonicalWebUrl.get() + "c/non-existing-project/+/123";
// Build Message
String txt = newPlaintextBody(changeUrl + "/1", "Test Message", null, null);
MailMessage.Builder b = messageBuilderWithDefaultFields().from(user.getNameEmail()).textContent(txt + textFooterForChange(123, ts));
sender.clear();
mailProcessor.process(b.build());
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("Gerrit Code Review was unable to process your email because the change was not" + " found.");
assertThat(message.headers()).containsKey("Subject");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method limitNumberOfComments.
@Test
@GerritConfig(name = "change.maxComments", value = "9")
public void limitNumberOfComments() throws Exception {
// This change has 2 change messages and 2 comments.
String changeId = createChangeWithReview();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.message = "foo";
commentInput.path = FILE_NAME;
RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields(FILE_NAME);
ReviewInput reviewInput = new ReviewInput();
reviewInput.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(commentInput));
reviewInput.robotComments = ImmutableMap.of(FILE_NAME, ImmutableList.of(robotCommentInput));
// Add 1 change message and another 2 comments. Total count is now 7, which is still OK.
gApi.changes().id(changeId).current().review(reviewInput);
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
MailMessage.Builder mailMessage = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "1) change message", "2) reply to comment", "3) file comment");
mailMessage.textContent(txt + textFooterForChange(changeInfo._number, ts));
ImmutableSet<CommentInfo> commentsBefore = getCommentsAndRobotComments(changeId);
// Should have 4 comments (and 3 change messages).
assertThat(commentsBefore).hasSize(4);
// The email adds 3 new comments (of which 1 is the change message).
mailProcessor.process(mailMessage.build());
ImmutableSet<CommentInfo> commentsAfter = getCommentsAndRobotComments(changeId);
assertThat(commentsAfter).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 sendNotificationOnProjectNotVisible.
@Test
public void sendNotificationOnProjectNotVisible() 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")));
// Block read permissions on the project.
projectOperations.project(project).forUpdate().add(block(Permission.READ).ref("refs/*").group(REGISTERED_USERS)).update();
// 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("Gerrit Code Review was unable to process your email because the change was not" + " found.");
assertThat(message.headers()).containsKey("Subject");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method sendNotificationOnChangeNotFound.
@Test
public void sendNotificationOnChangeNotFound() 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")));
// Delete the change so that it's not found.
gApi.changes().id(changeId).delete();
// 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("Gerrit Code Review was unable to process your email because the change was not" + " found.");
assertThat(message.headers()).containsKey("Subject");
}
use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.
the class MailProcessorIT method limitCumulativeCommentSize.
@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "7k")
public void limitCumulativeCommentSize() throws Exception {
// Use large sizes because autogenerated messages already have O(100) bytes.
String commentText2000Bytes = new String(new char[2000]).replace("\0", "x");
String changeId = createChangeWithReview();
CommentInput commentInput = new CommentInput();
commentInput.line = 1;
commentInput.message = commentText2000Bytes;
commentInput.path = FILE_NAME;
ReviewInput reviewInput = new ReviewInput().message(commentText2000Bytes);
reviewInput.comments = ImmutableMap.of(FILE_NAME, ImmutableList.of(commentInput));
// Use up ~4000 bytes.
gApi.changes().id(changeId).current().review(reviewInput);
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
String ts = MailProcessingUtil.rfcDateformatter.format(ZonedDateTime.ofInstant(gApi.changes().id(changeId).get().updated.toInstant(), ZoneId.of("UTC")));
// Hit the limit when trying that again.
MailMessage.Builder mailMessage = messageBuilderWithDefaultFields();
String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "change message: " + commentText2000Bytes, "reply to comment: " + commentText2000Bytes, null);
mailMessage.textContent(txt + textFooterForChange(changeInfo._number, ts));
List<CommentInfo> commentsBefore = testCommentHelper.getPublishedComments(changeId);
mailProcessor.process(mailMessage.build());
assertThat(testCommentHelper.getPublishedComments(changeId)).isEqualTo(commentsBefore);
assertNotifyTo(user);
Message message = sender.nextMessage();
assertThat(message.body()).contains("rejected one or more comments");
}
Aggregations