Search in sources :

Example 31 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method submittabilityAndOverrideEvaluated_whenApplicabilityIsEmpty.

@Test
public void submittabilityAndOverrideEvaluated_whenApplicabilityIsEmpty() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    null, /* submittabilityExpr= */
    "message:\"Fix bug\"", /* overrideExpr= */
    "label:\"build-cop-override=-1\"");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
    assertThat(result.applicabilityExpressionResult().isPresent()).isFalse();
    assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(Status.PASS);
    assertThat(result.overrideExpressionResult().get().status()).isEqualTo(Status.FAIL);
}
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 32 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method submittabilityAndOverrideEvaluated_whenApplicabilityIsTrue.

@Test
public void submittabilityAndOverrideEvaluated_whenApplicabilityIsTrue() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:" + project.get(), /* submittabilityExpr= */
    "message:\"Fix bug\"", /* overrideExpr= */
    "label:\"build-cop-override=-1\"");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
    assertThat(result.applicabilityExpressionResult().get().status()).isEqualTo(Status.PASS);
    assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(Status.PASS);
    assertThat(result.overrideExpressionResult().get().status()).isEqualTo(Status.FAIL);
}
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 33 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method submitRequirementIsError_whenApplicabilityExpressionHasInvalidSyntax.

@Test
public void submitRequirementIsError_whenApplicabilityExpressionHasInvalidSyntax() throws Exception {
    addLabel("build-cop-override");
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "invalid_field:invalid_value", /* submittabilityExpr= */
    "label:\"Code-Review=+2\"", /* overrideExpr= */
    "label:\"build-cop-override=+1\"");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.ERROR);
    assertThat(result.applicabilityExpressionResult().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 34 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method submitRequirementIsSatisfied_whenSubmittabilityExpressionIsTrue.

@Test
public void submitRequirementIsSatisfied_whenSubmittabilityExpressionIsTrue() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:" + project.get(), /* submittabilityExpr= */
    "message:\"Fix a bug\"", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
}
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 35 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method globalSubmitRequirement_duplicateInProjectConfig_overrideAllowed_projectResultReturned.

@Test
public void globalSubmitRequirement_duplicateInProjectConfig_overrideAllowed_projectResultReturned() throws Exception {
    SubmitRequirement globalSubmitRequirement = createSubmitRequirement(/*name=*/
    "config-requirement", /* applicabilityExpr= */
    "project:" + project.get(), /*submittabilityExpr= */
    "is:true", /* overrideExpr= */
    "", /*allowOverrideInChildProjects*/
    true);
    try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
        SubmitRequirement projectSubmitRequirement = createSubmitRequirement(/*name=*/
        "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(1);
        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