Search in sources :

Example 6 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class CommentsIT method commentsOnDeletedFileIsIncludedInEmails.

@Test
public void commentsOnDeletedFileIsIncludedInEmails() throws Exception {
    // Create a change with a file.
    createChange("subject", "f1.txt", "content");
    // Stack a second change that deletes the file.
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    gApi.changes().id(changeId).edit().deleteFile("f1.txt");
    gApi.changes().id(changeId).edit().publish();
    String currentRevision = gApi.changes().id(changeId).get().currentRevision;
    // Add a comment on the deleted file on the parent side.
    email.clear();
    CommentInput commentInput = CommentsUtil.newComment("f1.txt", Side.PARENT, /* line= */
    1, /* message= */
    "Comment text", /* unresolved= */
    false);
    CommentsUtil.addComments(gApi, changeId, currentRevision, commentInput);
    // Assert email contains the comment text.
    assertThat(email.getMessages()).hasSize(1);
    Message commentMessage = email.getMessages().get(0);
    assertThat(commentMessage.body()).contains("Patch Set 2:\n\n(1 comment)\n\nFile f1.txt:");
    assertThat(commentMessage.body()).contains("PS2, Line 1: content\nComment text");
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) IdString(com.google.gerrit.extensions.restapi.IdString) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class CommentsIT method patchsetLevelCommentCantHaveSide.

@Test
public void patchsetLevelCommentCantHaveSide() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput input = CommentsUtil.newCommentWithOnlyMandatoryFields(PATCHSET_LEVEL, "comment");
    input.side = Side.REVISION;
    BadRequestException ex = assertThrows(BadRequestException.class, () -> CommentsUtil.addComments(gApi, changeId, ps1, input));
    assertThat(ex.getMessage()).contains("side");
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) IdString(com.google.gerrit.extensions.restapi.IdString) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class CommentsIT method patchsetLevelCommentEmailNotification.

@Test
public void patchsetLevelCommentEmailNotification() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput comment = CommentsUtil.newCommentWithOnlyMandatoryFields(PATCHSET_LEVEL, "The change looks good, LGTM");
    CommentsUtil.addComments(gApi, changeId, ps1, comment);
    String emailBody = Iterables.getOnlyElement(email.getMessages()).body();
    assertThat(emailBody).contains("Patchset");
    assertThat(emailBody).doesNotContain("/PATCHSET_LEVEL");
    assertThat(emailBody).contains("The change looks good, LGTM");
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) IdString(com.google.gerrit.extensions.restapi.IdString) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class CommentsIT method cannotCreateCommentWithInvalidInReplyTo.

@Test
public void cannotCreateCommentWithInvalidInReplyTo() throws Exception {
    Change.Id changeId = changeOperations.newChange().create();
    CommentInput comment = CommentsUtil.newComment(COMMIT_MSG, "comment 1 reply");
    comment.inReplyTo = "invalid";
    BadRequestException exception = assertThrows(BadRequestException.class, () -> CommentsUtil.addComments(gApi, changeId, comment));
    assertThat(exception.getMessage()).contains(String.format("%s not found", comment.inReplyTo));
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Change(com.google.gerrit.entities.Change) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with CommentInput

use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.

the class CommentsIT method canCreateHumanCommentWithHumanCommentAsParent.

@Test
public void canCreateHumanCommentWithHumanCommentAsParent() throws Exception {
    Change.Id changeId = changeOperations.newChange().create();
    String parentCommentUuid = changeOperations.change(changeId).currentPatchset().newComment().create();
    CommentInput createdCommentInput = CommentsUtil.newComment(COMMIT_MSG, "comment reply");
    createdCommentInput.inReplyTo = parentCommentUuid;
    CommentsUtil.addComments(gApi, changeId, createdCommentInput);
    CommentInfo resultNewComment = Iterables.getOnlyElement(getPublishedCommentsAsList(changeId).stream().filter(c -> c.message.equals("comment reply")).collect(toImmutableSet()));
    assertThat(resultNewComment.inReplyTo).isEqualTo(parentCommentUuid);
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) Change(com.google.gerrit.entities.Change) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)63 Test (org.junit.Test)48 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)46 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)40 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)32 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)27 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)26 IdString (com.google.gerrit.extensions.restapi.IdString)21 ImmutableList (com.google.common.collect.ImmutableList)14 List (java.util.List)14 Collectors.toList (java.util.stream.Collectors.toList)14 ArrayList (java.util.ArrayList)12 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)11 Change (com.google.gerrit.entities.Change)9 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)8 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)6 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)6 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 Comment (com.google.gerrit.extensions.client.Comment)4