use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byFileEdits_addedFile_matching.
@Test
public void byFileEdits_addedFile_matching() 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='of the new'\"");
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_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.SubmitRequirementExpressionResult 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.SubmitRequirementExpressionResult 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.SubmitRequirementExpressionResult 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");
}
Aggregations