use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_addedContent_matching.
@Test
public void byFileEdits_addedContent_matching() throws Exception {
Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT + "line 4\n").childOf().change(parent).create();
SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line 4'\"");
ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
}
use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_notMatchingWithFilePath.
@Test
public void byFileEdits_notMatchingWithFilePath() throws Exception {
Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT.replace("line 3\n", "line three\n")).childOf().change(parent).create();
// commit edit only matches with files ending with ".java". Since our modified file name ends
// with ".txt", the applicability expression will not match.
SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.java',withDiffContaining='three'\"");
ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.FAIL);
}
use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_modifiedContent_nonMatching.
@Test
public void byFileEdits_modifiedContent_nonMatching() throws Exception {
Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT.replace("line 3\n", "line three\n")).childOf().change(parent).create();
SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='ten'\"");
ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.FAIL);
}
use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method throwingSubmitRequirementPredicate.
@Test
public void throwingSubmitRequirementPredicate() throws Exception {
try (Registration registration = extensionRegistry.newRegistration().add(new ThrowingSubmitRequirementPredicate(), ThrowingSubmitRequirementPredicate.OPERAND)) {
SubmitRequirementExpression expression = SubmitRequirementExpression.create(String.format("is:%s_%s", ThrowingSubmitRequirementPredicate.OPERAND, PLUGIN_NAME));
SubmitRequirementExpressionResult result = evaluator.evaluateExpression(expression, changeData);
assertThat(result.status()).isEqualTo(Status.ERROR);
assertThat(result.errorMessage().get()).isEqualTo(ThrowingSubmitRequirementPredicate.ERROR_MESSAGE);
}
}
use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_addedContent_nonMatching.
@Test
public void byFileEdits_addedContent_nonMatching() throws Exception {
Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT + "line 4\n").childOf().change(parent).create();
SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line 5'\"");
ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.FAIL);
}
Aggregations