Search in sources :

Example 31 with SubmitRequirementResult

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

the class SubmitRequirementsEvaluatorIT method submitRequirementIsSatisfied_whenSubmittabilityExpressionIsTrue.

@Test
public void submitRequirementIsSatisfied_whenSubmittabilityExpressionIsTrue() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:" + project.get(), /* submittabilityExpr= */
    "message:\"Fix a bug\"", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 32 with SubmitRequirementResult

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

the class SubmitRequirementsEvaluatorIT method globalSubmitRequirement_duplicateInProjectConfig_overrideAllowed_projectResultReturned.

@Test
public void globalSubmitRequirement_duplicateInProjectConfig_overrideAllowed_projectResultReturned() throws Exception {
    SubmitRequirement globalSubmitRequirement = createSubmitRequirement(/*name=*/
    "config-requirement", /* applicabilityExpr= */
    "project:" + project.get(), /*submittabilityExpr= */
    "is:true", /* overrideExpr= */
    "", /*allowOverrideInChildProjects*/
    true);
    try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
        SubmitRequirement projectSubmitRequirement = createSubmitRequirement(/*name=*/
        "config-requirement", /* applicabilityExpr= */
        "project:" + project.get(), /*submittabilityExpr= */
        "is:true", /* overrideExpr= */
        "", /*allowOverrideInChildProjects*/
        false);
        configSubmitRequirement(project, projectSubmitRequirement);
        Map<SubmitRequirement, SubmitRequirementResult> results = evaluator.evaluateAllRequirements(changeData, /* includeLegacy= */
        false);
        assertThat(results).hasSize(1);
        assertThat(results.get(projectSubmitRequirement).status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
    }
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 33 with SubmitRequirementResult

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

the class SubmitRequirementsEvaluatorIT method submitRequirementIsUnsatisfied_whenSubmittabilityExpressionIsFalse.

@Test
public void submitRequirementIsUnsatisfied_whenSubmittabilityExpressionIsFalse() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:" + project.get(), /* submittabilityExpr= */
    "label:\"Code-Review=+2\"", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.UNSATISFIED);
    assertThat(result.submittabilityExpressionResult().get().failingAtoms()).containsExactly("label:\"Code-Review=+2\"");
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 34 with SubmitRequirementResult

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

the class SubmitRequirementJsonSerializerTest method submitRequirementResult_emptySubmittabilityExpressionResultField_roundTrip.

@Test
public void submitRequirementResult_emptySubmittabilityExpressionResultField_roundTrip() throws Exception {
    SubmitRequirementResult srResult = srReqResult.toBuilder().submittabilityExpressionResult(Optional.empty()).applicabilityExpressionResult(Optional.empty()).overrideExpressionResult(Optional.empty()).build();
    TypeAdapter<SubmitRequirementResult> adapter = SubmitRequirementResult.typeAdapter(gson);
    assertThat(adapter.fromJson(adapter.toJson(srResult))).isEqualTo(srResult);
}
Also used : SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test)

Example 35 with SubmitRequirementResult

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

the class SubmitRequirementJsonSerializerTest method submitRequirementResult_withHidden_roundTrip.

@Test
public void submitRequirementResult_withHidden_roundTrip() throws Exception {
    SubmitRequirementResult srResultWithHidden = srReqResult.toBuilder().hidden(Optional.of(true)).build();
    TypeAdapter<SubmitRequirementResult> adapter = SubmitRequirementResult.typeAdapter(gson);
    assertThat(adapter.fromJson(adapter.toJson(srResultWithHidden))).isEqualTo(srResultWithHidden);
}
Also used : SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test)

Aggregations

SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)47 Test (org.junit.Test)36 SubmitRequirement (com.google.gerrit.entities.SubmitRequirement)27 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)21 SubmitRecord (com.google.gerrit.entities.SubmitRecord)14 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 Map (java.util.Map)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)3 VerifyNoPiiInChangeNotes (com.google.gerrit.acceptance.VerifyNoPiiInChangeNotes)3 Project (com.google.gerrit.entities.Project)3 Label (com.google.gerrit.entities.SubmitRecord.Label)3 SubmitType (com.google.gerrit.extensions.client.SubmitType)3 HashMap (java.util.HashMap)3 Optional (java.util.Optional)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3