Search in sources :

Example 1 with LINES_KEY

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");
}
Also used : IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) COMMUNITY(org.sonar.core.platform.EditionProvider.Edition.COMMUNITY) RandomStringUtils.randomAlphanumeric(org.apache.commons.lang.RandomStringUtils.randomAlphanumeric) EsTester(org.sonar.server.es.EsTester) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DatabaseMetaData(java.sql.DatabaseMetaData) Mockito.spy(org.mockito.Mockito.spy) DbSession(org.sonar.db.DbSession) TestSystem2(org.sonar.api.impl.utils.TestSystem2) PULL_REQUEST(org.sonar.db.component.BranchType.PULL_REQUEST) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) SQLException(java.sql.SQLException) PluginInfo(org.sonar.core.platform.PluginInfo) Arrays.asList(java.util.Arrays.asList) ENTERPRISE(org.sonar.core.platform.EditionProvider.Edition.ENTERPRISE) Configuration(org.sonar.api.config.Configuration) InternalProperties(org.sonar.server.property.InternalProperties) Version(org.sonar.updatecenter.common.Version) DbTester(org.sonar.db.DbTester) LINES_KEY(org.sonar.api.measures.CoreMetrics.LINES_KEY) RandomStringUtils.randomAlphabetic(org.apache.commons.lang.RandomStringUtils.randomAlphabetic) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) DockerSupport(org.sonar.server.platform.DockerSupport) MapInternalProperties(org.sonar.server.property.MapInternalProperties) Test(org.junit.Test) UserIndex(org.sonar.server.user.index.UserIndex) Mockito.when(org.mockito.Mockito.when) Assertions.entry(org.assertj.core.api.Assertions.entry) BRANCH(org.sonar.db.component.BranchType.BRANCH) PluginRepository(org.sonar.core.platform.PluginRepository) UserIndexer(org.sonar.server.user.index.UserIndexer) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) COVERAGE_KEY(org.sonar.api.measures.CoreMetrics.COVERAGE_KEY) Optional(java.util.Optional) UNANALYZED_CPP_KEY(org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_CPP_KEY) NCLOC_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_KEY) DEVELOPER(org.sonar.core.platform.EditionProvider.Edition.DEVELOPER) UNANALYZED_C_KEY(org.sonar.server.metric.UnanalyzedLanguageMetrics.UNANALYZED_C_KEY) Mockito.mock(org.mockito.Mockito.mock) MetricDto(org.sonar.db.metric.MetricDto) ComponentDto(org.sonar.db.component.ComponentDto) PluginInfo(org.sonar.core.platform.PluginInfo) Test(org.junit.Test)

Aggregations

DatabaseMetaData (java.sql.DatabaseMetaData)1 SQLException (java.sql.SQLException)1 Arrays.asList (java.util.Arrays.asList)1 List (java.util.List)1 Optional (java.util.Optional)1 IntStream (java.util.stream.IntStream)1 RandomStringUtils.randomAlphabetic (org.apache.commons.lang.RandomStringUtils.randomAlphabetic)1 RandomStringUtils.randomAlphanumeric (org.apache.commons.lang.RandomStringUtils.randomAlphanumeric)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.entry (org.assertj.core.api.Assertions.entry)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.spy (org.mockito.Mockito.spy)1 Mockito.when (org.mockito.Mockito.when)1 Configuration (org.sonar.api.config.Configuration)1 TestSystem2 (org.sonar.api.impl.utils.TestSystem2)1 COVERAGE_KEY (org.sonar.api.measures.CoreMetrics.COVERAGE_KEY)1 LINES_KEY (org.sonar.api.measures.CoreMetrics.LINES_KEY)1 NCLOC_KEY (org.sonar.api.measures.CoreMetrics.NCLOC_KEY)1