Search in sources :

Example 66 with ChangeMessageInfo

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

the class MailProcessorIT method parseAndPersistInlineComment.

@Test
public void parseAndPersistInlineComment() 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", null, "Some Inline Comment", null);
    b.textContent(txt + textFooterForChange(changeInfo._number, ts));
    mailProcessor.process(b.build());
    // Assert messages
    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(2).message).isEqualTo("Some Inline Comment");
    assertThat(comments.get(2).tag).isEqualTo("mailMessageId=some id");
    assertThat(comments.get(2).inReplyTo).isEqualTo(comments.get(1).id);
}
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 67 with ChangeMessageInfo

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

the class AbandonRestoreIT method assertChangeMessages.

private void assertChangeMessages(String changeId, List<String> expected) throws Exception {
    ChangeInfo c = get(changeId, MESSAGES);
    Iterable<ChangeMessageInfo> messages = c.messages;
    assertThat(messages).isNotNull();
    assertThat(messages).hasSize(expected.size());
    List<String> actual = new ArrayList<>();
    for (ChangeMessageInfo info : messages) {
        actual.add(info.message);
    }
    assertThat(actual).containsExactlyElementsIn(expected);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ArrayList(java.util.ArrayList) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo)

Example 68 with ChangeMessageInfo

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

the class ImpersonationIT method changeMessageCreatedOnBehalfOfHasRealUser.

@Test
public void changeMessageCreatedOnBehalfOfHasRealUser() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id().toString();
    in.message = "Message on behalf of";
    in.label("Code-Review", 1);
    requestScopeOperations.setApiUser(accountCreator.user2().id());
    gApi.changes().id(r.getChangeId()).revision(r.getPatchSetId().getId()).review(in);
    ChangeInfo info = gApi.changes().id(r.getChangeId()).get(MESSAGES);
    assertThat(info.messages).hasSize(2);
    ChangeMessageInfo changeMessageInfo = Iterables.getLast(info.messages);
    assertThat(changeMessageInfo.realAuthor).isNotNull();
    assertThat(changeMessageInfo.realAuthor._accountId).isEqualTo(accountCreator.user2().id().get());
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 69 with ChangeMessageInfo

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

the class DeleteVoteIT method deleteVote.

private void deleteVote(boolean onRevisionLevel) throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    PushOneCommit.Result r2 = amendChange(r.getChangeId());
    requestScopeOperations.setApiUser(user.id());
    recommend(r.getChangeId());
    sender.clear();
    String endPoint = "/changes/" + r.getChangeId() + (onRevisionLevel ? ("/revisions/" + r2.getCommit().getName()) : "") + "/reviewers/" + user.id().toString() + "/votes/Code-Review";
    RestResponse response = adminRestSession.delete(endPoint);
    response.assertNoContent();
    List<FakeEmailSender.Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    FakeEmailSender.Message msg = messages.get(0);
    assertThat(msg.rcpt()).containsExactly(user.getNameEmail());
    assertThat(msg.body()).contains(admin.fullName() + " has removed a vote from this change.");
    assertThat(msg.body()).contains("Removed Code-Review+1 by " + user.fullName() + " <" + user.email() + ">\n");
    endPoint = "/changes/" + r.getChangeId() + (onRevisionLevel ? ("/revisions/" + r2.getCommit().getName()) : "") + "/reviewers/" + user.id().toString() + "/votes";
    response = adminRestSession.get(endPoint);
    response.assertOK();
    Map<String, Short> m = newGson().fromJson(response.getReader(), new TypeToken<Map<String, Short>>() {
    }.getType());
    assertThat(m).containsExactly(LabelId.CODE_REVIEW, Short.valueOf((short) 0));
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    ChangeMessageInfo message = Iterables.getLast(c.messages);
    assertThat(message.author._accountId).isEqualTo(admin.id().get());
    assertThat(message.message).isEqualTo(String.format("Removed Code-Review+1 by %s\n", AccountTemplateUtil.getAccountTemplate(user.id())));
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactlyElementsIn(ImmutableSet.of(admin.id(), user.id()));
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) TypeToken(com.google.gson.reflect.TypeToken)

Example 70 with ChangeMessageInfo

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

the class HashtagsIT method addAlreadyExistingHashtag.

@Test
public void addAlreadyExistingHashtag() throws Exception {
    // Adding a hashtag that already exists on the change returns a sorted list
    // of hashtags without duplicates.
    PushOneCommit.Result r = createChange();
    addHashtags(r, "tag2");
    assertThatGet(r).containsExactly("tag2");
    assertMessage(r, "Hashtag added: tag2");
    ChangeMessageInfo last = getLastMessage(r);
    addHashtags(r, "tag2");
    assertThatGet(r).containsExactly("tag2");
    assertNoNewMessageSince(r, last);
    addHashtags(r, "tag1", "tag2");
    assertThatGet(r).containsExactly("tag1", "tag2").inOrder();
    assertMessage(r, "Hashtag added: tag1");
}
Also used : ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)75 Test (org.junit.Test)61 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)47 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)47 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)37 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)10 RevisionInfo (com.google.gerrit.extensions.common.RevisionInfo)10 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)8 ArrayList (java.util.ArrayList)8 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)6 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 BranchInput (com.google.gerrit.extensions.api.projects.BranchInput)5 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)5 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)5 Message (com.google.gerrit.testing.FakeEmailSender.Message)5 List (java.util.List)5 Change (com.google.gerrit.entities.Change)4