Search in sources :

Example 1 with TestProjectUpdate.allowLabel

use of com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method submitRequirement_partiallyOverriddenSRIsIgnored.

@Test
public void submitRequirement_partiallyOverriddenSRIsIgnored() throws Exception {
    // Create build-cop-override label
    LabelDefinitionInput input = new LabelDefinitionInput();
    input.function = "NoOp";
    input.values = ImmutableMap.of("+1", "Override", " 0", "No Override");
    gApi.projects().name(project.get()).label("build-cop-override").create(input).get();
    // Allow to vote on the build-cop-override label.
    projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("build-cop-override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
    // Define submit requirement in root project.
    configSubmitRequirement(allProjects, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label:Code-Review=+1")).setOverrideExpression(SubmitRequirementExpression.of("label:build-cop-override=+1")).setAllowOverrideInChildProjects(true).build());
    // Create Code-Review-Override label
    gApi.projects().name(project.get()).label("Code-Review-Override").create(input).get();
    // Allow to vote on the Code-Review-Override label.
    projectOperations.project(project).forUpdate().add(TestProjectUpdate.allowLabel("Code-Review-Override").range(0, 1).ref("refs/*").group(REGISTERED_USERS).build()).update();
    // Override submit requirement in project (requires Code-Review-Override+1 as override instead
    // of build-cop-override+1), but do not set all required properties (submittability expression
    // is missing). We update the project.config file directly in the remote repository, since
    // trying to push such a submit requirement would be rejected by the commit validation.
    projectOperations.project(project).forInvalidation().addProjectConfigUpdater(config -> config.setString(ProjectConfig.SUBMIT_REQUIREMENT, "Code-Review", ProjectConfig.KEY_SR_OVERRIDE_EXPRESSION, "label:Code-Review-Override=+1")).invalidate();
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ChangeInfo change = gApi.changes().id(changeId).get();
    assertThat(change.submitRequirements).hasSize(1);
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
    false);
    voteLabel(changeId, "Code-Review-Override", 1);
    change = gApi.changes().id(changeId).get();
    assertThat(change.submitRequirements).hasSize(1);
    // The override expression in the project is satisfied, but it's ignored since the SR is
    // incomplete.
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
    false);
    voteLabel(changeId, "build-cop-override", 1);
    change = gApi.changes().id(changeId).get();
    assertThat(change.submitRequirements).hasSize(2);
    // The submit requirement is overridden now (the override expression in the child project is
    // ignored)
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.OVERRIDDEN, /* isLegacy= */
    false);
    // Legacy requirement is coming from the label MaxWithBlock function. Still unsatisfied.
    assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
    true);
}
Also used : Status(com.google.gerrit.extensions.common.SubmitRequirementResultInfo.Status) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) RevObject(org.eclipse.jgit.revwalk.RevObject) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) LabelType(com.google.gerrit.entities.LabelType) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) TestProjectUpdate(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) MoreCollectors(com.google.common.collect.MoreCollectors) SubmitType(com.google.gerrit.extensions.client.SubmitType) Collection(java.util.Collection) VerifyNoPiiInChangeNotes(com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) RawParseUtils(org.eclipse.jgit.util.RawParseUtils) TestLabels.label(com.google.gerrit.server.project.testing.TestLabels.label) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) SubmitRecord(com.google.gerrit.entities.SubmitRecord) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) Ref(org.eclipse.jgit.lib.Ref) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) IndexPreloadingUtil(com.google.gerrit.httpd.raw.IndexPreloadingUtil) IntStream(java.util.stream.IntStream) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) TestLabels(com.google.gerrit.server.project.testing.TestLabels) UseTimezone(com.google.gerrit.acceptance.UseTimezone) ImmutableList(com.google.common.collect.ImmutableList) LabelFunction(com.google.gerrit.entities.LabelFunction) SubmitRequirementInput(com.google.gerrit.extensions.common.SubmitRequirementInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRecordInfo(com.google.gerrit.extensions.common.SubmitRecordInfo) ActionInfo(com.google.gerrit.extensions.common.ActionInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) TestRepository(org.eclipse.jgit.junit.TestRepository) SubmitRule(com.google.gerrit.server.rules.SubmitRule) Permission(com.google.gerrit.entities.Permission) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) LegacySubmitRequirementInfo(com.google.gerrit.extensions.common.LegacySubmitRequirementInfo) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Project(com.google.gerrit.entities.Project) Repository(org.eclipse.jgit.lib.Repository) SubmitRequirementExpressionInfo(com.google.gerrit.extensions.common.SubmitRequirementExpressionInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) LabelDefinitionInput(com.google.gerrit.extensions.common.LabelDefinitionInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 MoreCollectors (com.google.common.collect.MoreCollectors)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 ExtensionRegistry (com.google.gerrit.acceptance.ExtensionRegistry)1 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)1 NoHttpd (com.google.gerrit.acceptance.NoHttpd)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 UseTimezone (com.google.gerrit.acceptance.UseTimezone)1 VerifyNoPiiInChangeNotes (com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes)1 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)1 TestProjectUpdate (com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate)1 TestProjectUpdate.allow (com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow)1 TestProjectUpdate.allowLabel (com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel)1 RequestScopeOperations (com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations)1 Nullable (com.google.gerrit.common.Nullable)1