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);
}
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);
}
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");
}
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);
}
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);
}
}
Aggregations