diff options
author | Matteo Mara <matteo.mara@sonarsource.com> | 2024-07-11 12:11:11 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-07-24 20:02:48 +0000 |
commit | 2b2f246731c4052c4052e2f2d56416352132114f (patch) | |
tree | df46cec1c90793c9d96612068da5025fc53c8b55 /server/sonar-telemetry/src/test/java/org/sonar | |
parent | f1ea5d752726f3129b0266ea07fed1a84c45aa51 (diff) | |
download | sonarqube-2b2f246731c4052c4052e2f2d56416352132114f.tar.gz sonarqube-2b2f246731c4052c4052e2f2d56416352132114f.zip |
SONAR-22479 added new telemetry metric "ncloc" for language dimension
Diffstat (limited to 'server/sonar-telemetry/src/test/java/org/sonar')
-rw-r--r-- | server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryNclocProviderTest.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryNclocProviderTest.java b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryNclocProviderTest.java new file mode 100644 index 00000000000..00aeb98086e --- /dev/null +++ b/server/sonar-telemetry/src/test/java/org/sonar/telemetry/TelemetryNclocProviderTest.java @@ -0,0 +1,71 @@ +/* + * SonarQube + * Copyright (C) 2009-2024 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.telemetry; + +import java.util.Arrays; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.measure.ProjectLocDistributionDto; +import org.sonar.db.metric.MetricDto; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.sonar.api.measures.CoreMetrics.NCLOC_KEY; +import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY; +import static org.sonar.telemetry.TelemetryNclocProvider.METRIC_KEY; + +class TelemetryNclocProviderTest { + + DbClient dbClient = mock(DbClient.class, Mockito.RETURNS_DEEP_STUBS); + private final DbSession dbSession = mock(DbSession.class); + + @Test + void getUuidValues_returnsTheRightLanguageDistribution() { + TelemetryNclocProvider telemetryNclocProvider = new TelemetryNclocProvider(dbClient); + + when(dbClient.openSession(false)).thenReturn(dbSession); + + when(dbClient.metricDao().selectByKeys(dbSession, asList(NCLOC_KEY, NCLOC_LANGUAGE_DISTRIBUTION_KEY))).thenReturn(Arrays.asList( + new MetricDto().setKey(NCLOC_KEY).setUuid("ncloc_uuid"), + new MetricDto().setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY).setUuid("ncloc_distribution_uuid") + )); + + when(dbClient.liveMeasureDao().selectLargestBranchesLocDistribution(dbSession, "ncloc_uuid", "ncloc_distribution_uuid")).thenReturn(Arrays.asList( + new ProjectLocDistributionDto("project1", "branch1-p1", "java=5000;xml=1000;js=1000"), + new ProjectLocDistributionDto("project2", "branch1-p2", "java=10000;csharp=2000"), + new ProjectLocDistributionDto("project3", "branch1-p3", "java=7000;js=500") + )); + + assertEquals(METRIC_KEY, telemetryNclocProvider.getMetricKey()); + assertEquals(Granularity.DAILY, telemetryNclocProvider.getGranularity()); + assertEquals(Dimension.LANGUAGE, telemetryNclocProvider.getDimension()); + + assertThat(telemetryNclocProvider.getUuidValues()).containsOnlyKeys("java", "xml", "csharp", "js"); + assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("java", 22000L); + assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("xml", 1000L); + assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("csharp", 2000L); + assertThat(telemetryNclocProvider.getUuidValues()).containsEntry("js", 1500L); + } +}
\ No newline at end of file |