use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byPureRevert.
@Test
public void byPureRevert() throws Exception {
testRepo.reset("HEAD~1");
PushOneCommit.Result pushResult = createChange(testRepo, "refs/heads/master", "Fix a bug", "file.txt", "content", "topic");
changeData = pushResult.getChange();
changeId = pushResult.getChangeId();
SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
"project:" + project.get(), /* submittabilityExpr= */
"is:pure-revert", /* overrideExpr= */
"");
SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.UNSATISFIED);
approve(changeId);
gApi.changes().id(changeId).current().submit();
ChangeInfo changeInfo = gApi.changes().id(changeId).revert().get();
String revertId = Integer.toString(changeInfo._number);
ChangeData revertChangeData = changeQueryProvider.get().byLegacyChangeId(Change.Id.tryParse(revertId).get()).get(0);
result = evaluator.evaluateRequirement(sr, revertChangeData);
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method globalSubmitRequirement_duplicateInProjectConfig_overrideNotAllowedAllowed_globalResultReturned.
@Test
public void globalSubmitRequirement_duplicateInProjectConfig_overrideNotAllowedAllowed_globalResultReturned() throws Exception {
SubmitRequirement globalSubmitRequirement = createSubmitRequirement(/*name=*/
"config-requirement", /* applicabilityExpr= */
"project:" + project.get(), /*submittabilityExpr= */
"is:true", /* overrideExpr= */
"", /*allowOverrideInChildProjects*/
false);
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(globalSubmitRequirement).status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
}
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method submitRequirementIsOverridden_whenOverrideExpressionIsTrue.
@Test
public void submitRequirementIsOverridden_whenOverrideExpressionIsTrue() throws Exception {
addLabel("build-cop-override");
voteLabel(changeId, "build-cop-override", 1);
// Reload change data after applying the vote
changeData = changeQueryProvider.get().byLegacyChangeId(changeData.getId()).stream().collect(MoreCollectors.onlyElement());
SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
"project:" + project.get(), /* submittabilityExpr= */
"label:\"Code-Review=+2\"", /* overrideExpr= */
"label:\"build-cop-override=+1\"");
SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.OVERRIDDEN);
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method submitRequirementIsError_whenOverrideExpressionHasInvalidSyntax.
@Test
public void submitRequirementIsError_whenOverrideExpressionHasInvalidSyntax() throws Exception {
SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
"project:" + project.get(), /* submittabilityExpr= */
"label:\"Code-Review=+2\"", /* overrideExpr= */
"invalid_field:invalid_value");
SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.ERROR);
assertThat(result.overrideExpressionResult().get().errorMessage().get()).isEqualTo("Unsupported operator invalid_field:invalid_value");
}
use of com.google.gerrit.entities.SubmitRequirementResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method checkSubmitRequirementResult.
private void checkSubmitRequirementResult(ChangeData cd, String submittabilityExpr, SubmitRequirementResult.Status expectedStatus) {
SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
"project:" + project.get(), submittabilityExpr, /* overrideExpr= */
"");
SubmitRequirementResult result = evaluator.evaluateRequirement(sr, cd);
assertThat(result.status()).isEqualTo(expectedStatus);
}
Aggregations