Search in sources :

Example 66 with LabelType

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);
}
Also used : LabelType(com.google.gerrit.entities.LabelType) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 67 with LabelType

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);
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) TestRepository(org.eclipse.jgit.junit.TestRepository) Injector(com.google.inject.Injector) LabelType(com.google.gerrit.entities.LabelType) InMemoryModule(com.google.gerrit.testing.InMemoryModule) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Before(org.junit.Before)

Example 68 with LabelType

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);
}
Also used : LabelType(com.google.gerrit.entities.LabelType) Test(org.junit.Test)

Example 69 with LabelType

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);
    }
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) LabelType(com.google.gerrit.entities.LabelType) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 70 with LabelType

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);
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) LabelType(com.google.gerrit.entities.LabelType) AccessSection(com.google.gerrit.entities.AccessSection)

Aggregations

LabelType (com.google.gerrit.entities.LabelType)71 Test (org.junit.Test)26 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)20 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)16 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)13 Map (java.util.Map)12 LabelTypes (com.google.gerrit.entities.LabelTypes)10 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 Account (com.google.gerrit.entities.Account)8 LabelValue (com.google.gerrit.entities.LabelValue)8 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)8 HashMap (java.util.HashMap)8 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)7 ArrayList (java.util.ArrayList)7 LabelPermission (com.google.gerrit.server.permissions.LabelPermission)6 ProjectState (com.google.gerrit.server.project.ProjectState)6 Change (com.google.gerrit.entities.Change)5 SubmitRecord (com.google.gerrit.entities.SubmitRecord)5