use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method compositeExpression.
@Test
public void compositeExpression() throws Exception {
SubmitRequirementExpression expression = SubmitRequirementExpression.create(String.format("(project:%s AND branch:refs/heads/foo) OR message:\"Fix a bug\"", project.get()));
SubmitRequirementExpressionResult result = evaluator.evaluateExpression(expression, changeData);
assertThat(result.status()).isEqualTo(Status.PASS);
assertThat(result.passingAtoms()).containsExactly(String.format("project:%s", project.get()), "message:\"Fix a bug\"");
assertThat(result.failingAtoms()).containsExactly(String.format("branch:refs/heads/foo"));
}
use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_addedFile_nonMatching.
@Test
public void byFileEdits_addedFile_nonMatching() throws Exception {
Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
Change.Id childId = changeOperations.newChange().file("new_file.txt").content("content of the new file").childOf().change(parent).create();
SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^new.*\\.txt',withDiffContaining='not_exist'\"");
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 expressionWithFailingPredicate.
@Test
public void expressionWithFailingPredicate() throws Exception {
SubmitRequirementExpression expression = SubmitRequirementExpression.create("branch:refs/heads/foo");
SubmitRequirementExpressionResult result = evaluator.evaluateExpression(expression, changeData);
assertThat(result.status()).isEqualTo(Status.FAIL);
assertThat(result.errorMessage()).isEqualTo(Optional.empty());
}
use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_invalidContentPattern.
@Test
public void byFileEdits_invalidContentPattern() throws Exception {
SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'fileName\\.txt',withDiffContaining='^**'\"");
SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, changeData);
assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.ERROR);
assertThat(srResult.errorMessage().get()).isEqualTo("Invalid content pattern.");
}
use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_escapeSingleQuotes.
@Test
public void byFileEdits_escapeSingleQuotes() 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' is modified\n")).childOf().change(parent).create();
SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line \\'three\\' is'\"");
ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
}
Aggregations