use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method projectSubmitRequirementDuplicatesGlobal_overrideAllowed_projectRequirementEvaluated.
@Test
public void projectSubmitRequirementDuplicatesGlobal_overrideAllowed_projectRequirementEvaluated() throws Exception {
SubmitRequirement globalSubmitRequirement = SubmitRequirement.builder().setName("CoDe-reView").setSubmittabilityExpression(SubmitRequirementExpression.create("topic:test")).setAllowOverrideInChildProjects(true).build();
try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
// Setting the topic does not satisfy submit requirement, because the project definition is
// evaluated.
gApi.changes().id(changeId).topic("test");
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
// There is no mismatch with legacy submit requirement, so the single result is emitted.
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
// Voting satisfies the project definition.
voteLabel(changeId, "Code-Review", 2);
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
false);
}
}
use of com.google.gerrit.entities.SubmitRequirement in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method testLegacySubmitRequirementDuplicatesGlobalStatusMatches.
private void testLegacySubmitRequirementDuplicatesGlobalStatusMatches(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, but only the global is returned, since both are satisfied
voteLabel(changeId, "Code-Review", 2);
gApi.changes().id(changeId).topic("test");
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
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 submitRequirement_alwaysApplicable.
@Test
public void submitRequirement_alwaysApplicable() {
SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
"is:true", /* submittabilityExpr= */
"is:true", /* 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 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.SubmitRequirement 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);
}
}
Aggregations