use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method attentionSetNotUpdatedWhenNoCommentsPublished.
@Test
public void attentionSetNotUpdatedWhenNoCommentsPublished() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
gApi.changes().id(changeId).addReviewer(user.email());
gApi.changes().id(changeId).attention(user.email()).remove(new AttentionSetInput("removed"));
ImmutableSet<AttentionSetUpdate> attentionSet = result.getChange().attentionSet();
Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
assertThat(attentionSet).isEqualTo(amendResult.getChange().attentionSet());
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method publishCommentsAddsAllUsersInCommentThread.
@Test
public void publishCommentsAddsAllUsersInCommentThread() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
String revId = result.getCommit().getName();
requestScopeOperations.setApiUser(user.id());
DraftInput comment = testCommentHelper.newDraft(COMMENT_TEXT);
testCommentHelper.addDraft(changeId, revId, comment);
ReviewInput reviewInput = new ReviewInput().blockAutomaticAttentionSetRules();
reviewInput.drafts = ReviewInput.DraftHandling.PUBLISH;
change(result).current().review(reviewInput);
requestScopeOperations.setApiUser(admin.id());
comment = testCommentHelper.newDraft(COMMENT_TEXT, Iterables.getOnlyElement(gApi.changes().id(changeId).current().commentsAsList()).id);
testCommentHelper.addDraft(changeId, revId, comment);
Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
AttentionSetUpdate attentionSetUpdate = Iterables.getOnlyElement(amendResult.getChange().attentionSet());
assertThat(attentionSetUpdate.account()).isEqualTo(user.id());
assertThat(attentionSetUpdate.reason()).isEqualTo("Someone else replied on a comment you posted");
assertThat(attentionSetUpdate.operation()).isEqualTo(AttentionSetUpdate.Operation.ADD);
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method emailsSentOnPublishCommentsHaveDifferentMessageIds.
@Test
public void emailsSentOnPublishCommentsHaveDifferentMessageIds() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
gApi.changes().id(changeId).addReviewer(user.email());
sender.clear();
String revId = result.getCommit().getName();
DraftInput comment = testCommentHelper.newDraft(COMMENT_TEXT);
testCommentHelper.addDraft(changeId, revId, comment);
amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
List<FakeEmailSender.Message> messages = sender.getMessages();
assertThat(messages).hasSize(2);
FakeEmailSender.Message newPatchsetMessage = messages.get(0);
assertThat(newPatchsetMessage.body()).contains("new patch set");
assertThat(newPatchsetMessage.headers().get("Message-ID").toString()).doesNotContain("EmailReviewComments");
FakeEmailSender.Message newCommentsMessage = messages.get(1);
assertThat(newCommentsMessage.body()).contains("has posted comments on this change");
assertThat(newCommentsMessage.headers().get("Message-ID").toString()).contains("EmailReviewComments");
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method limitCumulativeCommentSize.
@Test
@GerritConfig(name = "change.cumulativeCommentSizeLimit", value = "500")
public void limitCumulativeCommentSize() throws Exception {
when(mockCommentValidator.validateComments(any(), any())).thenReturn(ImmutableList.of());
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
String revId = result.getCommit().getName();
String filePath = result.getChange().currentFilePaths().get(0);
String commentText400Bytes = new String(new char[400]).replace("\0", "x");
DraftInput draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, commentText400Bytes);
testCommentHelper.addDraft(changeId, revId, draftInline);
amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).hasSize(1);
draftInline = testCommentHelper.newDraft(filePath, Side.REVISION, 1, commentText400Bytes);
testCommentHelper.addDraft(changeId, revId, draftInline);
Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).hasSize(1);
amendResult.assertMessage("exceeding maximum cumulative size of comments");
}
use of com.google.gerrit.acceptance.PushOneCommit.Result in project gerrit by GerritCodeReview.
the class ReceiveCommitsCommentValidationIT method validateComments_commentRejected.
@Test
public void validateComments_commentRejected() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
String revId = result.getCommit().getName();
when(mockCommentValidator.validateComments(CommentValidationContext.create(result.getChange().getId().get(), result.getChange().project().get(), result.getChange().change().getDest().branch()), ImmutableList.of(COMMENT_FOR_VALIDATION))).thenReturn(ImmutableList.of(COMMENT_FOR_VALIDATION.failValidation("Oh no!")));
DraftInput comment = testCommentHelper.newDraft(COMMENT_TEXT);
testCommentHelper.addDraft(changeId, revId, comment);
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).isEmpty();
Result amendResult = amendChange(changeId, "refs/for/master%publish-comments", admin, testRepo);
amendResult.assertOkStatus();
amendResult.assertMessage("Comment validation failure:");
assertThat(testCommentHelper.getPublishedComments(result.getChangeId())).isEmpty();
}
Aggregations