Search in sources :

Example 11 with SubmitRequirement

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

the class SubmitRequirementIT method projectSubmitRequirementDuplicatesGlobal_overrideAllowed_projectRequirementEvaluated.

@Test
public void projectSubmitRequirementDuplicatesGlobal_overrideAllowed_projectRequirementEvaluated() throws Exception {
    SubmitRequirement globalSubmitRequirement = SubmitRequirement.builder().setName("CoDe-reView").setSubmittabilityExpression(SubmitRequirementExpression.create("topic:test")).setAllowOverrideInChildProjects(true).build();
    try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
        configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
        PushOneCommit.Result r = createChange();
        String changeId = r.getChangeId();
        // Setting the topic does not satisfy submit requirement, because the project definition is
        // evaluated.
        gApi.changes().id(changeId).topic("test");
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        // There is no mismatch with legacy submit requirement, so the single result is emitted.
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
        false);
        // Voting satisfies the project definition.
        voteLabel(changeId, "Code-Review", 2);
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.SATISFIED, /* isLegacy= */
        false);
    }
}
Also used : LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with SubmitRequirement

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

the class SubmitRequirementIT method testLegacySubmitRequirementDuplicatesGlobalStatusMatches.

private void testLegacySubmitRequirementDuplicatesGlobalStatusMatches(boolean allowOverrideInChildProject) throws Exception {
    SubmitRequirement globalSubmitRequirement = SubmitRequirement.builder().setName("CoDe-reView").setSubmittabilityExpression(SubmitRequirementExpression.create("topic:test")).setAllowOverrideInChildProjects(allowOverrideInChildProject).build();
    try (Registration registration = extensionRegistry.newRegistration().add(globalSubmitRequirement)) {
        PushOneCommit.Result r = createChange();
        String changeId = r.getChangeId();
        // Both are evaluated, but only the global is returned, since both are unsatisfied
        ChangeInfo change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.UNSATISFIED, /* isLegacy= */
        false);
        // Both are evaluated, but only the global is returned, since both are satisfied
        voteLabel(changeId, "Code-Review", 2);
        gApi.changes().id(changeId).topic("test");
        change = gApi.changes().id(changeId).get();
        assertThat(change.submitRequirements).hasSize(1);
        assertSubmitRequirementStatus(change.submitRequirements, "CoDe-reView", Status.SATISFIED, /* isLegacy= */
        false);
    }
}
Also used : LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 13 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method submitRequirement_alwaysApplicable.

@Test
public void submitRequirement_alwaysApplicable() {
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "is:true", /* submittabilityExpr= */
    "is:true", /* 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 14 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method byPureRevert.

@Test
public void byPureRevert() throws Exception {
    testRepo.reset("HEAD~1");
    PushOneCommit.Result pushResult = createChange(testRepo, "refs/heads/master", "Fix a bug", "file.txt", "content", "topic");
    changeData = pushResult.getChange();
    changeId = pushResult.getChangeId();
    SubmitRequirement sr = createSubmitRequirement(/* applicabilityExpr= */
    "project:" + project.get(), /* submittabilityExpr= */
    "is:pure-revert", /* overrideExpr= */
    "");
    SubmitRequirementResult result = evaluator.evaluateRequirement(sr, changeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.UNSATISFIED);
    approve(changeId);
    gApi.changes().id(changeId).current().submit();
    ChangeInfo changeInfo = gApi.changes().id(changeId).revert().get();
    String revertId = Integer.toString(changeInfo._number);
    ChangeData revertChangeData = changeQueryProvider.get().byLegacyChangeId(Change.Id.tryParse(revertId).get()).get(0);
    result = evaluator.evaluateRequirement(sr, revertChangeData);
    assertThat(result.status()).isEqualTo(SubmitRequirementResult.Status.SATISFIED);
}
Also used : SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 15 with SubmitRequirement

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

the class SubmitRequirementsEvaluatorIT method globalSubmitRequirement_duplicateInProjectConfig_overrideNotAllowedAllowed_globalResultReturned.

@Test
public void globalSubmitRequirement_duplicateInProjectConfig_overrideNotAllowedAllowed_globalResultReturned() throws Exception {
    SubmitRequirement globalSubmitRequirement = createSubmitRequirement(/*name=*/
    "config-requirement", /* applicabilityExpr= */
    "project:" + project.get(), /*submittabilityExpr= */
    "is:true", /* overrideExpr= */
    "", /*allowOverrideInChildProjects*/
    false);
    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(globalSubmitRequirement).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)

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