From b128adde3ba0a0b20189f90fde15d94490c7de52 Mon Sep 17 00:00:00 2001 From: Alain Kermis Date: Wed, 17 Jul 2024 14:48:57 +0200 Subject: SONAR-22479 Create telemetry-core module --- .../ProjectCppAutoconfigTelemetryProviderIT.java | 136 +++++++++++++++++++++ .../telemetry/TelemetryUserEnabledProviderIT.java | 95 ++++++++++++++ .../platform/platformlevel/PlatformLevel4.java | 4 +- .../ProjectCppAutoconfigTelemetryProvider.java | 97 +++++++++++++++ .../platform/telemetry/TelemetryNclocProvider.java | 8 +- .../telemetry/TelemetryUserEnabledProvider.java | 81 ++++++++++++ .../telemetry/TelemetryVersionProvider.java | 8 +- .../ProjectCppAutoconfigTelemetryProviderTest.java | 42 +++++++ .../telemetry/TelemetryNclocProviderTest.java | 4 +- .../TelemetryUserEnabledProviderTest.java | 44 +++++++ .../telemetry/TelemetryVersionProviderTest.java | 6 +- 11 files changed, 510 insertions(+), 15 deletions(-) create mode 100644 server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java create mode 100644 server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java create mode 100644 server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java create mode 100644 server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java create mode 100644 server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java create mode 100644 server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderTest.java (limited to 'server/sonar-webserver') diff --git a/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java new file mode 100644 index 00000000000..ee6c1f578e9 --- /dev/null +++ b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderIT.java @@ -0,0 +1,136 @@ +/* + * 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.server.platform.telemetry; + +import java.util.Map; +import java.util.function.Consumer; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; +import org.sonar.db.component.ComponentDto; +import org.sonar.db.component.ProjectData; +import org.sonar.db.measure.LiveMeasureDto; +import org.sonar.db.metric.MetricDto; +import org.sonar.db.project.ProjectDto; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY; +import static org.sonar.api.measures.Metric.ValueType.STRING; + +class ProjectCppAutoconfigTelemetryProviderIT { + + private final System2 system2 = new AlwaysIncreasingSystem2(1000L); + + @RegisterExtension + public final DbTester db = DbTester.create(system2); + + ProjectCppAutoconfigTelemetryProvider underTest = new ProjectCppAutoconfigTelemetryProvider(db.getDbClient()); + + @Test + void getUuidValues_whenNoProjects_returnEmptyList() { + assertThat(underTest.getUuidValues()).isEmpty(); + } + + @Test + void getUuidValues_whenNoCppAndCProjects_returnEmptyMap() { + Consumer configureMetric = metric -> metric + .setValueType(STRING.name()) + .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY); + + MetricDto metric = db.measures().insertMetric(configureMetric); + + ProjectData project1 = db.components().insertPrivateProject(); + ProjectData project2 = db.components().insertPrivateProject(); + + insertLiveMeasure("java", metric).accept(project1); + insertLiveMeasure("cobol", metric).accept(project2); + + + assertThat(underTest.getUuidValues()).isEmpty(); + } + + @Test + void getUuidValues_when1CppAnd1CProject_returnMapWithSize2AndAutoconfigByDefault() { + Consumer configureMetric = metric -> metric + .setValueType(STRING.name()) + .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY); + + MetricDto metric = db.measures().insertMetric(configureMetric); + + ProjectData project1 = db.components().insertPrivateProject(); + ProjectData project2 = db.components().insertPrivateProject(); + ProjectData project3 = db.components().insertPrivateProject(); + ProjectData project4 = db.components().insertPrivateProject(); + + insertLiveMeasure("c", metric).accept(project1); + insertLiveMeasure("cpp", metric).accept(project2); + insertLiveMeasure("java", metric).accept(project3); + insertLiveMeasure("cobol", metric).accept(project4); + + Map actualResult = underTest.getUuidValues(); + + assertThat(actualResult).hasSize(2); + assertThat(actualResult).containsExactlyInAnyOrderEntriesOf(Map.of(project1.getProjectDto().getUuid(), "AUTOCONFIG", + project2.getProjectDto().getUuid(), "AUTOCONFIG")); + } + + @Test + void getUuidValues_whenCAndCppProjectsWithDifferentConfig_returnMapWithSize2AndNotAutoconfig() { + Consumer configureMetric = metric -> metric + .setValueType(STRING.name()) + .setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY); + + MetricDto metric = db.measures().insertMetric(configureMetric); + + ProjectData project1 = db.components().insertPrivateProject(); + ProjectData project2 = db.components().insertPrivateProject(); + ProjectData project3 = db.components().insertPrivateProject(); + ProjectData project4 = db.components().insertPrivateProject(); + + insertLiveMeasure("c", metric).accept(project1); + insertLiveMeasure("cpp", metric).accept(project2); + insertLiveMeasure("java", metric).accept(project3); + insertLiveMeasure("cobol", metric).accept(project4); + + db.properties().insertProperty("sonar.cfamily.build-wrapper-output", "anyvalue", project1.getProjectDto().getUuid()); + db.properties().insertProperty("sonar.cfamily.compile-commands", "anyvalue", project2.getProjectDto().getUuid()); + + Map actualResult = underTest.getUuidValues(); + + assertThat(actualResult).hasSize(2); + assertThat(actualResult).containsExactlyInAnyOrderEntriesOf(Map.of(project1.getProjectDto().getUuid(), "BW_DEPRECATED", + project2.getProjectDto().getUuid(), "COMPDB")); + } + + private Consumer configureLiveMeasure(String language, MetricDto metric, ProjectDto project, ComponentDto componentDto) { + return liveMeasure -> liveMeasure + .setMetricUuid(metric.getUuid()) + .setComponentUuid(componentDto.uuid()) + .setProjectUuid(project.getUuid()) + .setData(language + "=" + 100); + } + + private Consumer insertLiveMeasure(String language, MetricDto metric) { + return projectData -> db.measures().insertLiveMeasure(projectData.getMainBranchComponent(), metric, + configureLiveMeasure(language, metric, projectData.getProjectDto(), projectData.getMainBranchComponent())); + } +} diff --git a/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java new file mode 100644 index 00000000000..f0466dac7a8 --- /dev/null +++ b/server/sonar-webserver/src/it/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderIT.java @@ -0,0 +1,95 @@ +/* + * 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.server.platform.telemetry; + +import java.util.Map; +import org.junit.Rule; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.sonar.api.impl.utils.AlwaysIncreasingSystem2; +import org.sonar.api.utils.System2; +import org.sonar.db.DbTester; +import org.sonar.db.user.UserDto; +import org.sonar.server.util.DigestUtil; + +import static org.assertj.core.api.Assertions.assertThat; + +class TelemetryUserEnabledProviderIT { + + private final System2 system2 = new AlwaysIncreasingSystem2(); + + @Rule + public final DbTester db = DbTester.create(system2); + + + private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(db.getDbClient()); + + @BeforeEach + public void beforeEach() { + db.executeUpdateSql("delete from users"); + } + + @Test + void getUuidValues_whenNoUsersInDatabase_shouldReturnEmptyMap() { + Map uuidValues = underTest.getUuidValues(); + + assertThat(uuidValues).isEmpty(); + } + + @Test + void getUuidValues_whenSomeUsersActive_shouldReturnBothBooleanValues() { + db.users().insertUser(user -> user.setUuid("uuid1").setActive(true)); + db.users().insertUser(user -> user.setUuid("uuid1").setActive(false)); + db.getSession().commit(); + + Map uuidValues = underTest.getUuidValues(); + + assertThat(uuidValues).hasSize(2); + assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(1); + assertThat(uuidValues.values().stream().filter(b -> !b)).hasSize(1); + } + + @Test + void getUuidValues_when10ActiveUsers_shouldReturn10BooleanValues() { + for (int i = 0; i < 10; i++) { + db.users().insertUser(user -> user.setActive(true)); + } + db.getSession().commit(); + + Map uuidValues = underTest.getUuidValues(); + + assertThat(uuidValues).hasSize(10); + assertThat(uuidValues.values().stream().filter(Boolean::booleanValue)).hasSize(10); + } + + @Test + void getUuidValues_shouldAnonymizeUserUuids() { + UserDto userDto1 = db.users().insertUser(); + UserDto userDto2 = db.users().insertUser(); + db.getSession().commit(); + + Map uuidValues = underTest.getUuidValues(); + + String anonymizedUser1 = DigestUtil.sha3_224Hex(userDto1.getUuid()); + String anonymizedUser2 = DigestUtil.sha3_224Hex(userDto2.getUuid()); + assertThat(uuidValues.keySet()).containsExactlyInAnyOrder(anonymizedUser1, anonymizedUser2); + } + +} diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java index aa63a07edd1..da7ff01ea80 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java @@ -184,7 +184,9 @@ import org.sonar.server.platform.PersistentSettings; import org.sonar.server.platform.SystemInfoWriterModule; import org.sonar.server.platform.WebCoreExtensionsInstaller; import org.sonar.server.platform.db.CheckAnyonePermissionsAtStartup; +import org.sonar.server.platform.telemetry.ProjectCppAutoconfigTelemetryProvider; import org.sonar.server.platform.telemetry.TelemetryNclocProvider; +import org.sonar.server.platform.telemetry.TelemetryUserEnabledProvider; import org.sonar.server.platform.telemetry.TelemetryVersionProvider; import org.sonar.server.platform.web.ActionDeprecationLoggerInterceptor; import org.sonar.server.platform.web.SonarLintConnectionFilter; @@ -290,8 +292,6 @@ import org.sonar.telemetry.legacy.QualityProfileDataProvider; import org.sonar.telemetry.legacy.TelemetryDataJsonWriter; import org.sonar.telemetry.legacy.TelemetryDataLoaderImpl; import org.sonar.telemetry.metrics.TelemetryMetricsLoader; -import org.sonar.telemetry.project.ProjectCppAutoconfigTelemetryProvider; -import org.sonar.telemetry.user.TelemetryUserEnabledProvider; import static org.sonar.core.extension.CoreExtensionsInstaller.noAdditionalSideFilter; import static org.sonar.core.extension.PlatformLevelPredicates.hasPlatformLevel4OrNone; diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java new file mode 100644 index 00000000000..6473c1238e2 --- /dev/null +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProvider.java @@ -0,0 +1,97 @@ +/* + * 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.server.platform.telemetry; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.project.ProjectDto; +import org.sonar.db.property.PropertyDto; +import org.sonar.db.property.PropertyQuery; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataProvider; +import org.sonar.telemetry.core.TelemetryDataType; + +public class ProjectCppAutoconfigTelemetryProvider implements TelemetryDataProvider { + + private final DbClient dbClient; + + public ProjectCppAutoconfigTelemetryProvider(DbClient dbClient) { + this.dbClient = dbClient; + } + + @Override + public String getMetricKey() { + return "project_cpp_config_type"; + } + + @Override + public Dimension getDimension() { + return Dimension.PROJECT; + } + + @Override + public Granularity getGranularity() { + return Granularity.WEEKLY; + } + + @Override + public TelemetryDataType getType() { + return TelemetryDataType.STRING; + } + + @Override + public Map getUuidValues() { + Map cppConfigTypePerProjectUuid = new HashMap<>(); + try (DbSession dbSession = dbClient.openSession(true)) { + //TODO in the feature ideally languages should be defined in the codebase as enums, using strings is error-prone + List cppProjects = dbClient.projectDao().selectProjectsByLanguage(dbSession, Set.of("cpp", "c")); + for (ProjectDto cppProject : cppProjects) { + CppConfigType cppConfigType = getCppConfigType(cppProject, dbSession); + cppConfigTypePerProjectUuid.put(cppProject.getUuid(), cppConfigType.name()); + } + } + return cppConfigTypePerProjectUuid; + } + + private CppConfigType getCppConfigType(ProjectDto project, DbSession dbSession) { + List propertyDtos = dbClient.propertiesDao().selectByQuery(PropertyQuery + .builder() + .setEntityUuid(project.getUuid()) + .build(), dbSession); + for (PropertyDto propertyDto : propertyDtos) { + if (propertyDto.getKey().equals("sonar.cfamily.build-wrapper-output")) { + return CppConfigType.BW_DEPRECATED; + } + if (propertyDto.getKey().equals("sonar.cfamily.compile-commands")) { + return CppConfigType.COMPDB; + } + } + return CppConfigType.AUTOCONFIG; + } + + enum CppConfigType { + BW_DEPRECATED, COMPDB, AUTOCONFIG + } +} diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java index 5e3fa11b544..81f683cb96a 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryNclocProvider.java @@ -27,10 +27,10 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.measure.ProjectLocDistributionDto; import org.sonar.db.metric.MetricDto; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataProvider; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataProvider; +import org.sonar.telemetry.core.TelemetryDataType; import static java.util.Arrays.asList; import static java.util.stream.Collectors.toMap; diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java new file mode 100644 index 00000000000..fa3aff0b38e --- /dev/null +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProvider.java @@ -0,0 +1,81 @@ +/* + * 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.server.platform.telemetry; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.sonar.db.DbClient; +import org.sonar.db.DbSession; +import org.sonar.db.user.UserDto; +import org.sonar.db.user.UserQuery; +import org.sonar.server.util.DigestUtil; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataProvider; +import org.sonar.telemetry.core.TelemetryDataType; + +public class TelemetryUserEnabledProvider implements TelemetryDataProvider { + + private final DbClient dbClient; + + public TelemetryUserEnabledProvider(DbClient dbClient) { + this.dbClient = dbClient; + } + + @Override + public String getMetricKey() { + return "user_enabled"; + } + + @Override + public Dimension getDimension() { + return Dimension.USER; + } + + @Override + public Granularity getGranularity() { + return Granularity.DAILY; + } + + @Override + public TelemetryDataType getType() { + return TelemetryDataType.BOOLEAN; + } + + @Override + public Map getUuidValues() { + Map result = new HashMap<>(); + int pageSize = 1000; + int page = 1; + try (DbSession dbSession = dbClient.openSession(false)) { + List userDtos; + do { + userDtos = dbClient.userDao().selectUsers(dbSession, UserQuery.builder().build(), page, pageSize); + for (UserDto userDto : userDtos) { + String anonymizedUuid = DigestUtil.sha3_224Hex(userDto.getUuid()); + result.put(anonymizedUuid, userDto.isActive()); + } + page++; + } while (!userDtos.isEmpty()); + } + return result; + } +} diff --git a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java index d76962b7cea..850190948ba 100644 --- a/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java +++ b/server/sonar-webserver/src/main/java/org/sonar/server/platform/telemetry/TelemetryVersionProvider.java @@ -20,10 +20,10 @@ package org.sonar.server.platform.telemetry; import org.sonar.api.platform.Server; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataProvider; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataProvider; +import org.sonar.telemetry.core.TelemetryDataType; public class TelemetryVersionProvider implements TelemetryDataProvider { diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java new file mode 100644 index 00000000000..295d03b07b1 --- /dev/null +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/ProjectCppAutoconfigTelemetryProviderTest.java @@ -0,0 +1,42 @@ +/* + * 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.server.platform.telemetry; + +import org.junit.jupiter.api.Test; +import org.sonar.db.DbClient; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +class ProjectCppAutoconfigTelemetryProviderTest { + + @Test + void testGetters() { + ProjectCppAutoconfigTelemetryProvider provider = new ProjectCppAutoconfigTelemetryProvider(mock(DbClient.class)); + + assertEquals("project_cpp_config_type", provider.getMetricKey()); + assertEquals(Dimension.PROJECT, provider.getDimension()); + assertEquals(Granularity.WEEKLY, provider.getGranularity()); + assertEquals(TelemetryDataType.STRING, provider.getType()); + } +} diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java index 7c9752a8088..6bfd81a6e91 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryNclocProviderTest.java @@ -26,8 +26,8 @@ import org.sonar.db.DbClient; import org.sonar.db.DbSession; import org.sonar.db.measure.ProjectLocDistributionDto; import org.sonar.db.metric.MetricDto; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderTest.java new file mode 100644 index 00000000000..d8b2e91f52b --- /dev/null +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryUserEnabledProviderTest.java @@ -0,0 +1,44 @@ +/* + * 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.server.platform.telemetry; + +import org.junit.jupiter.api.Test; +import org.sonar.db.DbClient; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; + +class TelemetryUserEnabledProviderTest { + + private final DbClient dbClient = mock(DbClient.class); + + private final TelemetryUserEnabledProvider underTest = new TelemetryUserEnabledProvider(dbClient); + + @Test + void testGetters() { + assertThat(underTest.getDimension()).isEqualTo(Dimension.USER); + assertThat(underTest.getGranularity()).isEqualTo(Granularity.DAILY); + assertThat(underTest.getMetricKey()).isEqualTo("user_enabled"); + assertThat(underTest.getType()).isEqualTo(TelemetryDataType.BOOLEAN); + } +} diff --git a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java index d5ea987eb6d..1a14d52bbf3 100644 --- a/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java +++ b/server/sonar-webserver/src/test/java/org/sonar/server/platform/telemetry/TelemetryVersionProviderTest.java @@ -21,9 +21,9 @@ package org.sonar.server.platform.telemetry; import org.junit.jupiter.api.Test; import org.sonar.api.platform.Server; -import org.sonar.telemetry.Dimension; -import org.sonar.telemetry.Granularity; -import org.sonar.telemetry.TelemetryDataType; +import org.sonar.telemetry.core.Dimension; +import org.sonar.telemetry.core.Granularity; +import org.sonar.telemetry.core.TelemetryDataType; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -- cgit v1.2.3