diff options
author | Pierre <pierre.guillot@sonarsource.com> | 2023-03-28 10:16:41 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-04-27 20:03:01 +0000 |
commit | 4114d4103e050e6213c2b514773e22d4e4a00bb2 (patch) | |
tree | 5fd582004ad0394e86a1032608a4a276144b911f /server/sonar-db-dao/src/test | |
parent | 3758946e528a5234c5ab9aede8a9206fa161da0a (diff) | |
download | sonarqube-4114d4103e050e6213c2b514773e22d4e4a00bb2.tar.gz sonarqube-4114d4103e050e6213c2b514773e22d4e4a00bb2.zip |
SONAR-18872 improve total ncloc computation9.9.1.69595
Diffstat (limited to 'server/sonar-db-dao/src/test')
-rw-r--r-- | server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java | 40 | ||||
-rw-r--r-- | server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java | 26 |
2 files changed, 30 insertions, 36 deletions
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java index 13cf0c87aff..727addd55bd 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java @@ -365,12 +365,9 @@ public class LiveMeasureDaoTest { db.measures().insertLiveMeasure(projectWithLinesButNoLoc, lines, m -> m.setValue(365d)); db.measures().insertLiveMeasure(projectWithLinesButNoLoc, ncloc, m -> m.setValue(0d)); - SumNclocDbQuery query = SumNclocDbQuery.builder() - .setOnlyPrivateProjects(false) - .build(); - long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query); - - assertThat(result).isEqualTo(10L + 200L); + assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), simpleProject.uuid())).isEqualTo(10L); + assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithBiggerBranch.uuid())).isEqualTo(200L); + assertThat(underTest.sumNclocOfBiggestBranchForProject(db.getSession(), projectWithLinesButNoLoc.uuid())).isZero(); } @Test @@ -410,41 +407,12 @@ public class LiveMeasureDaoTest { public void countNcloc_empty() { db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); db.measures().insertMetric(m -> m.setKey("lines").setValueType(INT.toString())); - SumNclocDbQuery query = SumNclocDbQuery.builder() - .setOnlyPrivateProjects(false) - .build(); - long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query); + long result = underTest.sumNclocOfBiggestBranchForProject(db.getSession(), "non-existing-project-uuid"); assertThat(result).isZero(); } @Test - public void countNcloc_and_exclude_project() { - MetricDto ncloc = db.measures().insertMetric(m -> m.setKey("ncloc").setValueType(INT.toString())); - - ComponentDto simpleProject = db.components().insertPublicProject(); - db.measures().insertLiveMeasure(simpleProject, ncloc, m -> m.setValue(10d)); - - ComponentDto projectWithBiggerBranch = db.components().insertPublicProject(); - ComponentDto bigBranch = db.components().insertProjectBranch(projectWithBiggerBranch, b -> b.setBranchType(BranchType.BRANCH)); - db.measures().insertLiveMeasure(projectWithBiggerBranch, ncloc, m -> m.setValue(100d)); - db.measures().insertLiveMeasure(bigBranch, ncloc, m -> m.setValue(200d)); - - ComponentDto projectToExclude = db.components().insertPublicProject(); - ComponentDto projectToExcludeBranch = db.components().insertProjectBranch(projectToExclude, b -> b.setBranchType(BranchType.BRANCH)); - db.measures().insertLiveMeasure(projectToExclude, ncloc, m -> m.setValue(300d)); - db.measures().insertLiveMeasure(projectToExcludeBranch, ncloc, m -> m.setValue(400d)); - - SumNclocDbQuery query = SumNclocDbQuery.builder() - .setProjectUuidToExclude(projectToExclude.uuid()) - .setOnlyPrivateProjects(false) - .build(); - long result = underTest.sumNclocOfBiggestBranch(db.getSession(), query); - - assertThat(result).isEqualTo(10L + 200L); - } - - @Test public void insert_data() { byte[] data = "text_value".getBytes(StandardCharsets.UTF_8); MetricDto metric = db.measures().insertMetric(); diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java index 51476f1449f..ec4defa6af7 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java @@ -31,6 +31,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.IntStream; import javax.annotation.Nullable; +import org.assertj.core.api.Assertions; import org.assertj.core.groups.Tuple; import org.junit.Rule; import org.junit.Test; @@ -280,6 +281,31 @@ public class ProjectDaoTest { } @Test + public void update_ncloc_should_update_project() { + ComponentDto project = db.components().insertPublicProject(); + + projectDao.updateNcloc(db.getSession(), project.uuid(), 10L); + + Assertions.assertThat(projectDao.getNclocSum(db.getSession())).isEqualTo(10L); + } + + @Test + public void getNcloc_sum_compute_correctly_sum_of_projects() { + projectDao.updateNcloc(db.getSession(), db.components().insertPublicProject().uuid(), 1L); + projectDao.updateNcloc(db.getSession(), db.components().insertPublicProject().uuid(), 20L); + projectDao.updateNcloc(db.getSession(), db.components().insertPublicProject().uuid(), 100L); + Assertions.assertThat(projectDao.getNclocSum(db.getSession())).isEqualTo(121L); + } + + @Test + public void getNcloc_sum_compute_correctly_sum_of_projects_while_excluding_project() { + projectDao.updateNcloc(db.getSession(), db.components().insertPublicProject().uuid(), 1L); + projectDao.updateNcloc(db.getSession(), db.components().insertPublicProject().uuid(), 20L); + ComponentDto project3 = db.components().insertPublicProject(); + projectDao.updateNcloc(db.getSession(), project3.uuid(), 100L); + Assertions.assertThat(projectDao.getNclocSum(db.getSession(), project3.uuid())).isEqualTo(21L); + } + @Test public void selectAllProjectUuids_shouldOnlyReturnProjectWithTRKQualifier() { ComponentDto application = db.components().insertPrivateApplication(); ComponentDto project = db.components().insertPrivateProject(); |