Search in sources :

Example 6 with RobotCommentInfo

use of com.google.gerrit.extensions.common.RobotCommentInfo 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 7 with RobotCommentInfo

use of com.google.gerrit.extensions.common.RobotCommentInfo 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)

Example 8 with RobotCommentInfo

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

the class RobotCommentsIT method getFixPreviewForNonExistingFile.

@Test
public void getFixPreviewForNonExistingFile() throws Exception {
    FixReplacementInfo replacement = new FixReplacementInfo();
    replacement.path = "a_non_existent_file.txt";
    replacement.range = createRange(1, 0, 2, 0);
    replacement.replacement = "Modified content\n";
    FixSuggestionInfo fixSuggestion = createFixSuggestionInfo(replacement);
    RobotCommentInput commentInput = TestCommentHelper.createRobotCommentInput(FILE_NAME2, fixSuggestion);
    testCommentHelper.addRobotComment(changeId, commentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    List<String> fixIds = getFixIds(robotCommentInfos);
    String fixId = Iterables.getOnlyElement(fixIds);
    assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeId).current().getFixPreview(fixId));
}
Also used : FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) 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 9 with RobotCommentInfo

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

the class RobotCommentsIT method canCreateRobotCommentWithHumanCommentAsParent.

@Test
public void canCreateRobotCommentWithHumanCommentAsParent() throws Exception {
    Change.Id changeId = changeOperations.newChange().create();
    String changeIdString = changeOperations.change(changeId).get().changeId();
    String parentCommentUuid = changeOperations.change(changeId).currentPatchset().newComment().create();
    ReviewInput.RobotCommentInput robotCommentInput = TestCommentHelper.createRobotCommentInputWithMandatoryFields(COMMIT_MSG);
    robotCommentInput.message = "comment reply";
    robotCommentInput.inReplyTo = parentCommentUuid;
    testCommentHelper.addRobotComment(changeIdString, robotCommentInput);
    RobotCommentInfo resultComment = Iterables.getOnlyElement(gApi.changes().id(changeIdString).current().robotCommentsAsList().stream().filter(c -> c.message.equals("comment reply")).collect(toImmutableSet()));
    assertThat(resultComment.inReplyTo).isEqualTo(parentCommentUuid);
}
Also used : RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) Change(com.google.gerrit.entities.Change) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with RobotCommentInfo

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

the class RobotCommentsIT method applyingFixOnTopOfChangeEditReturnsEditInfoForUpdatedChangeEdit.

@Test
public void applyingFixOnTopOfChangeEditReturnsEditInfoForUpdatedChangeEdit() throws Exception {
    gApi.changes().id(changeId).edit().create();
    fixReplacementInfo.path = FILE_NAME;
    fixReplacementInfo.replacement = "Modified content";
    fixReplacementInfo.range = createRange(3, 1, 3, 3);
    testCommentHelper.addRobotComment(changeId, withFixRobotCommentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    List<String> fixIds = getFixIds(robotCommentInfos);
    String fixId = Iterables.getOnlyElement(fixIds);
    EditInfo editInfo = gApi.changes().id(changeId).current().applyFix(fixId);
    Optional<EditInfo> expectedEditInfo = gApi.changes().id(changeId).edit().get();
    String expectedEditCommit = expectedEditInfo.map(edit -> edit.commit.commit).orElse("");
    assertThat(editInfo).commit().commit().isEqualTo(expectedEditCommit);
    String expectedBaseRevision = expectedEditInfo.map(edit -> edit.baseRevision).orElse("");
    assertThat(editInfo).baseRevision().isEqualTo(expectedBaseRevision);
}
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) EditInfo(com.google.gerrit.extensions.common.EditInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)34 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)33 Test (org.junit.Test)33 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)18 FixReplacementInfo (com.google.gerrit.extensions.common.FixReplacementInfo)16 FixSuggestionInfo (com.google.gerrit.extensions.common.FixSuggestionInfo)15 Change (com.google.gerrit.entities.Change)9 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)8 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)7 ImmutableList (com.google.common.collect.ImmutableList)6 DiffInfo (com.google.gerrit.extensions.common.DiffInfo)6 RobotCommentInfoSubject.assertThatList (com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList)6 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)6 EditInfo (com.google.gerrit.extensions.common.EditInfo)5 List (java.util.List)5 Collectors.toList (java.util.stream.Collectors.toList)5 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Iterables (com.google.common.collect.Iterables)3 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)3