Search in sources :

Example 76 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo 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");
}
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) 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)

Example 77 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class MailProcessorIT method parseAndPersistPatchsetLevelComment.

@Test
public void parseAndPersistPatchsetLevelComment() 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")));
    // Build Message
    MailMessage.Builder b = messageBuilderWithDefaultFields();
    String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", "Test Message", null, null);
    b.textContent(txt + textFooterForChange(changeInfo._number, ts));
    mailProcessor.process(b.build());
    Collection<ChangeMessageInfo> messages = gApi.changes().id(changeId).get().messages;
    assertThat(messages).hasSize(3);
    assertThat(Iterables.getLast(messages).message).isEqualTo("Patch Set 1:\n\n(1 comment)");
    assertThat(Iterables.getLast(messages).tag).isEqualTo("mailMessageId=some id");
    // Assert comment
    List<CommentInfo> comments = gApi.changes().id(changeId).current().commentsAsList();
    assertThat(comments).hasSize(3);
    assertThat(comments.get(0).path).isEqualTo(PATCHSET_LEVEL);
    assertThat(comments.get(0).message).isEqualTo("Test Message");
    assertThat(comments.get(0).tag).isEqualTo("mailMessageId=some id");
    assertThat(comments.get(0).parent).isNull();
    assertThat(comments.get(0).side).isNull();
    assertThat(comments.get(0).line).isNull();
    assertThat(comments.get(0).parent).isNull();
    assertThat(comments.get(0).inReplyTo).isNull();
}
Also used : MailMessage(com.google.gerrit.mail.MailMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test)

Example 78 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class MailProcessorIT method validateChangeMessage_rejected.

@Test
public void validateChangeMessage_rejected() 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")));
    setupFailValidation(CommentForValidation.CommentType.CHANGE_MESSAGE, changeInfo.project, changeInfo._number);
    MailMessage.Builder b = messageBuilderWithDefaultFields();
    String txt = newPlaintextBody(getChangeUrl(changeInfo) + "/1", COMMENT_TEXT, null, null);
    b.textContent(txt + textFooterForChange(changeInfo._number, ts));
    List<CommentInfo> commentsBefore = testCommentHelper.getPublishedComments(changeId);
    mailProcessor.process(b.build());
    assertThat(testCommentHelper.getPublishedComments(changeId)).isEqualTo(commentsBefore);
    assertNotifyTo(user);
    Message message = sender.nextMessage();
    assertThat(message.body()).contains("rejected one or more comments");
    // ensure the message header contains a valid message id.
    assertThat(((StringEmailHeader) message.headers().get("Message-ID")).getString()).containsMatch("<someid-REJECTION-HTML@" + new URL(canonicalWebUrl.get()).getHost() + ">");
}
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) StringEmailHeader(com.google.gerrit.entities.EmailHeader.StringEmailHeader) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) URL(java.net.URL) Test(org.junit.Test)

Example 79 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class ChangesRestApiBindingsIT method commentEndpoints.

@Test
public void commentEndpoints() throws Exception {
    String changeId = createChange().getChangeId();
    for (RestCall restCall : COMMENT_ENDPOINTS) {
        DraftInput draftInput = new DraftInput();
        draftInput.path = Patch.COMMIT_MSG;
        draftInput.side = Side.REVISION;
        draftInput.line = 1;
        draftInput.message = "draft comment";
        CommentInfo commentInfo = gApi.changes().id(changeId).current().createDraft(draftInput).get();
        ReviewInput reviewInput = new ReviewInput();
        reviewInput.drafts = DraftHandling.PUBLISH;
        gApi.changes().id(changeId).current().review(reviewInput);
        RestApiCallHelper.execute(adminRestSession, restCall, changeId, "current", commentInfo.id);
    }
}
Also used : RestCall(com.google.gerrit.acceptance.rest.util.RestCall) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 80 with CommentInfo

use of com.google.gerrit.extensions.common.CommentInfo in project gerrit by GerritCodeReview.

the class ChangeMessagesIT method deleteOneChangeMessage.

private void deleteOneChangeMessage(int changeNum, int deletedMessageIndex, TestAccount deletedBy, String reason) throws Exception {
    List<ChangeMessageInfo> messagesBeforeDeletion = gApi.changes().id(changeNum).messages();
    List<CommentInfo> commentsBefore = getChangeSortedComments(changeNum);
    List<RevCommit> commitsBefore = getChangeMetaCommitsInReverseOrder(Change.id(changeNum));
    String id = messagesBeforeDeletion.get(deletedMessageIndex).id;
    DeleteChangeMessageInput input = new DeleteChangeMessageInput(reason);
    ChangeMessageInfo info = gApi.changes().id(changeNum).message(id).delete(input);
    // Verify the return change message info is as expect.
    String expectedMessage = "Change message removed by: " + deletedBy.getNameEmail();
    if (!Strings.isNullOrEmpty(reason)) {
        expectedMessage = expectedMessage + "\nReason: " + reason;
    }
    assertThat(info.message).isEqualTo(expectedMessage);
    List<ChangeMessageInfo> messagesAfterDeletion = gApi.changes().id(changeNum).messages();
    assertMessagesAfterDeletion(messagesBeforeDeletion, messagesAfterDeletion, deletedMessageIndex, expectedMessage);
    assertCommentsAfterDeletion(changeNum, commentsBefore);
    // Verify change index is updated after deletion.
    List<ChangeInfo> changes = gApi.changes().query("message removed").get();
    assertThat(changes.stream().map(c -> c._number).collect(toSet())).contains(changeNum);
    // Verifies states of commits.
    assertMetaCommitsAfterDeletion(commitsBefore, changeNum, id, deletedBy, reason);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) UseTimezone(com.google.gerrit.acceptance.UseTimezone) ChangeNoteUtil.parseCommitMessageRange(com.google.gerrit.server.notedb.ChangeNoteUtil.parseCommitMessageRange) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.entities.Change) RawParseUtils.decode(org.eclipse.jgit.util.RawParseUtils.decode) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Collectors.toSet(java.util.stream.Collectors.toSet) TestProjectUpdate.allowCapability(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) Iterator(java.util.Iterator) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RawParseUtils(org.eclipse.jgit.util.RawParseUtils) ChangeNoteUtil(com.google.gerrit.server.notedb.ChangeNoteUtil) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) UseClockStep(com.google.gerrit.acceptance.UseClockStep) List(java.util.List) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) DETAILED_ACCOUNTS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_ACCOUNTS) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) DeleteChangeMessageInput(com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) DeleteChangeMessageInput(com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

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