Search in sources :

Example 6 with EditInfo

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

the class ChangeEditIT method retrieveEdit.

@Test
public void retrieveEdit() throws Exception {
    adminRestSession.get(urlEdit(changeId)).assertNoContent();
    createArbitraryEditFor(changeId);
    EditInfo editInfo = getEditInfo(changeId, false);
    ChangeInfo changeInfo = get(changeId);
    assertThat(editInfo.commit.commit).isNotEqualTo(changeInfo.currentRevision);
    assertThat(editInfo).commit().parents().hasSize(1);
    assertThat(editInfo).baseRevision().isEqualTo(changeInfo.currentRevision);
    gApi.changes().id(changeId).edit().delete();
    adminRestSession.get(urlEdit(changeId)).assertNoContent();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) EditInfo(com.google.gerrit.extensions.common.EditInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with EditInfo

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

the class RobotCommentsIT method applyingFixOnTopOfChangeEditReturnsEditInfoForUpdatedChangeEdit.

@Test
public void applyingFixOnTopOfChangeEditReturnsEditInfoForUpdatedChangeEdit() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    gApi.changes().id(changeId).edit().create();
    fixReplacementInfo.path = FILE_NAME;
    fixReplacementInfo.replacement = "Modified content";
    fixReplacementInfo.range = createRange(3, 1, 3, 3);
    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) Iterables(com.google.common.collect.Iterables) Arrays(java.util.Arrays) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.RobotCommentInfoSubject.assertThatList) HashMap(java.util.HashMap) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Comment(com.google.gerrit.extensions.client.Comment) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Map(java.util.Map) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) ImmutableMap(com.google.common.collect.ImmutableMap) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) BinaryResultSubject(com.google.gerrit.extensions.restapi.BinaryResultSubject) Test(org.junit.Test) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) Truth.assertThat(com.google.common.truth.Truth.assertThat) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.EditInfoSubject.assertThat) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) Collections(java.util.Collections) EditInfo(com.google.gerrit.extensions.common.EditInfo) EditInfo(com.google.gerrit.extensions.common.EditInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with EditInfo

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

the class RobotCommentsIT method fixOnPreviousPatchSetWithExistingChangeEditCanBeApplied.

@Test
public void fixOnPreviousPatchSetWithExistingChangeEditCanBeApplied() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    // Create an empty change edit.
    gApi.changes().id(changeId).edit().create();
    fixReplacementInfo.path = FILE_NAME;
    fixReplacementInfo.replacement = "Modified content";
    fixReplacementInfo.range = createRange(3, 1, 3, 3);
    addRobotComment(changeId, withFixRobotCommentInput);
    List<RobotCommentInfo> robotCommentInfos = getRobotComments();
    // Remember patch set and add another one.
    String previousRevision = gApi.changes().id(changeId).get().currentRevision;
    amendChange(changeId);
    List<String> fixIds = getFixIds(robotCommentInfos);
    String fixId = Iterables.getOnlyElement(fixIds);
    EditInfo editInfo = gApi.changes().id(changeId).revision(previousRevision).applyFix(fixId);
    Optional<BinaryResult> file = gApi.changes().id(changeId).edit().getFile(FILE_NAME);
    BinaryResultSubject.assertThat(file).value().asString().isEqualTo("First line\nSecond line\nTModified contentrd line\nFourth line\nFifth line\n" + "Sixth line\nSeventh line\nEighth line\nNinth line\nTenth line\n");
    assertThat(editInfo).baseRevision().isEqualTo(previousRevision);
}
Also used : EditInfo(com.google.gerrit.extensions.common.EditInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with EditInfo

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

the class RobotCommentsIT method createdChangeEditIsBasedOnCurrentPatchSet.

@Test
public void createdChangeEditIsBasedOnCurrentPatchSet() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    String currentRevision = gApi.changes().id(changeId).get().currentRevision;
    fixReplacementInfo.path = FILE_NAME;
    fixReplacementInfo.replacement = "Modified content";
    fixReplacementInfo.range = createRange(3, 1, 3, 3);
    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);
    assertThat(editInfo).baseRevision().isEqualTo(currentRevision);
}
Also used : EditInfo(com.google.gerrit.extensions.common.EditInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 10 with EditInfo

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

the class RobotCommentsIT method applyingFixReturnsEditInfoForCreatedChangeEdit.

@Test
public void applyingFixReturnsEditInfoForCreatedChangeEdit() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    fixReplacementInfo.path = FILE_NAME;
    fixReplacementInfo.replacement = "Modified content";
    fixReplacementInfo.range = createRange(3, 1, 3, 3);
    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) Iterables(com.google.common.collect.Iterables) Arrays(java.util.Arrays) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.RobotCommentInfoSubject.assertThatList) HashMap(java.util.HashMap) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Comment(com.google.gerrit.extensions.client.Comment) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Map(java.util.Map) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Before(org.junit.Before) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) ImmutableMap(com.google.common.collect.ImmutableMap) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) BinaryResultSubject(com.google.gerrit.extensions.restapi.BinaryResultSubject) Test(org.junit.Test) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) Truth.assertThat(com.google.common.truth.Truth.assertThat) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) Objects(java.util.Objects) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.EditInfoSubject.assertThat) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) Collections(java.util.Collections) EditInfo(com.google.gerrit.extensions.common.EditInfo) EditInfo(com.google.gerrit.extensions.common.EditInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

EditInfo (com.google.gerrit.extensions.common.EditInfo)14 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Test (org.junit.Test)13 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 RobotCommentInfo (com.google.gerrit.extensions.common.RobotCommentInfo)4 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)3 BinaryResult (com.google.gerrit.extensions.restapi.BinaryResult)3 Map (java.util.Map)3 ImmutableList (com.google.common.collect.ImmutableList)2 Iterables (com.google.common.collect.Iterables)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 TruthJUnit.assume (com.google.common.truth.TruthJUnit.assume)2 AcceptanceTestRequestScope (com.google.gerrit.acceptance.AcceptanceTestRequestScope)2 GerritConfig (com.google.gerrit.acceptance.GerritConfig)2 SUBJECT (com.google.gerrit.acceptance.PushOneCommit.SUBJECT)2 RestResponse (com.google.gerrit.acceptance.RestResponse)2 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)2