Search in sources :

Example 16 with CommentInfo

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

the class CommentsIT method createDraft.

@Test
public void createDraft() throws Exception {
    for (Integer line : lines) {
        PushOneCommit.Result r = createChange();
        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);
        assertThat(result).hasSize(1);
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
    }
}
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) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 17 with CommentInfo

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

the class CommentsIT method listChangeDrafts.

@Test
public void listChangeDrafts() throws Exception {
    PushOneCommit.Result r1 = createChange();
    PushOneCommit.Result r2 = pushFactory.create(db, admin.getIdent(), testRepo, SUBJECT, FILE_NAME, "new content", r1.getChangeId()).to("refs/for/master");
    setApiUser(admin);
    addDraft(r1.getChangeId(), r1.getCommit().getName(), newDraft(FILE_NAME, Side.REVISION, 1, "nit: trailing whitespace"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), newDraft(FILE_NAME, Side.REVISION, 1, "typo: content"));
    setApiUser(user);
    addDraft(r2.getChangeId(), r2.getCommit().getName(), newDraft(FILE_NAME, Side.REVISION, 1, "+1, please fix"));
    setApiUser(admin);
    Map<String, List<CommentInfo>> actual = gApi.changes().id(r1.getChangeId()).drafts();
    assertThat(actual.keySet()).containsExactly(FILE_NAME);
    List<CommentInfo> comments = actual.get(FILE_NAME);
    assertThat(comments).hasSize(2);
    CommentInfo c1 = comments.get(0);
    assertThat(c1.author).isNull();
    assertThat(c1.patchSet).isEqualTo(1);
    assertThat(c1.message).isEqualTo("nit: trailing whitespace");
    assertThat(c1.side).isNull();
    assertThat(c1.line).isEqualTo(1);
    CommentInfo c2 = comments.get(1);
    assertThat(c2.author).isNull();
    assertThat(c2.patchSet).isEqualTo(2);
    assertThat(c2.message).isEqualTo("typo: content");
    assertThat(c2.side).isNull();
    assertThat(c2.line).isEqualTo(1);
}
Also used : 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)

Example 18 with CommentInfo

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

the class CommentsIT method insertCommentsWithHistoricTimestamp.

@Test
public void insertCommentsWithHistoricTimestamp() throws Exception {
    Timestamp timestamp = new Timestamp(0);
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, contents);
        PushOneCommit.Result r = push.to("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        comment.updated = timestamp;
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        ChangeResource changeRsrc = changes.get().parse(TopLevelResource.INSTANCE, IdString.fromDecoded(changeId));
        RevisionResource revRsrc = revisions.parse(changeRsrc, IdString.fromDecoded(revId));
        postReview.get().apply(batchUpdateFactory, revRsrc, input, timestamp);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        CommentInput ci = infoToInput(file).apply(actual);
        ci.updated = comment.updated;
        assertThat(comment).isEqualTo(ci);
        assertThat(actual.updated).isEqualTo(gApi.changes().id(r.getChangeId()).info().created);
        // Updating historic comments doesn't cause lastUpdatedOn to regress.
        assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
    }
}
Also used : RevisionResource(com.google.gerrit.server.change.RevisionResource) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Timestamp(java.sql.Timestamp) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeResource(com.google.gerrit.server.change.ChangeResource) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 19 with CommentInfo

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

the class CommentsIT method deleteOneCommentMultipleTimes.

@Test
public void deleteOneCommentMultipleTimes() throws Exception {
    PushOneCommit.Result result = createChange();
    Change.Id id = result.getChange().getId();
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput c1 = newComment(FILE_NAME, "comment 1");
    CommentInput c2 = newComment(FILE_NAME, "comment 2");
    CommentInput c3 = newComment(FILE_NAME, "comment 3");
    addComments(changeId, ps1, c1);
    addComments(changeId, ps1, c2);
    addComments(changeId, ps1, c3);
    List<CommentInfo> commentsBeforeDelete = getChangeSortedComments(changeId);
    assertThat(commentsBeforeDelete).hasSize(3);
    Optional<CommentInfo> targetComment = commentsBeforeDelete.stream().filter(c -> c.message.equals("comment 2")).findFirst();
    assertThat(targetComment).isPresent();
    String uuid = targetComment.get().id;
    CommentInfo oldComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
    List<RevCommit> commitsBeforeDelete = new ArrayList<>();
    if (notesMigration.commitChangeWrites()) {
        commitsBeforeDelete = getCommits(id);
    }
    setApiUser(admin);
    for (int i = 0; i < 3; i++) {
        DeleteCommentInput input = new DeleteCommentInput("delete comment 2, iteration: " + i);
        gApi.changes().id(changeId).revision(ps1).comment(uuid).delete(input);
    }
    CommentInfo updatedComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
    String expectedMsg = String.format("Comment removed by: %s; Reason: %s", admin.fullName, "delete comment 2, iteration: 2");
    assertThat(updatedComment.message).isEqualTo(expectedMsg);
    oldComment.message = expectedMsg;
    assertThat(updatedComment).isEqualTo(oldComment);
    if (notesMigration.commitChangeWrites()) {
        assertMetaBranchCommitsAfterRewriting(commitsBeforeDelete, id, uuid, expectedMsg);
    }
    assertThat(getChangeSortedComments(changeId)).hasSize(3);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Arrays(java.util.Arrays) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Matcher(java.util.regex.Matcher) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) NoteMap(org.eclipse.jgit.notes.NoteMap) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) Function(com.google.common.base.Function) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) ChangeNoteUtil(com.google.gerrit.server.notedb.ChangeNoteUtil) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) PostReview(com.google.gerrit.server.change.PostReview) Collectors(java.util.stream.Collectors) TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) NoHttpd(com.google.gerrit.acceptance.NoHttpd) List(java.util.List) RefNames(com.google.gerrit.reviewdb.client.RefNames) Ref(org.eclipse.jgit.lib.Ref) Entry(java.util.Map.Entry) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Iterables(com.google.common.collect.Iterables) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) ChangesCollection(com.google.gerrit.server.change.ChangesCollection) Message(com.google.gerrit.testutil.FakeEmailSender.Message) IdString(com.google.gerrit.extensions.restapi.IdString) Patch(com.google.gerrit.reviewdb.client.Patch) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) Comment(com.google.gerrit.extensions.client.Comment) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ChangeResource(com.google.gerrit.server.change.ChangeResource) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Before(org.junit.Before) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeEmailSender(com.google.gerrit.testutil.FakeEmailSender) DeleteCommentRewriter(com.google.gerrit.server.notedb.DeleteCommentRewriter) Provider(com.google.inject.Provider) RevisionResource(com.google.gerrit.server.change.RevisionResource) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Comparator(java.util.Comparator) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) Change(com.google.gerrit.reviewdb.client.Change) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 20 with CommentInfo

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

the class CommentsIT method postCommentWithReply.

@Test
public void postCommentWithReply() throws Exception {
    for (Integer line : lines) {
        String file = "file";
        String contents = "contents " + line;
        PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, "first subject", file, contents);
        PushOneCommit.Result r = push.to("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        input = new ReviewInput();
        comment = newComment(file, Side.REVISION, line, "comment 1 reply", false);
        comment.inReplyTo = actual.id;
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        revision(r).review(input);
        result = getPublishedComments(changeId, revId);
        actual = result.get(comment.path).get(1);
        assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
        assertThat(comment).isEqualTo(infoToInput(file).apply(getPublishedComment(changeId, revId, actual.id)));
    }
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) 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) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) 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