Search in sources :

Example 11 with RobotCommentInfo

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

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

the class RobotCommentsIT method patchsetLevelRobotCommentCanBeAddedAndRetrieved.

@Test
public void patchsetLevelRobotCommentCanBeAddedAndRetrieved() throws Exception {
    RobotCommentInput input = TestCommentHelper.createRobotCommentInput(PATCHSET_LEVEL);
    testCommentHelper.addRobotComment(changeId, input);
    List<RobotCommentInfo> results = getRobotComments();
    assertThatList(results).onlyElement().path().isEqualTo(PATCHSET_LEVEL);
}
Also used : 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 13 with RobotCommentInfo

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

the class RobotCommentsIT method getFixPreviewForCommitMsg.

@Test
public void getFixPreviewForCommitMsg() throws Exception {
    String footer = "Change-Id: " + changeId;
    updateCommitMessage(changeId, "Commit title\n\nCommit message line 1\nLine 2\nLine 3\nLast line\n\n" + footer + "\n");
    FixReplacementInfo commitMsgReplacement = new FixReplacementInfo();
    commitMsgReplacement.path = Patch.COMMIT_MSG;
    // The test assumes that the first 5 lines is a header.
    // Line 10 has content "Line 2"
    commitMsgReplacement.range = createRange(10, 0, 11, 0);
    commitMsgReplacement.replacement = "New content\n";
    FixSuggestionInfo commitMsgSuggestionInfo = createFixSuggestionInfo(commitMsgReplacement);
    RobotCommentInput commitMsgRobotCommentInput = TestCommentHelper.createRobotCommentInput(Patch.COMMIT_MSG, commitMsgSuggestionInfo);
    testCommentHelper.addRobotComment(changeId, commitMsgRobotCommentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    List<String> fixIds = getFixIds(robotCommentInfos);
    String fixId = Iterables.getOnlyElement(fixIds);
    Map<String, DiffInfo> fixPreview = gApi.changes().id(changeId).current().getFixPreview(fixId);
    assertThat(fixPreview).hasSize(1);
    assertThat(fixPreview).containsKey(Patch.COMMIT_MSG);
    DiffInfo diff = fixPreview.get(Patch.COMMIT_MSG);
    assertThat(diff).metaA().name().isEqualTo(Patch.COMMIT_MSG);
    assertThat(diff).metaA().contentType().isEqualTo(GERRIT_COMMIT_MESSAGE_TYPE);
    assertThat(diff).metaB().name().isEqualTo(Patch.COMMIT_MSG);
    assertThat(diff).metaB().contentType().isEqualTo(GERRIT_COMMIT_MESSAGE_TYPE);
    assertThat(diff).content().element(0).commonLines().hasSize(9);
    // Header has a dynamic content, do not check it
    assertThat(diff).content().element(0).commonLines().element(6).isEqualTo("Commit title");
    assertThat(diff).content().element(0).commonLines().element(7).isEqualTo("");
    assertThat(diff).content().element(0).commonLines().element(8).isEqualTo("Commit message line 1");
    assertThat(diff).content().element(1).linesOfA().containsExactly("Line 2");
    assertThat(diff).content().element(1).linesOfB().containsExactly("New content");
    assertThat(diff).content().element(2).commonLines().containsExactly("Line 3", "Last line", "", footer, "");
}
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) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with RobotCommentInfo

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

the class RobotCommentsIT method fixOnCurrentPatchSetWithChangeEditOnPreviousPatchSetCannotBeApplied.

@Test
public void fixOnCurrentPatchSetWithChangeEditOnPreviousPatchSetCannotBeApplied() throws Exception {
    // Create an empty change edit.
    gApi.changes().id(changeId).edit().create();
    // Add another patch set.
    amendChange(changeId);
    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);
    ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.changes().id(changeId).current().applyFix(fixId));
    assertThat(thrown).hasMessageThat().contains("based");
}
Also used : ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with RobotCommentInfo

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

the class PatchsetOperationsImplTest method robotCommentIsCreatedWithRobotId.

@Test
public void robotCommentIsCreatedWithRobotId() throws Exception {
    Change.Id changeId = changeOperations.newChange().create();
    String commentUuid = changeOperations.change(changeId).currentPatchset().newRobotComment().robotId("robot-id").create();
    RobotCommentInfo comment = getRobotCommentFromServerInCurrentPatchset(changeId, commentUuid);
    assertThat(comment).robotId().isEqualTo("robot-id");
}
Also used : Change(com.google.gerrit.entities.Change) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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