Search in sources :

Example 1 with Patch

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

the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedUpInLatestPatchSet.

@Test
public void rebaseHunkIsIdentifiedWhenMovedUpInLatestPatchSet() throws Exception {
    String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
    ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
    rebaseChangeOn(changeId, commit2);
    // Move the code up by removing lines (pure deletion + shrinking replacement) in the latest
    // patch set.
    Function<String, String> contentModification = fileContent -> fileContent.replace("Line 1\n", "").replace("Line 10\nLine 11\n", "Line ten\n");
    addModifiedPatchSet(changeId, FILE_NAME, contentModification);
    DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
    assertThat(diffInfo).content().element(0).linesOfA().containsExactly("Line 1");
    assertThat(diffInfo).content().element(0).linesOfB().isNull();
    assertThat(diffInfo).content().element(0).isNotDueToRebase();
    assertThat(diffInfo).content().element(1).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(2).linesOfA().containsExactly("Line 10", "Line 11");
    assertThat(diffInfo).content().element(2).linesOfB().containsExactly("Line ten");
    assertThat(diffInfo).content().element(2).isNotDueToRebase();
    assertThat(diffInfo).content().element(3).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(4).linesOfA().containsExactly("Line 40");
    assertThat(diffInfo).content().element(4).linesOfB().containsExactly("Line forty");
    assertThat(diffInfo).content().element(4).isDueToRebase();
    assertThat(diffInfo).content().element(5).commonLines().isNotEmpty();
    Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(initialPatchSetId);
    assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
    assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(3);
}
Also used : Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Collectors.toMap(java.util.stream.Collectors.toMap) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Locale(java.util.Locale) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) FileInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.FileInfoSubject.assertThat) ImmutableMap(com.google.common.collect.ImmutableMap) BufferedImage(java.awt.image.BufferedImage) Collectors(java.util.stream.Collectors) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Collectors.joining(java.util.stream.Collectors.joining) Result(com.google.gerrit.acceptance.PushOneCommit.Result) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) DiffOperations(com.google.gerrit.server.patch.DiffOperations) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Joiner(com.google.common.base.Joiner) IntStream(java.util.stream.IntStream) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RawInputUtil(com.google.gerrit.common.RawInputUtil) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) EditWebLink(com.google.gerrit.extensions.webui.EditWebLink) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) GitUtil(com.google.gerrit.acceptance.GitUtil) FileApi(com.google.gerrit.extensions.api.changes.FileApi) FileInfo(com.google.gerrit.extensions.common.FileInfo) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Permission(com.google.gerrit.entities.Permission) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeType(com.google.gerrit.extensions.common.ChangeType) DiffOptions(com.google.gerrit.server.patch.DiffOptions) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) Ignore(org.junit.Ignore) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) DateTimeFormatter(java.time.format.DateTimeFormatter) FileInfo(com.google.gerrit.extensions.common.FileInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with Patch

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

the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedUpInPreviousPatchSet.

@Test
public void rebaseHunkIsIdentifiedWhenMovedUpInPreviousPatchSet() throws Exception {
    // Move the code up by removing lines (pure deletion + shrinking replacement) in the previous
    // patch set.
    Function<String, String> contentModification1 = fileContent -> fileContent.replace("Line 1\n", "").replace("Line 10\nLine 11\n", "Line ten\n");
    addModifiedPatchSet(changeId, FILE_NAME, contentModification1);
    String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
    String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
    ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
    rebaseChangeOn(changeId, commit2);
    Function<String, String> contentModification2 = fileContent -> fileContent.replace("Line 100\n", "Line one hundred\n");
    addModifiedPatchSet(changeId, FILE_NAME, contentModification2);
    DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(previousPatchSetId).get();
    assertThat(diffInfo).content().element(0).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(1).linesOfA().containsExactly("Line 40");
    assertThat(diffInfo).content().element(1).linesOfB().containsExactly("Line forty");
    assertThat(diffInfo).content().element(1).isDueToRebase();
    assertThat(diffInfo).content().element(2).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(3).linesOfA().containsExactly("Line 100");
    assertThat(diffInfo).content().element(3).linesOfB().containsExactly("Line one hundred");
    assertThat(diffInfo).content().element(3).isNotDueToRebase();
    Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(previousPatchSetId);
    assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
    assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
Also used : Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Collectors.toMap(java.util.stream.Collectors.toMap) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Locale(java.util.Locale) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) FileInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.FileInfoSubject.assertThat) ImmutableMap(com.google.common.collect.ImmutableMap) BufferedImage(java.awt.image.BufferedImage) Collectors(java.util.stream.Collectors) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Collectors.joining(java.util.stream.Collectors.joining) Result(com.google.gerrit.acceptance.PushOneCommit.Result) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) DiffOperations(com.google.gerrit.server.patch.DiffOperations) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Joiner(com.google.common.base.Joiner) IntStream(java.util.stream.IntStream) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RawInputUtil(com.google.gerrit.common.RawInputUtil) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) EditWebLink(com.google.gerrit.extensions.webui.EditWebLink) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) GitUtil(com.google.gerrit.acceptance.GitUtil) FileApi(com.google.gerrit.extensions.api.changes.FileApi) FileInfo(com.google.gerrit.extensions.common.FileInfo) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Permission(com.google.gerrit.entities.Permission) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeType(com.google.gerrit.extensions.common.ChangeType) DiffOptions(com.google.gerrit.server.patch.DiffOptions) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) Ignore(org.junit.Ignore) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) DateTimeFormatter(java.time.format.DateTimeFormatter) FileInfo(com.google.gerrit.extensions.common.FileInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with Patch

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

the class RobotCommentsIT method addedRobotCommentsAreLinkedToChangeMessages.

@UseClockStep
@Test
public void addedRobotCommentsAreLinkedToChangeMessages() throws Exception {
    // Advancing the time after creating the change so that the first robot comment is not in the
    // same timestamp as with the change creation.
    TestTimeUtil.incrementClock(10, TimeUnit.SECONDS);
    RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
    RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
    RobotCommentInput c3 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
    // Give the robot comments identifiable names for testing
    c1.message = "robot comment 1";
    c2.message = "robot comment 2";
    c3.message = "robot comment 3";
    testCommentHelper.addRobotComment(changeId, c1, "robot message 1");
    TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
    testCommentHelper.addRobotComment(changeId, c2, "robot message 2");
    TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
    testCommentHelper.addRobotComment(changeId, c3, "robot message 3");
    TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
    Map<String, List<RobotCommentInfo>> robotComments = gApi.changes().id(changeId).robotComments();
    List<RobotCommentInfo> robotCommentsList = robotComments.values().stream().flatMap(List::stream).collect(toList());
    List<ChangeMessageInfo> allMessages = gApi.changes().id(changeId).get(MESSAGES).messages.stream().collect(toList());
    assertThat(allMessages.stream().map(cm -> cm.message).collect(toList())).containsExactly("Uploaded patch set 1.", "Patch Set 1:\n\n(1 comment)\n\nrobot message 1", "Patch Set 1:\n\n(1 comment)\n\nrobot message 2", "Patch Set 1:\n\n(1 comment)\n\nrobot message 3");
    assertThat(robotCommentsList.stream().map(c -> c.message).collect(toList())).containsExactly("robot comment 1", "robot comment 2", "robot comment 3");
    String message1ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 1")).collect(onlyElement()).id;
    String message2ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 2")).collect(onlyElement()).id;
    String message3ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 3")).collect(onlyElement()).id;
    String comment1MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 1")).collect(onlyElement()).changeMessageId;
    String comment2MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 2")).collect(onlyElement()).changeMessageId;
    String comment3MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 3")).collect(onlyElement()).changeMessageId;
    /**
     * All change messages have the auto-generated tag. Robot comments can be linked to
     * auto-generated messages where each comment is linked to the next nearest change message in
     * timestamp
     */
    assertThat(message1ChangeId).isEqualTo(comment1MessageId);
    assertThat(message2ChangeId).isEqualTo(comment2MessageId);
    assertThat(message3ChangeId).isEqualTo(comment3MessageId);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Map(java.util.Map) Side(com.google.gerrit.extensions.client.Side) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) ImmutableMap(com.google.common.collect.ImmutableMap) IntraLineStatus(com.google.gerrit.extensions.common.DiffInfo.IntraLineStatus) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Objects(java.util.Objects) UseClockStep(com.google.gerrit.acceptance.UseClockStep) List(java.util.List) BinaryResultSubject(com.google.gerrit.extensions.restapi.testing.BinaryResultSubject) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) EditInfo(com.google.gerrit.extensions.common.EditInfo) Iterables(com.google.common.collect.Iterables) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) Comment(com.google.gerrit.extensions.client.Comment) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) TestCommentHelper(com.google.gerrit.testing.TestCommentHelper) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) TestTimeUtil(com.google.gerrit.testing.TestTimeUtil) Before(org.junit.Before) FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) TimeUnit(java.util.concurrent.TimeUnit) ChangeType(com.google.gerrit.extensions.common.ChangeType) Collectors.toList(java.util.stream.Collectors.toList) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Collections(java.util.Collections) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.EditInfoSubject.assertThat) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 4 with Patch

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

the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedDownInPreviousPatchSet.

@Test
public void rebaseHunkIsIdentifiedWhenMovedDownInPreviousPatchSet() throws Exception {
    // Move the code down by introducing additional lines (pure insert + enlarging replacement) in
    // the previous patch set.
    Function<String, String> contentModification1 = fileContent -> "Line zero\n" + fileContent.replace("Line 10\n", "Line ten\nLine ten and a half\n");
    addModifiedPatchSet(changeId, FILE_NAME, contentModification1);
    String previousPatchSetId = gApi.changes().id(changeId).get().currentRevision;
    String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
    ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
    rebaseChangeOn(changeId, commit2);
    Function<String, String> contentModification2 = fileContent -> fileContent.replace("Line 100\n", "Line one hundred\n");
    addModifiedPatchSet(changeId, FILE_NAME, contentModification2);
    DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(previousPatchSetId).get();
    assertThat(diffInfo).content().element(0).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(1).linesOfA().containsExactly("Line 40");
    assertThat(diffInfo).content().element(1).linesOfB().containsExactly("Line forty");
    assertThat(diffInfo).content().element(1).isDueToRebase();
    assertThat(diffInfo).content().element(2).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(3).linesOfA().containsExactly("Line 100");
    assertThat(diffInfo).content().element(3).linesOfB().containsExactly("Line one hundred");
    assertThat(diffInfo).content().element(3).isNotDueToRebase();
    Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(previousPatchSetId);
    assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(1);
    assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
Also used : Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Collectors.toMap(java.util.stream.Collectors.toMap) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Locale(java.util.Locale) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) FileInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.FileInfoSubject.assertThat) ImmutableMap(com.google.common.collect.ImmutableMap) BufferedImage(java.awt.image.BufferedImage) Collectors(java.util.stream.Collectors) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Collectors.joining(java.util.stream.Collectors.joining) Result(com.google.gerrit.acceptance.PushOneCommit.Result) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) DiffOperations(com.google.gerrit.server.patch.DiffOperations) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Joiner(com.google.common.base.Joiner) IntStream(java.util.stream.IntStream) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RawInputUtil(com.google.gerrit.common.RawInputUtil) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) EditWebLink(com.google.gerrit.extensions.webui.EditWebLink) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) GitUtil(com.google.gerrit.acceptance.GitUtil) FileApi(com.google.gerrit.extensions.api.changes.FileApi) FileInfo(com.google.gerrit.extensions.common.FileInfo) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Permission(com.google.gerrit.entities.Permission) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeType(com.google.gerrit.extensions.common.ChangeType) DiffOptions(com.google.gerrit.server.patch.DiffOptions) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) Ignore(org.junit.Ignore) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) DateTimeFormatter(java.time.format.DateTimeFormatter) FileInfo(com.google.gerrit.extensions.common.FileInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with Patch

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

the class RevisionDiffIT method rebaseHunkIsIdentifiedWhenMovedDownInLatestPatchSet.

@Test
public void rebaseHunkIsIdentifiedWhenMovedDownInLatestPatchSet() throws Exception {
    String newFileContent = FILE_CONTENT.replace("Line 40\n", "Line forty\n");
    ObjectId commit2 = addCommit(commit1, FILE_NAME, newFileContent);
    rebaseChangeOn(changeId, commit2);
    // Move the code down by introducing additional lines (pure insert + enlarging replacement) in
    // the latest patch set.
    Function<String, String> contentModification = fileContent -> "Line zero\n" + fileContent.replace("Line 10\n", "Line ten\nLine ten and a half\n");
    addModifiedPatchSet(changeId, FILE_NAME, contentModification);
    DiffInfo diffInfo = getDiffRequest(changeId, CURRENT, FILE_NAME).withBase(initialPatchSetId).get();
    assertThat(diffInfo).content().element(0).linesOfA().isNull();
    assertThat(diffInfo).content().element(0).linesOfB().containsExactly("Line zero");
    assertThat(diffInfo).content().element(0).isNotDueToRebase();
    assertThat(diffInfo).content().element(1).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(2).linesOfA().containsExactly("Line 10");
    assertThat(diffInfo).content().element(2).linesOfB().containsExactly("Line ten", "Line ten and a half");
    assertThat(diffInfo).content().element(2).isNotDueToRebase();
    assertThat(diffInfo).content().element(3).commonLines().isNotEmpty();
    assertThat(diffInfo).content().element(4).linesOfA().containsExactly("Line 40");
    assertThat(diffInfo).content().element(4).linesOfB().containsExactly("Line forty");
    assertThat(diffInfo).content().element(4).isDueToRebase();
    assertThat(diffInfo).content().element(5).commonLines().isNotEmpty();
    Map<String, FileInfo> changedFiles = gApi.changes().id(changeId).current().files(initialPatchSetId);
    assertThat(changedFiles.get(FILE_NAME)).linesInserted().isEqualTo(3);
    assertThat(changedFiles.get(FILE_NAME)).linesDeleted().isEqualTo(1);
}
Also used : Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Collectors.toMap(java.util.stream.Collectors.toMap) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Locale(java.util.Locale) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) FileInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.FileInfoSubject.assertThat) ImmutableMap(com.google.common.collect.ImmutableMap) BufferedImage(java.awt.image.BufferedImage) Collectors(java.util.stream.Collectors) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Collectors.joining(java.util.stream.Collectors.joining) Result(com.google.gerrit.acceptance.PushOneCommit.Result) PersonIdent(org.eclipse.jgit.lib.PersonIdent) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) DiffOperations(com.google.gerrit.server.patch.DiffOperations) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Joiner(com.google.common.base.Joiner) IntStream(java.util.stream.IntStream) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RawInputUtil(com.google.gerrit.common.RawInputUtil) MERGE_LIST(com.google.gerrit.entities.Patch.MERGE_LIST) Function(java.util.function.Function) ArrayList(java.util.ArrayList) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) EditWebLink(com.google.gerrit.extensions.webui.EditWebLink) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) FileDiffOutput(com.google.gerrit.server.patch.filediff.FileDiffOutput) GitUtil(com.google.gerrit.acceptance.GitUtil) FileApi(com.google.gerrit.extensions.api.changes.FileApi) FileInfo(com.google.gerrit.extensions.common.FileInfo) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) DiffPreferencesInfo(com.google.gerrit.extensions.client.DiffPreferencesInfo) ObjectIds.abbreviateName(com.google.gerrit.git.ObjectIds.abbreviateName) Permission(com.google.gerrit.entities.Permission) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeType(com.google.gerrit.extensions.common.ChangeType) DiffOptions(com.google.gerrit.server.patch.DiffOptions) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) Ignore(org.junit.Ignore) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) DateTimeFormatter(java.time.format.DateTimeFormatter) FileInfo(com.google.gerrit.extensions.common.FileInfo) ObjectId(org.eclipse.jgit.lib.ObjectId) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Patch (com.google.gerrit.entities.Patch)8 Inject (com.google.inject.Inject)8 List (java.util.List)8 Map (java.util.Map)8 ImmutableList (com.google.common.collect.ImmutableList)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)7 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)7 Arrays (java.util.Arrays)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 Truth.assertThat (com.google.common.truth.Truth.assertThat)6 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)6 RawInputUtil (com.google.gerrit.common.RawInputUtil)6 COMMIT_MSG (com.google.gerrit.entities.Patch.COMMIT_MSG)6 PATCHSET_LEVEL (com.google.gerrit.entities.Patch.PATCHSET_LEVEL)6 DiffPreferencesInfo (com.google.gerrit.extensions.client.DiffPreferencesInfo)6 ChangeType (com.google.gerrit.extensions.common.ChangeType)6 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)6 DiffInfoSubject.assertThat (com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat)6 Joiner (com.google.common.base.Joiner)5