use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class ProjectConfigTest method readConfigLabelDefaultValue.
@Test
public void readConfigLabelDefaultValue() throws Exception {
RevCommit rev = tr.commit().add("groups", group(developers)).add("project.config", "[label \"CustomLabel\"]\n" + " value = -1 Negative\n" + // No 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 RefControlTest method setUp.
@Before
public void setUp() throws Exception {
Injector injector = Guice.createInjector(new InMemoryModule());
injector.injectMembers(this);
// Tests previously used ProjectConfig.Factory to create ProjectConfigs without going through
// the ProjectCache, which was wrong. Manually call getInstance so we don't store it in a
// field that is accessible to test methods.
ProjectConfig.Factory projectConfigFactory = injector.getInstance(ProjectConfig.Factory.class);
singleVersionListener.start();
try {
schemaCreator.create();
} finally {
singleVersionListener.stop();
}
// changing defaults in SchemaCreator or ProjectCreator.
try (Repository allProjectsRepo = repoManager.createRepository(allProjectsName);
TestRepository<Repository> tr = new TestRepository<>(allProjectsRepo)) {
tr.delete(REFS_CONFIG);
try (MetaDataUpdate md = metaDataUpdateFactory.create(allProjectsName)) {
ProjectConfig allProjectsConfig = projectConfigFactory.create(allProjectsName);
allProjectsConfig.load(md);
LabelType cr = TestLabels.codeReview();
allProjectsConfig.upsertLabelType(cr);
allProjectsConfig.commit(md);
}
}
repoManager.createRepository(parentKey).close();
repoManager.createRepository(localKey).close();
try (MetaDataUpdate md = metaDataUpdateFactory.create(localKey)) {
ProjectConfig newLocal = projectConfigFactory.create(localKey);
newLocal.load(md);
newLocal.updateProject(p -> p.setParent(parentKey));
newLocal.commit(md);
}
requestContext.setContext(() -> null);
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class SchemaCreatorImplTest method createSchema_Label_CodeReview.
@Test
public void createSchema_Label_CodeReview() throws Exception {
LabelType codeReview = getLabelTypes().byLabel("Code-Review").get();
assertThat(codeReview).isNotNull();
assertThat(codeReview.getName()).isEqualTo("Code-Review");
assertThat(codeReview.getDefaultValue()).isEqualTo(0);
assertThat(codeReview.getFunction()).isEqualTo(LabelFunction.MAX_WITH_BLOCK);
assertThat(codeReview.isCopyMinScore()).isTrue();
assertValueRange(codeReview, -2, -1, 0, 1, 2);
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class CommentAddedEventIT method reviewChange_MultipleVotes.
@Test
public void reviewChange_MultipleVotes() throws Exception {
TestListener listener = new TestListener();
try (Registration registration = extensionRegistry.newRegistration().add(listener)) {
saveLabelConfig();
PushOneCommit.Result r = createChange();
ReviewInput reviewInput = new ReviewInput().label(label.getName(), -1);
reviewInput.message = label.getName();
revision(r).review(reviewInput);
ChangeInfo c = get(r.getChangeId(), DETAILED_LABELS);
LabelInfo q = c.labels.get(label.getName());
assertThat(q.all).hasSize(1);
ApprovalValues labelAttr = getApprovalValues(label, listener);
assertThat(labelAttr.oldValue).isEqualTo(0);
assertThat(labelAttr.value).isEqualTo(-1);
assertThat(listener.getLastCommentAddedEvent().getComment()).isEqualTo(String.format("Patch Set 1: %s-1\n\n%s", label.getName(), label.getName()));
// there should be 3 approval labels (label, pLabel, and CRVV)
assertThat(listener.getLastCommentAddedEvent().getApprovals()).hasSize(3);
// check the approvals that were not voted on
ApprovalValues pLabelAttr = getApprovalValues(pLabel, listener);
assertThat(pLabelAttr.oldValue).isNull();
assertThat(pLabelAttr.value).isEqualTo(0);
LabelType crLabel = LabelType.withDefaultValues("Code-Review");
ApprovalValues crlAttr = getApprovalValues(crLabel, listener);
assertThat(crlAttr.oldValue).isNull();
assertThat(crlAttr.value).isEqualTo(0);
// update pLabel approval
reviewInput = new ReviewInput().label(pLabel.getName(), 1);
reviewInput.message = pLabel.getName();
revision(r).review(reviewInput);
c = get(r.getChangeId(), DETAILED_LABELS);
q = c.labels.get(label.getName());
assertThat(q.all).hasSize(1);
pLabelAttr = getApprovalValues(pLabel, listener);
assertThat(pLabelAttr.oldValue).isEqualTo(0);
assertThat(pLabelAttr.value).isEqualTo(1);
assertThat(listener.getLastCommentAddedEvent().getComment()).isEqualTo(String.format("Patch Set 1: %s+1\n\n%s", pLabel.getName(), pLabel.getName()));
// check the approvals that were not voted on
labelAttr = getApprovalValues(label, listener);
assertThat(labelAttr.oldValue).isNull();
assertThat(labelAttr.value).isEqualTo(-1);
crlAttr = getApprovalValues(crLabel, listener);
assertThat(crlAttr.oldValue).isNull();
assertThat(crlAttr.value).isEqualTo(0);
}
}
use of com.google.gerrit.entities.LabelType in project gerrit by GerritCodeReview.
the class LabelNormalizerTest method configureProject.
private void configureProject() throws Exception {
ProjectConfig pc = loadAllProjects();
for (AccessSection sec : pc.getAccessSections()) {
pc.upsertAccessSection(sec.getName(), updatedSection -> {
for (String label : pc.getLabelSections().keySet()) {
updatedSection.removePermission(forLabel(label));
}
});
}
LabelType lt = label(LabelId.VERIFIED, value(1, LabelId.VERIFIED), value(0, "No score"), value(-1, "Fails"));
pc.upsertLabelType(lt);
save(pc);
}
Aggregations