Search in sources :

Example 6 with CommentInfo

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

the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnAllRevisions.

@Test
public void publishCommentsOnPushPublishesDraftsOnAllRevisions() throws Exception {
    PushOneCommit.Result r = createChange();
    String rev1 = r.getCommit().name();
    CommentInfo c1 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment1"));
    CommentInfo c2 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment2"));
    r = amendChange(r.getChangeId());
    String rev2 = r.getCommit().name();
    CommentInfo c3 = addDraft(r.getChangeId(), rev2, newDraft(FILE_NAME, 1, "comment3"));
    assertThat(getPublishedComments(r.getChangeId())).isEmpty();
    gApi.changes().id(r.getChangeId()).addReviewer(user.email);
    sender.clear();
    amendChange(r.getChangeId(), "refs/for/master%publish-comments");
    Collection<CommentInfo> comments = getPublishedComments(r.getChangeId());
    assertThat(comments.stream().map(c -> c.id)).containsExactly(c1.id, c2.id, c3.id);
    assertThat(comments.stream().map(c -> c.message)).containsExactly("comment1", "comment2", "comment3");
    assertThat(getLastMessage(r.getChangeId())).isEqualTo("Uploaded patch set 3.\n\n(3 comments)");
    List<String> messages = sender.getMessages().stream().map(m -> m.body()).sorted(Comparator.comparingInt(m -> m.contains("reexamine") ? 0 : 1)).collect(toList());
    assertThat(messages).hasSize(2);
    assertThat(messages.get(0)).contains("Gerrit-MessageType: newpatchset");
    assertThat(messages.get(0)).contains("I'd like you to reexamine a change");
    assertThat(messages.get(0)).doesNotContain("Uploaded patch set 3");
    assertThat(messages.get(1)).contains("Gerrit-MessageType: comment");
    assertThat(messages.get(1)).containsMatch(Pattern.compile(// then, this test documents the current behavior.
    "Uploaded patch set 3\\.\n" + "\n" + "\\(3 comments\\)\\n.*" + "PS1, Line 1:.*" + "comment1\\n.*" + "PS1, Line 1:.*" + "comment2\\n.*" + "PS2, Line 1:.*" + "comment3\\n", Pattern.DOTALL));
}
Also used : CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with CommentInfo

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

the class ImpersonationIT method voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf.

@Test
public void voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf() throws Exception {
    allowRunAs();
    PushOneCommit.Result r = createChange();
    setApiUser(user);
    DraftInput di = new DraftInput();
    di.path = Patch.COMMIT_MSG;
    di.side = Side.REVISION;
    di.line = 1;
    di.message = "inline comment";
    gApi.changes().id(r.getChangeId()).current().createDraft(di);
    setApiUser(admin);
    // Things that aren't allowed with on_behalf_of:
    //  - no labels.
    //  - publish other user's drafts.
    ReviewInput in = new ReviewInput();
    in.message = "message";
    in.drafts = DraftHandling.PUBLISH;
    RestResponse res = adminRestSession.postWithHeader("/changes/" + r.getChangeId() + "/revisions/current/review", in, runAsHeader(user.id));
    res.assertOK();
    ChangeMessageInfo m = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
    assertThat(m.message).endsWith(in.message);
    assertThat(m.author._accountId).isEqualTo(user.id.get());
    CommentInfo c = Iterables.getOnlyElement(gApi.changes().id(r.getChangeId()).comments().get(di.path));
    assertThat(c.author._accountId).isEqualTo(user.id.get());
    assertThat(c.message).isEqualTo(di.message);
    setApiUser(user);
    assertThat(gApi.changes().id(r.getChangeId()).drafts()).isEmpty();
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) 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 8 with CommentInfo

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

the class CommentsIT method commentTags.

@Test
public void commentTags() throws Exception {
    PushOneCommit.Result r = createChange();
    CommentInput pub = new CommentInput();
    pub.line = 1;
    pub.message = "published comment";
    pub.path = FILE_NAME;
    ReviewInput rin = newInput(pub);
    rin.tag = "tag1";
    gApi.changes().id(r.getChangeId()).current().review(rin);
    List<CommentInfo> comments = gApi.changes().id(r.getChangeId()).current().commentsAsList();
    assertThat(comments).hasSize(1);
    assertThat(comments.get(0).tag).isEqualTo("tag1");
    DraftInput draft = new DraftInput();
    draft.line = 2;
    draft.message = "draft comment";
    draft.path = FILE_NAME;
    draft.tag = "tag2";
    addDraft(r.getChangeId(), r.getCommit().name(), draft);
    List<CommentInfo> drafts = gApi.changes().id(r.getChangeId()).current().draftsAsList();
    assertThat(drafts).hasSize(1);
    assertThat(drafts.get(0).tag).isEqualTo("tag2");
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) 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 9 with CommentInfo

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

the class CommentsIT method putDraft.

@Test
public void putDraft() throws Exception {
    for (Integer line : lines) {
        PushOneCommit.Result r = createChange();
        Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        String path = "file1";
        DraftInput comment = newDraft(path, Side.REVISION, line, "comment 1");
        addDraft(changeId, revId, comment);
        Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
        String uuid = actual.id;
        comment.message = "updated comment 1";
        updateDraft(changeId, revId, comment, uuid);
        result = getDraftComments(changeId, revId);
        actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
        // Posting a draft comment doesn't cause lastUpdatedOn to change.
        assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
    }
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with CommentInfo

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

the class CommentsIT method listDrafts.

@Test
public void listDrafts() throws Exception {
    String file = "file";
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    String revId = r.getCommit().getName();
    assertThat(getDraftComments(changeId, revId)).isEmpty();
    List<DraftInput> expectedDrafts = new ArrayList<>();
    for (Integer line : lines) {
        DraftInput comment = newDraft(file, Side.REVISION, line, "comment " + line);
        expectedDrafts.add(comment);
        addDraft(changeId, revId, comment);
    }
    Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
    assertThat(result).isNotEmpty();
    List<CommentInfo> actualComments = result.get(file);
    assertThat(Lists.transform(actualComments, infoToDraft(file))).containsExactlyElementsIn(expectedDrafts);
}
Also used : ArrayList(java.util.ArrayList) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

CommentInfo (com.google.gerrit.extensions.common.CommentInfo)33 Test (org.junit.Test)31 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)24 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)23 List (java.util.List)18 ImmutableList (com.google.common.collect.ImmutableList)17 ArrayList (java.util.ArrayList)17 IdString (com.google.gerrit.extensions.restapi.IdString)16 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)12 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)10 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)10 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 Change (com.google.gerrit.reviewdb.client.Change)6 MailMessage (com.google.gerrit.server.mail.receive.MailMessage)6 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)5 Timestamp (java.sql.Timestamp)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 ChangeResource (com.google.gerrit.server.change.ChangeResource)3