Search in sources :

Example 16 with SubmitRequirementResult

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

the class SubmitRequirementsEvaluatorIT method submitRequirementIsNotApplicable_whenApplicabilityExpressionIsFalse.

@Test
public void submitRequirementIsNotApplicable_whenApplicabilityExpressionIsFalse() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:non-existent-project", /* submittabilityExpr= */
    "message:\"Fix bug\"", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.NOT_APPLICABLE);
}
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 17 with SubmitRequirementResult

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

the class SubmitRequirementsEvaluatorIT method submittabilityIsEvaluated_whenOverrideApplies.

@Test
public void submittabilityIsEvaluated_whenOverrideApplies() throws Exception {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    null, /* submittabilityExpr= */
    "message:\"Fix bug\"", /* overrideExpr= */
    "project:" + project.get());
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.OVERRIDDEN);
    assertThat(result.applicabilityExpressionResult().isPresent()).isFalse();
    assertThat(result.submittabilityExpressionResult().get().status()).isEqualTo(Status.PASS);
    assertThat(result.overrideExpressionResult().get().status()).isEqualTo(Status.PASS);
}
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 18 with SubmitRequirementResult

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

the class SubmitRequirementsAdapterTest method defaultSubmitRule_withLabelStatusNeed_labelHasIgnoreSelfApproval.

@Test
public void defaultSubmitRule_withLabelStatusNeed_labelHasIgnoreSelfApproval() throws Exception {
    SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.NOT_READY, Arrays.asList(createLabel("ISA-Label", Label.Status.NEED)));
    List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
    false);
    assertThat(requirements).hasSize(1);
    assertResult(requirements.get(0), /* reqName= */
    "ISA-Label", /* submitExpression= */
    "label:ISA-Label=MAX,user=non_uploader -label:ISA-Label=MIN", SubmitRequirementResult.Status.UNSATISFIED, SubmitRequirementExpressionResult.Status.FAIL);
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test)

Example 19 with SubmitRequirementResult

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

the class SubmitRequirementsAdapterTest method defaultSubmitRule_withLabelStatusOk_labelHasIgnoreSelfApproval.

@Test
public void defaultSubmitRule_withLabelStatusOk_labelHasIgnoreSelfApproval() throws Exception {
    SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.OK, Arrays.asList(createLabel("ISA-Label", Label.Status.OK)));
    List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
    false);
    assertThat(requirements).hasSize(1);
    assertResult(requirements.get(0), /* reqName= */
    "ISA-Label", /* submitExpression= */
    "label:ISA-Label=MAX,user=non_uploader -label:ISA-Label=MIN", SubmitRequirementResult.Status.SATISFIED, SubmitRequirementExpressionResult.Status.PASS);
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test)

Example 20 with SubmitRequirementResult

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

the class CheckSubmitRequirement method apply.

@Override
public Response<SubmitRequirementResultInfo> apply(ChangeResource resource, SubmitRequirementInput input) throws BadRequestException {
    SubmitRequirement requirement = createSubmitRequirement(input);
    SubmitRequirementResult res = evaluator.evaluateRequirement(requirement, resource.getChangeData());
    return Response.ok(SubmitRequirementsJson.toInfo(requirement, res));
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult)

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