Search in sources :

Example 21 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_doubleEscapeSingleQuote.

@Test
public void byFileEdits_doubleEscapeSingleQuote() 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();
    // Users can still provide back-slashes in regexes by escaping them.
    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);
}
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 22 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_invalidFilePattern.

@Test
public void byFileEdits_invalidFilePattern() throws Exception {
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^**',withDiffContaining='content'\"");
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, changeData);
    assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.ERROR);
    assertThat(srResult.errorMessage().get()).isEqualTo("Invalid file pattern.");
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 23 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_modifiedContent_matching.

@Test
public void byFileEdits_modifiedContent_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='three'\"");
    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 24 with SubmitRequirementExpressionResult

use of com.google.gerrit.entities.SubmitRequirementExpressionResult in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_exactMatchingWithFilePath_nonMatching.

@Test
public void byFileEdits_exactMatchingWithFilePath_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:\"'non_existent.txt',withDiffContaining='three'\"");
    ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
    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)

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