use of com.google.gerrit.entities.SubmitRequirementExpression in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_modifiedContentPattern_matching.
@Test
public void byFileEdits_modifiedContentPattern_matching() 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='^.*th[rR]ee$'\"");
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.SubmitRequirementExpression in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_invalidSyntax.
@Test
public void byFileEdits_invalidSyntax() 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=forgot single quotes\"");
ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
// If the format is invalid, the operator falls back to the default operator of
// ChangeQueryBuilder which does not match the change, i.e. returns false.
assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.FAIL);
}
use of com.google.gerrit.entities.SubmitRequirementExpression in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_exactMatchingWithFilePath_matching.
@Test
public void byFileEdits_exactMatchingWithFilePath_matching() 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(String.format("file:\"'%s',withDiffContaining='three'\"", FILE_NAME));
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.SubmitRequirementExpression in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method invalidExpression.
@Test
public void invalidExpression() throws Exception {
SubmitRequirementExpression expression = SubmitRequirementExpression.create("invalid_field:invalid_value");
SubmitRequirementExpressionResult result = evaluator.evaluateExpression(expression, changeData);
assertThat(result.status()).isEqualTo(Status.ERROR);
assertThat(result.errorMessage().get()).isEqualTo("Unsupported operator invalid_field:invalid_value");
}
use of com.google.gerrit.entities.SubmitRequirementExpression 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"));
}
Aggregations