Search in sources :

Example 11 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method submitRequirement_evaluatedWithInternalUserCredentials.

@Test
public void submitRequirement_evaluatedWithInternalUserCredentials() throws Exception {
    GroupInput in = new GroupInput();
    in.name = "invisible-group";
    in.visibleToAll = false;
    in.ownerId = adminGroupUuid().get();
    gApi.groups().create(in);
    configSubmitRequirement(project, SubmitRequirement.builder().setName("My-Requirement").setApplicabilityExpression(SubmitRequirementExpression.of("ownerin:invisible-group")).setSubmittabilityExpression(SubmitRequirementExpression.create("is:true")).setAllowOverrideInChildProjects(false).build());
    requestScopeOperations.setApiUser(user.id());
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ChangeInfo change = gApi.changes().id(changeId).get();
    SubmitRequirementResultInfo srResult = change.submitRequirements.stream().filter(sr -> sr.name.equals("My-Requirement")).collect(MoreCollectors.onlyElement());
    assertThat(srResult.status).isEqualTo(Status.NOT_APPLICABLE);
}
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) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method submitRequirements_eliminatesDuplicatesForLegacyMatchingSRs.

@Test
public void submitRequirements_eliminatesDuplicatesForLegacyMatchingSRs() throws Exception {
    // If a custom/prolog submit rule emits the same label name multiple times, we merge these into
    // a single submit requirement result: in this test, we have two different submit rules that
    // return the same label name, but both are fulfilled (i.e. they both allow submission). The
    // submit requirements API returns one SR result with status=SATISFIED.
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    SubmitRule r1 = createSubmitRule("r1", SubmitRecord.Status.OK, "CR", SubmitRecord.Label.Status.OK);
    SubmitRule r2 = createSubmitRule("r2", SubmitRecord.Status.OK, "CR", SubmitRecord.Label.Status.MAY);
    try (Registration registration = extensionRegistry.newRegistration().add(r1).add(r2)) {
        ChangeInfo change = gApi.changes().id(changeId).get();
        Collection<SubmitRequirementResultInfo> submitRequirements = change.submitRequirements;
        assertThat(submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        true);
        assertSubmitRequirementStatus(submitRequirements, "CR", Status.SATISFIED, /* isLegacy= */
        true);
    }
}
Also used : SubmitRule(com.google.gerrit.server.rules.SubmitRule) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method submitRequirement_applicabilityExpressionIsAlwaysHidden.

@Test
public void submitRequirement_applicabilityExpressionIsAlwaysHidden() throws Exception {
    configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setApplicabilityExpression(SubmitRequirementExpression.of("branch:refs/heads/master")).setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    voteLabel(changeId, "Code-Review", 2);
    ChangeInfo changeInfo = gApi.changes().id(changeId).get();
    SubmitRequirementResultInfo requirement = changeInfo.submitRequirements.stream().collect(MoreCollectors.onlyElement());
    assertSubmitRequirementExpression(requirement.applicabilityExpressionResult, /* expression= */
    null, /* passingAtoms= */
    null, /* failingAtoms= */
    null, /* fulfilled= */
    true);
    assertThat(requirement.submittabilityExpressionResult).isNotNull();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 14 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method checkSubmitRequirement_error.

@Test
public void checkSubmitRequirement_error() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    SubmitRequirementInput in = createSubmitRequirementInput("Code-Review", /* submittabilityExpression= */
    "!!!");
    SubmitRequirementResultInfo result = gApi.changes().id(changeId).checkSubmitRequirement(in);
    assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.ERROR);
}
Also used : SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) SubmitRequirementInput(com.google.gerrit.extensions.common.SubmitRequirementInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 15 with SubmitRequirementResultInfo

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

the class SubmitRequirementIT method checkSubmitRequirement_overridden.

@Test
public void checkSubmitRequirement_overridden() throws Exception {
    // label function has no effect
    configLabel("Override-Label", LabelFunction.NO_OP);
    projectOperations.project(project).forUpdate().add(allowLabel("Override-Label").ref("refs/heads/master").group(REGISTERED_USERS).range(-1, 1)).update();
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    SubmitRequirementInput in = createSubmitRequirementInput("Code-Review", /* applicableIf= */
    null, /* submittableIf= */
    "label:Code-Review=+2", /* overrideIf= */
    "label:Override-Label=+1");
    SubmitRequirementResultInfo result = gApi.changes().id(changeId).checkSubmitRequirement(in);
    assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.UNSATISFIED);
    voteLabel(changeId, "Code-Review", 2);
    result = gApi.changes().id(changeId).checkSubmitRequirement(in);
    assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.SATISFIED);
    voteLabel(changeId, "Override-Label", 1);
    result = gApi.changes().id(changeId).checkSubmitRequirement(in);
    assertThat(result.status).isEqualTo(SubmitRequirementResultInfo.Status.OVERRIDDEN);
}
Also used : SubmitRequirementResultInfo(com.google.gerrit.extensions.common.SubmitRequirementResultInfo) SubmitRequirementInput(com.google.gerrit.extensions.common.SubmitRequirementInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

SubmitRequirementResultInfo (com.google.gerrit.extensions.common.SubmitRequirementResultInfo)17 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)16 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 Test (org.junit.Test)16 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)12 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)8 SubmitRequirementInput (com.google.gerrit.extensions.common.SubmitRequirementInput)7 SubmitRule (com.google.gerrit.server.rules.SubmitRule)7 LabelType (com.google.gerrit.entities.LabelType)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 Iterables (com.google.common.collect.Iterables)3 MoreCollectors (com.google.common.collect.MoreCollectors)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)3 ExtensionRegistry (com.google.gerrit.acceptance.ExtensionRegistry)3 NoHttpd (com.google.gerrit.acceptance.NoHttpd)3 UseTimezone (com.google.gerrit.acceptance.UseTimezone)3 VerifyNoPiiInChangeNotes (com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes)3