3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 package org.sonar.ce.task.projectanalysis.step;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolderRule;
25 import org.sonar.ce.task.step.TestComputationStepContext;
26 import org.sonar.db.DbClient;
27 import org.sonar.db.DbTester;
28 import org.sonar.db.component.BranchType;
29 import org.sonar.db.component.ComponentDto;
30 import org.sonar.db.metric.MetricDto;
31 import org.sonar.server.project.Project;
33 import static java.util.Collections.emptyList;
34 import static org.assertj.core.api.Assertions.assertThat;
35 import static org.sonar.api.measures.Metric.ValueType.INT;
37 public class ProjectNclocComputationStepIT {
39 public DbTester db = DbTester.create();
40 private final DbClient dbClient = db.getDbClient();
43 public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
45 private final ProjectNclocComputationStep step = new ProjectNclocComputationStep(analysisMetadataHolder, dbClient);
48 public void test_computing_branch_ncloc() {
49 MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString()));
50 ComponentDto project = db.components().insertPublicProject().getMainBranchComponent();
51 ComponentDto branch1 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
52 db.measures().insertLiveMeasure(branch1, ncloc, m -> m.setValue(200d));
53 ComponentDto branch2 = db.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.BRANCH));
54 db.measures().insertLiveMeasure(branch2, ncloc, m -> m.setValue(10d));
55 analysisMetadataHolder.setProject(new Project(project.uuid(), project.getKey(), project.name(), project.description(), emptyList()));
56 step.execute(TestComputationStepContext.TestStatistics::new);
58 assertThat(dbClient.projectDao().getNclocSum(db.getSession())).isEqualTo(200L);
62 public void description_is_not_missing() {
63 assertThat(step.getDescription()).isNotBlank();