Search in sources :

Example 26 with SubmitRequirement

use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.

the class SubmitRequirementIT method testLegacySubmitRequirementDuplicatesGlobalStatusDoesNotMatch.

private void testLegacySubmitRequirementDuplicatesGlobalStatusDoesNotMatch(boolean allowOverrideInChildProject) throws Exception {
    SubmitRequirement globalSubmitRequirement = SubmitRequirement.builder().setName("CoDe-reView").setSubmittabilityExpression(SubmitRequirementExpression.create("topic:test")).setAllowOverrideInChildProjects(allowOverrideInChildProject).build();
    try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
        PushOneCommit.Result r = createChange();
        String changeId = r.getChangeId();
        // Both are evaluated, but only the global is returned, since both are unsatisfied
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.UNSATISFIED, /* isLegacy= */
        false);
        // Both are evaluated and both are returned, since result mismatch
        voteLabel(changeId, "Code-Review", 2);
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        true);
        assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.UNSATISFIED, /* isLegacy= */
        false);
        gApi.changes().id(changeId).topic("test");
        gApi.changes().id(changeId).reviewer(admin.id().toString()).deleteVote(LabelId.CODE_REVIEW);
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(2);
        assertThat(change.submitRequirements).hasSize(2);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        true);
        assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.SATISFIED, /* isLegacy= */
        false);
    }
}
Also used : LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 27 with SubmitRequirement

use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method submittabilityAndOverrideNotEvaluated_whenApplicabilityIsFalse.

@Test
public void submittabilityAndOverrideNotEvaluated_whenApplicabilityIsFalse() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:non-existent-project", /* submittabilityExpr= */
    "message:\"Fix bug\"", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.NOT_APPLICABLE);
    assertThat(result.applicabilityExpressionResult().get().status()).isEqualTo(Status.FAIL);
    assertThat(result.submittabilityExpressionResult().isPresent()).isFalse();
    assertThat(result.overrideExpressionResult().isPresent()).isFalse();
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 28 with SubmitRequirement

use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method submitRequirementIsError_whenSubmittabilityExpressionHasInvalidSyntax.

@Test
public void submitRequirementIsError_whenSubmittabilityExpressionHasInvalidSyntax() throws Exception {
    addLabel("build-cop-override");
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:" + project.get(), /* submittabilityExpr= */
    "invalid_field:invalid_value", /* overrideExpr= */
    "label:\"build-cop-override=+1\"");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.ERROR);
    assertThat(result.submittabilityExpressionResult().get().errorMessage().get()).isEqualTo("Unsupported operator invalid_field:invalid_value");
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 29 with SubmitRequirement

use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method submitRequirement_alwaysNotApplicable.

@Test
public void submitRequirement_alwaysNotApplicable() {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "is:false", // redundant
    "is:false", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.NOT_APPLICABLE);
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 30 with SubmitRequirement

use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method globalSubmitRequirementEvaluated.

@Test
public void globalSubmitRequirementEvaluated() throws Exception {
    SubmitRequirement globalSubmitRequirement = createSubmitRequirement(/*name=*/
    "global-config-requirement", /* applicabilityExpr= */
    "project:" + project.get(), /*submittabilityExpr= */
    "is:true", /* overrideExpr= */
    "", /*allowOverrideInChildProjects*/
    false);
    try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
        SubmitRequirement projectSubmitRequirement = createSubmitRequirement(/*name=*/
        "project-config-requirement", /* applicabilityExpr= */
        "project:" + project.get(), /*submittabilityExpr= */
        "is:true", /* overrideExpr= */
        "", /*allowOverrideInChildProjects*/
        false);
        configSubmitRequirement(project, projectSubmitRequirement);
        Map<SubmitRequirement, SubmitRequirementResult> results = evaluator.evaluateAllRequirements(changeData, /* includeLegacy= */
        false);
        assertThat(results).hasSize(2);
        assertThat(results.get(globalSubmitRequirement).status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
        assertThat(results.get(projectSubmitRequirement).status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
    }
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

SubmitRequirement (com.google.gerrit.entities.SubmitRequirement)39 SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)27 Test (org.junit.Test)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)8 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)6 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 LegacySubmitRequirement (com.google.gerrit.entities.LegacySubmitRequirement)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 Map (java.util.Map)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 Label (com.google.gerrit.entities.SubmitRecord.Label)3 LinkedHashMap (java.util.LinkedHashMap)3 Optional (java.util.Optional)3 FluentLogger (com.google.common.flogger.FluentLogger)2 LabelType (com.google.gerrit.entities.LabelType)2 PatchSet (com.google.gerrit.entities.PatchSet)2