Search in sources :

Example 36 with SubmitRecord

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

the class ChangeFieldTest method storedSubmitRecordsWithRequirement.

@Test
public void storedSubmitRecordsWithRequirement() {
    SubmitRecord r = record(SubmitRecord.Status.OK, label(SubmitRecord.Label.Status.MAY, "Label-1", null), label(SubmitRecord.Label.Status.OK, "Label-2", 1));
    LegacySubmitRequirement sr = LegacySubmitRequirement.builder().setType("short_type").setFallbackText("Fallback text may contain special symbols like < > \\ / ; :").build();
    r.requirements = Collections.singletonList(sr);
    assertStoredRecordRoundTrip(r);
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) LegacySubmitRequirement(com.google.gerrit.entities.LegacySubmitRequirement) Test(org.junit.Test)

Example 37 with SubmitRecord

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

the class SubmitRequirementsAdapterTest method customSubmitRule_withLabels.

@Test
public void customSubmitRule_withLabels() {
    SubmitRecord submitRecord = createSubmitRecord("gerrit~PrologRule", Status.NOT_READY, Arrays.asList(createLabel("custom-label-1", Label.Status.NEED), createLabel("custom-label-2", Label.Status.REJECT)));
    List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
    false);
    assertThat(requirements).hasSize(2);
    assertResult(requirements.get(0), /* reqName= */
    "custom-label-1", /* submitExpression= */
    "label:custom-label-1=gerrit~PrologRule", SubmitRequirementResult.Status.UNSATISFIED, SubmitRequirementExpressionResult.Status.FAIL);
    assertResult(requirements.get(1), /* reqName= */
    "custom-label-2", /* submitExpression= */
    "label:custom-label-2=gerrit~PrologRule", 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 38 with SubmitRecord

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

the class SubmitRequirementsAdapterTest method defaultSubmitRule_withOneLabelForced.

@Test
public void defaultSubmitRule_withOneLabelForced() {
    SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.OK, Arrays.asList(createLabel("Code-Review", Label.Status.NEED)));
    // Submit records that are forced are written with their initial status in NoteDb, e.g. NEED.
    // If we do a force submit, the gerrit server appends an extra marker record with status=FORCED
    // to indicate that all other records were forced, that's why we explicitly pass isForced=true
    // to the "submit requirements adapter". The resulting submit requirement result has a
    // status=FORCED.
    List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
    true);
    assertThat(requirements).hasSize(1);
    assertResult(requirements.get(0), /* reqName= */
    "Code-Review", /* submitExpression= */
    "label:Code-Review=MAX -label:Code-Review=MIN", SubmitRequirementResult.Status.FORCED, SubmitRequirementExpressionResult.Status.FAIL);
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmitRequirementResult(com.google.gerrit.entities.SubmitRequirementResult) Test(org.junit.Test)

Example 39 with SubmitRecord

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

the class SubmitRequirementsAdapterTest method defaultSubmitRule_withExistingAndNonExistingLabels.

@Test
public void defaultSubmitRule_withExistingAndNonExistingLabels() throws Exception {
    SubmitRecord submitRecord = createSubmitRecord(DefaultSubmitRule.RULE_NAME, Status.OK, Arrays.asList(createLabel("Non-Existing", Label.Status.OK), createLabel("Code-Review", Label.Status.OK)));
    List<SubmitRequirementResult> requirements = SubmitRequirementsAdapter.createResult(submitRecord, labelTypes, psCommitId, /* isForced= */
    false);
    // The "Non-Existing" label was skipped since it does not exist in the project config.
    assertThat(requirements).hasSize(1);
    assertResult(requirements.get(0), /* reqName= */
    "Code-Review", /* submitExpression= */
    "label:Code-Review=MAX -label:Code-Review=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 40 with SubmitRecord

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

the class SubmitRequirementsAdapterTest method defaultSubmitRule_withLabelsAllPass.

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

Aggregations

SubmitRecord (com.google.gerrit.entities.SubmitRecord)49 Test (org.junit.Test)24 SubmitRequirementResult (com.google.gerrit.entities.SubmitRequirementResult)14 Change (com.google.gerrit.entities.Change)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 LabelType (com.google.gerrit.entities.LabelType)6 List (java.util.List)6 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)5 ChangeData (com.google.gerrit.server.query.change.ChangeData)5 Inject (com.google.inject.Inject)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 ImmutableList (com.google.common.collect.ImmutableList)4 FluentLogger (com.google.common.flogger.FluentLogger)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 LabelFunction (com.google.gerrit.entities.LabelFunction)4 PatchSet (com.google.gerrit.entities.PatchSet)4 Project (com.google.gerrit.entities.Project)4 StorageException (com.google.gerrit.exceptions.StorageException)4 DefaultSubmitRule (com.google.gerrit.server.rules.DefaultSubmitRule)4