Search in sources :

Example 11 with SubmitRequirementExpressionResult

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);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 12 with SubmitRequirementExpressionResult

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);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 13 with SubmitRequirementExpressionResult

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);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 14 with SubmitRequirementExpressionResult

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);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 15 with SubmitRequirementExpressionResult

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");
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

SubmitRequirementExpressionResult (com.google.gerrit.entities.SubmitRequirementExpressionResult)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)23 SubmitRequirementExpression (com.google.gerrit.entities.SubmitRequirementExpression)23 Test (org.junit.Test)23 Change (com.google.gerrit.entities.Change)16 ChangeData (com.google.gerrit.server.query.change.ChangeData)16 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)1 ManualRequestContext (com.google.gerrit.server.util.ManualRequestContext)1