Search in sources :

Example 1 with FixReplacementInfo

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

the class RobotCommentsIT method fixSuggestionCannotPointToPatchsetLevel.

@Test
public void fixSuggestionCannotPointToPatchsetLevel() throws Exception {
    RobotCommentInput input = TestCommentHelper.createRobotCommentInput(FILE_NAME);
    FixReplacementInfo brokenFixReplacement = createFixReplacementInfo();
    brokenFixReplacement.path = PATCHSET_LEVEL;
    input.fixSuggestions = ImmutableList.of(createFixSuggestionInfo(brokenFixReplacement));
    BadRequestException ex = assertThrows(BadRequestException.class, () -> testCommentHelper.addRobotComment(changeId, input));
    assertThat(ex.getMessage()).contains("file path must not be " + PATCHSET_LEVEL);
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with FixReplacementInfo

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

the class RobotCommentsIT method rangesOfFixReplacementsOfDifferentFixSuggestionsForSameFileMayOverlap.

@Test
public void rangesOfFixReplacementsOfDifferentFixSuggestionsForSameFileMayOverlap() throws Exception {
    FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
    fixReplacementInfo1.path = FILE_NAME;
    fixReplacementInfo1.range = createRange(2, 0, 3, 1);
    fixReplacementInfo1.replacement = "First modification\n";
    FixSuggestionInfo fixSuggestionInfo1 = createFixSuggestionInfo(fixReplacementInfo1);
    FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
    fixReplacementInfo2.path = FILE_NAME;
    fixReplacementInfo2.range = createRange(3, 0, 4, 0);
    fixReplacementInfo2.replacement = "Second modification\n";
    FixSuggestionInfo fixSuggestionInfo2 = createFixSuggestionInfo(fixReplacementInfo2);
    withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo1, fixSuggestionInfo2);
    testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    assertThatList(robotCommentInfos).onlyElement().fixSuggestions().hasSize(2);
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with FixReplacementInfo

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

the class RobotCommentsIT method fixReplacementsDoNotNeedToBeOrderedAccordingToRange.

@Test
public void fixReplacementsDoNotNeedToBeOrderedAccordingToRange() throws Exception {
    FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
    fixReplacementInfo1.path = FILE_NAME;
    fixReplacementInfo1.range = createRange(2, 0, 3, 0);
    fixReplacementInfo1.replacement = "First modification\n";
    FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
    fixReplacementInfo2.path = FILE_NAME;
    fixReplacementInfo2.range = createRange(3, 0, 4, 0);
    fixReplacementInfo2.replacement = "Second modification\n";
    FixReplacementInfo fixReplacementInfo3 = new FixReplacementInfo();
    fixReplacementInfo3.path = FILE_NAME;
    fixReplacementInfo3.range = createRange(4, 0, 5, 0);
    fixReplacementInfo3.replacement = "Third modification\n";
    FixSuggestionInfo fixSuggestionInfo = createFixSuggestionInfo(fixReplacementInfo2, fixReplacementInfo1, fixReplacementInfo3);
    withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo);
    testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    assertThatList(robotCommentInfos).onlyElement().onlyFixSuggestion().replacements().hasSize(3);
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with FixReplacementInfo

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

the class RobotCommentsIT method twoConflictingFixesOnSameFileCannotBeApplied.

@Test
public void twoConflictingFixesOnSameFileCannotBeApplied() throws Exception {
    FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
    fixReplacementInfo1.path = FILE_NAME;
    fixReplacementInfo1.range = createRange(2, 0, 3, 1);
    fixReplacementInfo1.replacement = "First modification\n";
    FixSuggestionInfo fixSuggestionInfo1 = createFixSuggestionInfo(fixReplacementInfo1);
    FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
    fixReplacementInfo2.path = FILE_NAME;
    fixReplacementInfo2.range = createRange(3, 0, 4, 0);
    fixReplacementInfo2.replacement = "Some other modified content\n";
    FixSuggestionInfo fixSuggestionInfo2 = createFixSuggestionInfo(fixReplacementInfo2);
    RobotCommentInput robotCommentInput1 = TestCommentHelper.createRobotCommentInput(FILE_NAME, fixSuggestionInfo1);
    RobotCommentInput robotCommentInput2 = TestCommentHelper.createRobotCommentInput(FILE_NAME, fixSuggestionInfo2);
    testCommentHelper.addRobotComment(changeId, robotCommentInput1);
    testCommentHelper.addRobotComment(changeId, robotCommentInput2);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    List<String> fixIds = getFixIds(robotCommentInfos);
    gApi.changes().id(changeId).current().applyFix(fixIds.get(0));
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).current().applyFix(fixIds.get(1)));
    assertThat(thrown).hasMessageThat().contains("merge");
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with FixReplacementInfo

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

the class RobotCommentsIT method fixInvolvingTwoFilesCanBeApplied.

@Test
public void fixInvolvingTwoFilesCanBeApplied() throws Exception {
    FixReplacementInfo fixReplacementInfo1 = new FixReplacementInfo();
    fixReplacementInfo1.path = FILE_NAME;
    fixReplacementInfo1.range = createRange(2, 0, 3, 0);
    fixReplacementInfo1.replacement = "First modification\n";
    FixReplacementInfo fixReplacementInfo2 = new FixReplacementInfo();
    fixReplacementInfo2.path = FILE_NAME2;
    fixReplacementInfo2.range = createRange(1, 0, 2, 0);
    fixReplacementInfo2.replacement = "Different file modification\n";
    FixSuggestionInfo fixSuggestionInfo = createFixSuggestionInfo(fixReplacementInfo1, fixReplacementInfo2);
    withFixRobotCommentInput.fixSuggestions = ImmutableList.of(fixSuggestionInfo);
    testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    List<String> fixIds = getFixIds(robotCommentInfos);
    String fixId = Iterables.getOnlyElement(fixIds);
    gApi.changes().id(changeId).current().applyFix(fixId);
    Optional<BinaryResult> file = gApi.changes().id(changeId).edit().getFile(FILE_NAME);
    BinaryResultSubject.assertThat(file).value().asString().isEqualTo("First line\nFirst modification\nThird line\nFourth line\nFifth line\nSixth line\n" + "Seventh line\nEighth line\nNinth line\nTenth line\n");
    Optional<BinaryResult> file2 = gApi.changes().id(changeId).edit().getFile(FILE_NAME2);
    BinaryResultSubject.assertThat(file2).value().asString().isEqualTo("Different file modification\n2nd line\n3rd line\n");
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

FixReplacementInfo (com.google.gerrit.extensions.common.FixReplacementInfo)22 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 FixSuggestionInfo (com.google.gerrit.extensions.common.FixSuggestionInfo)19 Test (org.junit.Test)19 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)13 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)11 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)3 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)3 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)3 AutoValue (com.google.auto.value.AutoValue)2 Strings (com.google.common.base.Strings)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Ordering (com.google.common.collect.Ordering)2 HashCode (com.google.common.hash.HashCode)2 Hashing (com.google.common.hash.Hashing)2 Nullable (com.google.gerrit.common.Nullable)2 NotifyHandling (com.google.gerrit.extensions.api.changes.NotifyHandling)2