Search in sources :

Example 6 with SubmitRequirementExpression

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

the class SubmitRequirementsEvaluatorIT method byFileEdits_notMatchingWithFilePath.

@Test
public void byFileEdits_notMatchingWithFilePath() 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();
    // commit edit only matches with files ending with ".java". Since our modified file name ends
    // with ".txt", the applicability expression will not match.
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.java',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)

Example 7 with SubmitRequirementExpression

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

the class SubmitRequirementsEvaluatorIT method byFileEdits_modifiedContent_nonMatching.

@Test
public void byFileEdits_modifiedContent_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:\"'^.*\\.txt',withDiffContaining='ten'\"");
    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)

Example 8 with SubmitRequirementExpression

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

the class SubmitRequirementsEvaluatorIT method throwingSubmitRequirementPredicate.

@Test
public void throwingSubmitRequirementPredicate() throws Exception {
    try (Registration registration = extensionRegistry.newRegistration().add(new ThrowingSubmitRequirementPredicate(), ThrowingSubmitRequirementPredicate.OPERAND)) {
        SubmitRequirementExpression expression = SubmitRequirementExpression.create(String.format("is:%s_%s", ThrowingSubmitRequirementPredicate.OPERAND, PLUGIN_NAME));
        SubmitRequirementExpressionResult result = evaluator.evaluateExpression(expression, changeData);
        assertThat(result.status()).isEqualTo(Status.ERROR);
        assertThat(result.errorMessage().get()).isEqualTo(ThrowingSubmitRequirementPredicate.ERROR_MESSAGE);
    }
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with SubmitRequirementExpression

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

the class SubmitRequirementsEvaluatorIT method byFileEdits_addedContent_nonMatching.

@Test
public void byFileEdits_addedContent_nonMatching() throws Exception {
    Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
    Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT + "line 4\n").childOf().change(parent).create();
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line 5'\"");
    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)

Example 10 with SubmitRequirementExpression

use of com.google.gerrit.entities.SubmitRequirementExpression 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)

Aggregations

SubmitRequirementExpression (com.google.gerrit.entities.SubmitRequirementExpression)24 Test (org.junit.Test)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)23 SubmitRequirementExpressionResult (com.google.gerrit.entities.SubmitRequirementExpressionResult)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