Search in sources :

Example 36 with SubmitRequirement

use of com.google.gerrit.entities.SubmitRequirement 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 37 with SubmitRequirement

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

the class ProjectConfigTest method readSubmitRequirementEmpty.

@Test
public void readSubmitRequirementEmpty() throws Exception {
    RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[submit-requirement \"Code-Review\"]\n" + "  submittableIf =  label(Code-Review, +2)\n").create();
    ProjectConfig cfg = read(rev);
    Map<String, SubmitRequirement> submitRequirements = cfg.getSubmitRequirementSections();
    assertThat(submitRequirements).containsExactly("Code-Review", SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.create("label(Code-Review, +2)")).setAllowOverrideInChildProjects(false).build());
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 38 with SubmitRequirement

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

the class ProjectConfigTest method readSubmitRequirementsIdentical_WithCapitalizationDifference.

@Test
public void readSubmitRequirementsIdentical_WithCapitalizationDifference() throws Exception {
    RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[submit-requirement \"code-review\"]\n" + "  description = At least one Code Review +2\n" + "  submittableIf =  label(code-review, +2)\n" + "[submit-requirement \"Code-Review\"]\n" + "  description = Another code review label\n" + "  submittableIf =  label(code-review, +2)\n" + "  canOverrideInChildProjects = true\n").create();
    ProjectConfig cfg = read(rev);
    Map<String, SubmitRequirement> submitRequirements = cfg.getSubmitRequirementSections();
    assertThat(submitRequirements).containsExactly("code-review", SubmitRequirement.builder().setName("code-review").setDescription(Optional.of("At least one Code Review +2")).setSubmittabilityExpression(SubmitRequirementExpression.create("label(code-review, +2)")).setAllowOverrideInChildProjects(false).build());
    assertThat(cfg.getValidationErrors()).hasSize(1);
    assertThat(Iterables.getOnlyElement(cfg.getValidationErrors()).getMessage()).isEqualTo("project.config: Submit requirement 'Code-Review' conflicts with 'code-review'.");
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 39 with SubmitRequirement

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

the class ProjectConfigTest method readSubmitRequirementNoSubmittabilityExpression.

@Test
public void readSubmitRequirementNoSubmittabilityExpression() throws Exception {
    RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[submit-requirement \"Code-Review\"]\n" + "  applicableIf =label(Code-Review, +2)\n").create();
    ProjectConfig cfg = read(rev);
    Map<String, SubmitRequirement> submitRequirements = cfg.getSubmitRequirementSections();
    assertThat(submitRequirements).isEmpty();
    assertThat(cfg.getValidationErrors()).hasSize(1);
    assertThat(Iterables.getOnlyElement(cfg.getValidationErrors()).getMessage()).isEqualTo("project.config: Setting a submittability expression for submit requirement" + " 'Code-Review' is required: Missing" + " submit-requirement.Code-Review.submittableIf");
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Aggregations

SubmitRequirement (com.google.gerrit.entities.SubmitRequirement)39 SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)27 Test (org.junit.Test)24 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)20 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)8 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)6 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)6 LegacySubmitRequirement (com.google.gerrit.entities.LegacySubmitRequirement)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 Map (java.util.Map)5 RevCommit (org.eclipse.jgit.revwalk.RevCommit)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 HashMap (java.util.HashMap)4 Label (com.google.gerrit.entities.SubmitRecord.Label)3 LinkedHashMap (java.util.LinkedHashMap)3 Optional (java.util.Optional)3 FluentLogger (com.google.common.flogger.FluentLogger)2 LabelType (com.google.gerrit.entities.LabelType)2 PatchSet (com.google.gerrit.entities.PatchSet)2