use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method submitRequirement_returnsEmpty_forMergedChangeWithPreviouslyStoredSRs.
@Test
public void submitRequirement_returnsEmpty_forMergedChangeWithPreviouslyStoredSRs() throws Exception {
for (SubmitType submitType : SubmitType.values()) {
Project.NameKey project = createProjectForPush(submitType);
TestRepository<InMemoryRepository> repo = cloneProject(project);
configSubmitRequirement(project, SubmitRequirement.builder().setName("Code-Review").setSubmittabilityExpression(SubmitRequirementExpression.maxCodeReview()).setAllowOverrideInChildProjects(false).build());
PushOneCommit.Result r = createChange(repo, "master", "Add a file", "foo", "content", "topic");
String changeId = r.getChangeId();
// Abandon change. Submit requirements get stored in the revision note of patch-set 1.
gApi.changes().id(changeId).abandon();
ChangeInfo change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).hasSize(1);
assertSubmitRequirementStatus(change.submitRequirements, "Code-Review", Status.UNSATISFIED, /* isLegacy= */
false);
// Clear SRs for the project and update code-review label to be non-blocking.
clearSubmitRequirements(project);
LabelType cr = TestLabels.codeReview().toBuilder().setFunction(LabelFunction.NO_BLOCK).build();
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(cr);
u.save();
}
// Restore the change. No SRs apply.
gApi.changes().id(changeId).restore();
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).isEmpty();
// Merge the change. Still, no SRs apply.
gApi.changes().id(changeId).current().submit();
change = gApi.changes().id(changeId).get();
assertThat(change.submitRequirements).isEmpty();
}
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class SubmitRequirementIT method legacySubmitRequirementWithIgnoreSelfApproval.
@Test
public void legacySubmitRequirementWithIgnoreSelfApproval() throws Exception {
LabelType verified = label(LabelId.VERIFIED, value(1, "Passes"), value(0, "No score"), value(-1, "Failed"));
verified = verified.toBuilder().setIgnoreSelfApproval(true).build();
try (ProjectConfigUpdate u = updateProject(project)) {
u.getConfig().upsertLabelType(verified);
u.save();
}
projectOperations.project(project).forUpdate().add(allowLabel(verified.getName()).ref(RefNames.REFS_HEADS + "*").group(REGISTERED_USERS).range(-1, 1)).update();
// The DefaultSubmitRule emits an "OK" submit record for Verified, while the
// ignoreSelfApprovalRule emits a "NEED" submit record. The "submit requirements" adapter merges
// both results and returns the blocking one only.
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
gApi.changes().id(changeId).addReviewer(user.id().toString());
voteLabel(changeId, verified.getName(), +1);
ChangeInfo changeInfo = gApi.changes().id(changeId).get();
Collection<SubmitRequirementResultInfo> submitRequirements = changeInfo.submitRequirements;
assertSubmitRequirementStatus(submitRequirements, "Verified", Status.UNSATISFIED, /* isLegacy= */
true);
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class LabelTypeSerializerTest method roundTripWithMinimalValues.
@Test
public void roundTripWithMinimalValues() {
LabelType autoValue = ALL_VALUES_SET.toBuilder().setRefPatterns(null).setCopyCondition(null).build();
assertThat(deserialize(serialize(autoValue))).isEqualTo(autoValue);
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class ProjectConfigTest method readConfigLabelOldStyleWithLeadingSpace.
@Test
public void readConfigLabelOldStyleWithLeadingSpace() throws Exception {
RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[label \"CustomLabel\"]\n" + " value = -1 Negative\n" + // Leading space before 0.
" value = 0 No Score\n" + " value = 1 Positive\n").create();
ProjectConfig cfg = read(rev);
Map<String, LabelType> labels = cfg.getLabelSections();
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
assertThat((int) dv).isEqualTo(0);
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class ProjectConfigTest method readConfigLabelDefaultValueInRange.
@Test
public void readConfigLabelDefaultValueInRange() throws Exception {
RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[label \"CustomLabel\"]\n" + " value = -1 Negative\n" + " value = 0 No Score\n" + " value = 1 Positive\n" + " defaultValue = -1\n").create();
ProjectConfig cfg = read(rev);
Map<String, LabelType> labels = cfg.getLabelSections();
Short dv = labels.entrySet().iterator().next().getValue().getDefaultValue();
assertThat((int) dv).isEqualTo(-1);
}
Aggregations