use of org.sonar.api.measures.CoreMetrics.LINES_KEY in project sonarqube by SonarSource.
the class TelemetryDataLoaderImplTest method send_telemetry_data.
@Test
public void send_telemetry_data() {
String serverId = "AU-TpxcB-iU5OvuD2FL7";
String version = "7.5.4";
server.setId(serverId);
server.setVersion(version);
List<PluginInfo> plugins = asList(newPlugin("java", "4.12.0.11033"), newPlugin("scmgit", "1.2"), new PluginInfo("other"));
when(pluginRepository.getPluginInfos()).thenReturn(plugins);
when(editionProvider.get()).thenReturn(Optional.of(DEVELOPER));
int userCount = 3;
IntStream.range(0, userCount).forEach(i -> db.users().insertUser(u -> u.setExternalIdentityProvider("provider" + i)));
db.users().insertUser(u -> u.setActive(false).setExternalIdentityProvider("provider0"));
userIndexer.indexAll();
MetricDto lines = db.measures().insertMetric(m -> m.setKey(LINES_KEY));
MetricDto ncloc = db.measures().insertMetric(m -> m.setKey(NCLOC_KEY));
MetricDto coverage = db.measures().insertMetric(m -> m.setKey(COVERAGE_KEY));
MetricDto nclocDistrib = db.measures().insertMetric(m -> m.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY));
ComponentDto project1 = db.components().insertPublicProject();
ComponentDto project1Branch = db.components().insertProjectBranch(project1);
db.measures().insertLiveMeasure(project1, lines, m -> m.setValue(200d));
db.measures().insertLiveMeasure(project1, ncloc, m -> m.setValue(100d));
db.measures().insertLiveMeasure(project1, coverage, m -> m.setValue(80d));
db.measures().insertLiveMeasure(project1, nclocDistrib, m -> m.setValue(null).setData("java=200;js=50"));
ComponentDto project2 = db.components().insertPublicProject();
db.measures().insertLiveMeasure(project2, lines, m -> m.setValue(300d));
db.measures().insertLiveMeasure(project2, ncloc, m -> m.setValue(200d));
db.measures().insertLiveMeasure(project2, coverage, m -> m.setValue(80d));
db.measures().insertLiveMeasure(project2, nclocDistrib, m -> m.setValue(null).setData("java=300;kotlin=2500"));
projectMeasuresIndexer.indexAll();
// alm
db.almSettings().insertAzureAlmSetting();
db.almSettings().insertAzureAlmSetting(a -> a.setUrl("https://dev.azure.com"));
db.almSettings().insertBitbucketAlmSetting();
db.almSettings().insertBitbucketCloudAlmSetting();
db.almSettings().insertGitHubAlmSetting();
db.almSettings().insertGitHubAlmSetting(a -> a.setUrl("https://api.github.com"));
db.almSettings().insertGitlabAlmSetting();
db.almSettings().insertGitlabAlmSetting(a -> a.setUrl("https://gitlab.com/api/v4"));
TelemetryData data = communityUnderTest.load();
assertThat(data.getServerId()).isEqualTo(serverId);
assertThat(data.getVersion()).isEqualTo(version);
assertThat(data.getEdition()).contains(DEVELOPER);
assertDatabaseMetadata(data.getDatabase());
assertThat(data.getPlugins()).containsOnly(entry("java", "4.12.0.11033"), entry("scmgit", "1.2"), entry("other", "undefined"));
assertThat(data.getUserCount()).isEqualTo(userCount);
assertThat(data.getProjectCount()).isEqualTo(2L);
assertThat(data.getNcloc()).isEqualTo(300L);
assertThat(data.getProjectCountByLanguage()).containsOnly(entry("java", 2L), entry("kotlin", 1L), entry("js", 1L));
assertThat(data.getNclocByLanguage()).containsOnly(entry("java", 500L), entry("kotlin", 2500L), entry("js", 50L));
assertThat(data.isInDocker()).isFalse();
assertThat(data.getAlmIntegrationCountByAlm()).containsEntry("azure_devops_server", 1L).containsEntry("azure_devops_cloud", 1L).containsEntry("bitbucket_server", 1L).containsEntry("bitbucket_cloud", 1L).containsEntry("gitlab_server", 1L).containsEntry("gitlab_cloud", 1L).containsEntry("github_cloud", 1L).containsEntry("github_server", 1L);
assertThat(data.getExternalAuthenticationProviders()).containsExactlyInAnyOrder("provider0", "provider1", "provider2");
}
Aggregations