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