use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class PatchsetOperationsImplTest method commentIsCreatedWithSpecifiedCreationTime.
@Test
public void commentIsCreatedWithSpecifiedCreationTime() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
// Don't use nanos. NoteDb supports only second precision.
Instant creationTime = LocalDateTime.of(2020, Month.SEPTEMBER, 15, 12, 10, 43).atZone(ZoneOffset.UTC).toInstant();
String commentUuid = changeOperations.change(changeId).currentPatchset().newComment().createdOn(creationTime).create();
Timestamp creationTimestamp = Timestamp.from(creationTime);
CommentInfo comment = getCommentFromServer(changeId, commentUuid);
assertThat(comment).updated().isEqualTo(creationTimestamp);
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class PatchsetOperationsImplTest method draftCommentCanBeCreatedOnParentCommit.
@Test
public void draftCommentCanBeCreatedOnParentCommit() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
String commentUuid = changeOperations.change(changeId).currentPatchset().newDraftComment().onParentCommit().create();
CommentInfo comment = getDraftCommentFromServer(changeId, commentUuid);
assertThat(comment).side().isEqualTo(Side.PARENT);
assertThat(comment).parent().isEqualTo(1);
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class PatchsetOperationsImplTest method rangeRobotCommentCanBeCreated.
@Test
public void rangeRobotCommentCanBeCreated() throws Exception {
Change.Id changeId = changeOperations.newChange().file("file1").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
String commentUuid = changeOperations.change(changeId).currentPatchset().newRobotComment().fromLine(2).charOffset(4).toLine(3).charOffset(5).ofFile("file1").create();
CommentInfo comment = getRobotCommentFromServerInCurrentPatchset(changeId, commentUuid);
assertThat(comment).range().startLine().isEqualTo(2);
assertThat(comment).range().startCharacter().isEqualTo(4);
assertThat(comment).range().endLine().isEqualTo(3);
assertThat(comment).range().endCharacter().isEqualTo(5);
// Line is automatically filled from specified range. It's the end line.
assertThat(comment).line().isEqualTo(3);
}
use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.
the class PatchsetOperationsImplTest method patchsetLevelCommentCanBeCreated.
@Test
public void patchsetLevelCommentCanBeCreated() throws Exception {
Change.Id changeId = changeOperations.newChange().create();
String commentUuid = changeOperations.change(changeId).currentPatchset().newComment().onPatchsetLevel().create();
CommentInfo comment = getCommentFromServer(changeId, commentUuid);
assertThat(comment).path().isEqualTo(Patch.PATCHSET_LEVEL);
}
use of com.google.gerrit.extensions.common.CommentInfo 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");
}
Aggregations