Search in sources :

Example 96 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class RevertIT method revertSubmissionUnrelatedWithTwoMergeCommits.

@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void revertSubmissionUnrelatedWithTwoMergeCommits() throws Exception {
    String topic = "topic";
    PushOneCommit.Result firstResult = createChange(testRepo, "master", "first change", "a.txt", "message", topic);
    approve(firstResult.getChangeId());
    testRepo.reset("HEAD~1");
    PushOneCommit.Result secondResult = createChange(testRepo, "master", "second change", "b.txt", "message", topic);
    approve(secondResult.getChangeId());
    testRepo.reset("HEAD~1");
    PushOneCommit.Result thirdResult = createChange(testRepo, "master", "third change", "c.txt", "message", topic);
    approve(thirdResult.getChangeId());
    gApi.changes().id(firstResult.getChangeId()).current().submit();
    // put the head on the most recent merge commit.
    testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master:merge")).call();
    testRepo.reset("merge");
    // Create another change that should be ignored. The reverts should be rebased on top of the
    // merge commit.
    PushOneCommit.Result fourthResult = createChange(testRepo, "master", "fourth change", "d.txt", "message", topic);
    approve(fourthResult.getChangeId());
    gApi.changes().id(fourthResult.getChangeId()).current().submit();
    RevertSubmissionInfo revertSubmissionInfo = gApi.changes().id(secondResult.getChangeId()).revertSubmission();
    assertThat(revertSubmissionInfo.revertChanges.stream().map(change -> change.created).distinct().count()).isEqualTo(1);
    List<ChangeApi> revertChanges = getChangeApis(revertSubmissionInfo);
    Collections.reverse(revertChanges);
    assertThat(revertChanges.get(0).current().files().get("c.txt").linesDeleted).isEqualTo(1);
    assertThat(revertChanges.get(1).current().files().get("b.txt").linesDeleted).isEqualTo(1);
    assertThat(revertChanges.get(2).current().files().get("a.txt").linesDeleted).isEqualTo(1);
    String sha1FirstRevert = revertChanges.get(0).current().commit(false).commit;
    String sha1SecondRevert = revertChanges.get(1).current().commit(false).commit;
    // parent of the first revert is the merged change of previous changes.
    assertThat(revertChanges.get(0).current().commit(false).parents.get(0).subject).contains("Merge \"third change\"");
    // Next reverts would stack on top of the previous ones.
    assertThat(revertChanges.get(1).current().commit(false).parents.get(0).commit).isEqualTo(sha1FirstRevert);
    assertThat(revertChanges.get(2).current().commit(false).parents.get(0).commit).isEqualTo(sha1SecondRevert);
    assertThat(revertChanges).hasSize(3);
    assertThat(gApi.changes().id(revertChanges.get(1).id()).current().related().changes).hasSize(3);
}
Also used : RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) RefSpec(org.eclipse.jgit.transport.RefSpec) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 97 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class AbandonIT method notAbandonedIfMergeableWhenMergeableOperatorIsEnabled.

@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
@GerritConfig(name = "changeCleanup.abandonIfMergeable", value = "false")
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "API_REF_UPDATED_AND_CHANGE_REINDEX")
public void notAbandonedIfMergeableWhenMergeableOperatorIsEnabled() throws Exception {
    ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
    // create 2 changes
    int id1 = createChange().getChange().getId().get();
    int id2 = createChange().getChange().getId().get();
    // create 2 changes that conflict with each other
    testRepo.reset(initial);
    int id3 = createChange("change 3", "file.txt", "content").getChange().getId().get();
    testRepo.reset(initial);
    int id4 = createChange("change 4", "file.txt", "other content").getChange().getId().get();
    // make all 4 previously created changes older than 1 week
    TestTimeUtil.incrementClock(7 * 24, HOURS);
    // create 1 new change that will not be abandoned because it is not older than 1 week
    testRepo.reset(initial);
    ChangeData cd = createChange().getChange();
    int id5 = cd.getId().get();
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3, id4, id5);
    assertThat(query("is:abandoned")).isEmpty();
    // submit one of the conflicting changes
    gApi.changes().id(id3).current().review(ReviewInput.approve());
    gApi.changes().id(id3).current().submit();
    assertThat(toChangeNumbers(query("is:merged"))).containsExactly(id3);
    assertThat(toChangeNumbers(query("-is:mergeable"))).containsExactly(id4);
    abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id5, id2, id1);
    assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id4);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeData(com.google.gerrit.server.query.change.ChangeData) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 98 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class AbandonIT method abandonedIfMergeableWhenMergeableOperatorIsDisabled.

/**
 * When indexing mergeable is disabled then the abandonIfMergeable option is ineffective and the
 * auto abandon behaves as though it were set to its default value (true).
 */
@Test
@UseClockStep
@GerritConfig(name = "changeCleanup.abandonAfter", value = "1w")
@GerritConfig(name = "changeCleanup.abandonIfMergeable", value = "false")
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "NEVER")
public void abandonedIfMergeableWhenMergeableOperatorIsDisabled() throws Exception {
    ObjectId initial = repo().exactRef(HEAD).getLeaf().getObjectId();
    // create 2 changes
    int id1 = createChange().getChange().getId().get();
    int id2 = createChange().getChange().getId().get();
    // create 2 changes that conflict with each other
    testRepo.reset(initial);
    int id3 = createChange("change 3", "file.txt", "content").getChange().getId().get();
    testRepo.reset(initial);
    int id4 = createChange("change 4", "file.txt", "other content").getChange().getId().get();
    // make all 4 previously created changes older than 1 week
    TestTimeUtil.incrementClock(7 * 24, HOURS);
    // create 1 new change that will not be abandoned because it is not older than 1 week
    testRepo.reset(initial);
    ChangeData cd = createChange().getChange();
    int id5 = cd.getId().get();
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id1, id2, id3, id4, id5);
    assertThat(query("is:abandoned")).isEmpty();
    // submit one of the conflicting changes
    gApi.changes().id(id3).current().review(ReviewInput.approve());
    gApi.changes().id(id3).current().submit();
    assertThat(toChangeNumbers(query("is:merged"))).containsExactly(id3);
    BadRequestException thrown = assertThrows(BadRequestException.class, () -> query("-is:mergeable"));
    assertThat(thrown).hasMessageThat().contains("operator is not supported");
    abandonUtil.abandonInactiveOpenChanges(batchUpdateFactory);
    assertThat(toChangeNumbers(query("is:open"))).containsExactly(id5);
    assertThat(toChangeNumbers(query("is:abandoned"))).containsExactly(id4, id2, id1);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ChangeData(com.google.gerrit.server.query.change.ChangeData) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 99 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class DisablePrivateChangesIT method createPrivateChangeWithDisablePrivateChangesTrue.

@Test
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
public void createPrivateChangeWithDisablePrivateChangesTrue() throws Exception {
    ChangeInput input = new ChangeInput(project.get(), "master", "empty change");
    input.isPrivate = true;
    MethodNotAllowedException thrown = assertThrows(MethodNotAllowedException.class, () -> gApi.changes().create(input));
    assertThat(thrown).hasMessageThat().contains("private changes are disabled");
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 100 with GerritConfig

use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.

the class DisablePrivateChangesIT method setPrivateWithDisablePrivateChangesTrue.

@Test
@GerritConfig(name = "change.disablePrivateChanges", value = "true")
public void setPrivateWithDisablePrivateChangesTrue() throws Exception {
    PushOneCommit.Result result = createChange();
    MethodNotAllowedException thrown = assertThrows(MethodNotAllowedException.class, () -> gApi.changes().id(result.getChangeId()).setPrivate(true, "set private"));
    assertThat(thrown).hasMessageThat().contains("private changes are disabled");
}
Also used : MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)187 Test (org.junit.Test)185 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)170 RestResponse (com.google.gerrit.acceptance.RestResponse)56 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)40 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)35 Repository (org.eclipse.jgit.lib.Repository)21 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)19 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)17 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)17 ExternalIdNotes (com.google.gerrit.server.account.externalids.ExternalIdNotes)16 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)14 TestRepository (org.eclipse.jgit.junit.TestRepository)14 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)11 TestAccount (com.google.gerrit.acceptance.TestAccount)10 Account (com.google.gerrit.entities.Account)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)10 Project (com.google.gerrit.entities.Project)9 ConfigInfo (com.google.gerrit.extensions.api.projects.ConfigInfo)9 Change (com.google.gerrit.entities.Change)8