Search in sources :

Example 71 with CommentInfo

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);
}
Also used : Instant(java.time.Instant) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Timestamp(java.sql.Timestamp) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 72 with CommentInfo

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);
}
Also used : Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 73 with CommentInfo

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);
}
Also used : Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 74 with CommentInfo

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);
}
Also used : Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 75 with CommentInfo

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");
}
Also used : MailMessage(com.google.gerrit.mail.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) MailMessage(com.google.gerrit.mail.MailMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test)

Aggregations

CommentInfo (com.google.gerrit.extensions.common.CommentInfo)186 Test (org.junit.Test)178 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)164 Change (com.google.gerrit.entities.Change)120 PatchSet (com.google.gerrit.entities.PatchSet)62 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)56 List (java.util.List)51 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)47 ImmutableList (com.google.common.collect.ImmutableList)46 IdString (com.google.gerrit.extensions.restapi.IdString)34 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)27 ArrayList (java.util.ArrayList)26 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)25 Collectors.toList (java.util.stream.Collectors.toList)25 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)24 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)22 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)21 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)20 CommentInfoSubject.assertThatList (com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList)19 MailMessage (com.google.gerrit.mail.MailMessage)13