Search in sources :

Example 26 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedCommentHasUpdatedTimestamp.

@Test
public void portedCommentHasUpdatedTimestamp() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).updated().isNotNull();
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 27 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedCommentHasOriginalTag.

@Test
public void portedCommentHasOriginalTag() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().create();
    TestPatchset patchset1 = changeOps.change(changeId).currentPatchset().get();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().create();
    // Add comment.
    String commentUuid = newComment(patchset1.patchsetId()).tag("My comment tag").create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).tag().isEqualTo("My comment tag");
}
Also used : TestPatchset(com.google.gerrit.acceptance.testsuite.change.TestPatchset) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 28 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method commentsArePortedWhenAllEditsAreDueToRebase.

@Test
public void commentsArePortedWhenAllEditsAreDueToRebase() throws Exception {
    String fileName = "f.txt";
    String baseContent = IntStream.rangeClosed(1, 50).mapToObj(number -> String.format("Line %d\n", number)).collect(joining());
    ObjectId headCommit = testRepo.getRepository().resolve("HEAD");
    ObjectId baseCommit = addCommit(headCommit, fileName, baseContent);
    // Create a change on top of baseCommit, modify line 1, then add comment on line 10.
    PushOneCommit.Result r = createEmptyChange();
    Change.Id changeId = r.getChange().getId();
    addModifiedPatchSet(changeId.toString(), fileName, baseContent.replace("Line 1\n", "Line one\n"));
    PatchSet.Id ps2Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    newComment(ps2Id).message("Line comment").onLine(10).ofFile(fileName).create();
    // Add a commit on top of baseCommit. Delete line 4. Rebase the change on top of this commit.
    ObjectId newBase = addCommit(baseCommit, fileName, baseContent.replace("Line 4\n", ""));
    rebaseChangeOn(changeId.toString(), newBase);
    PatchSet.Id ps3Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    List<CommentInfo> portedComments = flatten(getPortedComments(ps3Id));
    assertThat(portedComments).hasSize(1);
    int portedLine = portedComments.get(0).line;
    BinaryResult fileContent = gApi.changes().id(changeId.get()).current().file(fileName).content();
    List<String> lines = Splitter.on("\n").splitToList(fileContent.asString());
    // Comment has shifted to L9 instead of L10 because of the deletion of line 4.
    assertThat(portedLine).isEqualTo(9);
    assertThat(lines.get(portedLine - 1)).isEqualTo("Line 10");
}
Also used : IntStream(java.util.stream.IntStream) Patch(com.google.gerrit.entities.Patch) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Inject(com.google.inject.Inject) RawInputUtil(com.google.gerrit.common.RawInputUtil) LocalDateTime(java.time.LocalDateTime) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) AccountOperations(com.google.gerrit.acceptance.testsuite.account.AccountOperations) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Side(com.google.gerrit.extensions.client.Side) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ZoneOffset(java.time.ZoneOffset) Splitter(com.google.common.base.Splitter) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) ImmutableMap(com.google.common.collect.ImmutableMap) CommentInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThat) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) Account(com.google.gerrit.entities.Account) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) CommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.CommentInfoSubject.assertThatList) Collectors.joining(java.util.stream.Collectors.joining) Correspondence(com.google.common.truth.Correspondence) ObjectId(org.eclipse.jgit.lib.ObjectId) Result(com.google.gerrit.acceptance.PushOneCommit.Result) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) Ignore(org.junit.Ignore) TestCommentCreation(com.google.gerrit.acceptance.testsuite.change.TestCommentCreation) TestPatchset(com.google.gerrit.acceptance.testsuite.change.TestPatchset) MapSubject.assertThatMap(com.google.gerrit.truth.MapSubject.assertThatMap) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) NullAwareCorrespondence(com.google.gerrit.truth.NullAwareCorrespondence) Result(com.google.gerrit.acceptance.PushOneCommit.Result) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 29 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedRangeCommentCanHandleDeletedLines.

@Test
public void portedRangeCommentCanHandleDeletedLines() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().file("myFile").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().file("myFile").content("Line 2\nLine 3\nLine 4\n").create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).fromLine(3).charOffset(2).toLine(4).charOffset(5).ofFile("myFile").create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).range().startLine().isEqualTo(2);
    assertThat(portedComment).range().startCharacter().isEqualTo(2);
    assertThat(portedComment).range().endLine().isEqualTo(3);
    assertThat(portedComment).range().endCharacter().isEqualTo(5);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 30 with Change

use of com.google.gerrit.entities.Change in project gerrit by GerritCodeReview.

the class PortedCommentsIT method portedLineCommentOnLineJustAfterModificationCanBePorted.

@Test
public void portedLineCommentOnLineJustAfterModificationCanBePorted() throws Exception {
    // Set up change and patchsets.
    Change.Id changeId = changeOps.newChange().file("myFile").content("Line 1\nLine 2\nLine 3\nLine 4\n").create();
    PatchSet.Id patchset1Id = changeOps.change(changeId).currentPatchset().get().patchsetId();
    PatchSet.Id patchset2Id = changeOps.change(changeId).newPatchset().file("myFile").content("Line 1\nLine 2\nLine three\nLine 4\n").create();
    // Add comment.
    String commentUuid = newComment(patchset1Id).onLine(4).ofFile("myFile").create();
    CommentInfo portedComment = getPortedComment(patchset2Id, commentUuid);
    assertThat(portedComment).line().isEqualTo(4);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

Change (com.google.gerrit.entities.Change)659 Test (org.junit.Test)510 PatchSet (com.google.gerrit.entities.PatchSet)167 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)165 ObjectId (org.eclipse.jgit.lib.ObjectId)113 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)112 RevCommit (org.eclipse.jgit.revwalk.RevCommit)88 Account (com.google.gerrit.entities.Account)83 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)72 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)66 List (java.util.List)64 ImmutableList (com.google.common.collect.ImmutableList)63 ChangeData (com.google.gerrit.server.query.change.ChangeData)60 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)58 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)56 Instant (java.time.Instant)54 Project (com.google.gerrit.entities.Project)52 StorageException (com.google.gerrit.exceptions.StorageException)50 Ref (org.eclipse.jgit.lib.Ref)49 HumanComment (com.google.gerrit.entities.HumanComment)46