Search in sources :

Example 1 with NCLOC_LANGUAGE_DISTRIBUTION_KEY

use of org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY in project sonarqube by SonarSource.

the class SearchProjectsActionTest method return_languages_facet_with_language_having_no_project_if_language_is_in_filter.

@Test
public void return_languages_facet_with_language_having_no_project_if_language_is_in_filter() {
    userSession.logIn();
    MetricDto languagesDistribution = db.measures().insertMetric(c -> c.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY).setValueType("DATA"));
    insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=2;java=6")));
    insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("java=5")));
    index();
    SearchProjectsWsResponse result = call(request.setFilter("languages = xoo").setFacets(singletonList(FILTER_LANGUAGES)));
    Common.Facet facet = result.getFacets().getFacetsList().stream().filter(oneFacet -> FILTER_LANGUAGES.equals(oneFacet.getProperty())).findFirst().orElseThrow(IllegalStateException::new);
    assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsOnly(tuple("xoo", 0L), tuple("java", 2L), tuple("<null>", 1L));
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 2 with NCLOC_LANGUAGE_DISTRIBUTION_KEY

use of org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY in project sonarqube by SonarSource.

the class SearchProjectsActionTest method return_languages_facet.

@Test
public void return_languages_facet() {
    userSession.logIn();
    MetricDto languagesDistribution = db.measures().insertMetric(c -> c.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY).setValueType("DATA"));
    insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=2;java=6;xoo=18")));
    insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("java=5;xoo=19")));
    insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("xoo=1")));
    insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=1;java=3;xoo=8")));
    index();
    SearchProjectsWsResponse result = call(request.setFacets(singletonList(FILTER_LANGUAGES)));
    Common.Facet facet = result.getFacets().getFacetsList().stream().filter(oneFacet -> FILTER_LANGUAGES.equals(oneFacet.getProperty())).findFirst().orElseThrow(IllegalStateException::new);
    assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsExactly(tuple("xoo", 4L), tuple("java", 3L), tuple("<null>", 2L));
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 3 with NCLOC_LANGUAGE_DISTRIBUTION_KEY

use of org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY in project sonarqube by SonarSource.

the class SearchProjectsActionTest method filter_projects_by_languages.

@Test
public void filter_projects_by_languages() {
    userSession.logIn();
    MetricDto languagesDistribution = db.measures().insertMetric(c -> c.setKey(NCLOC_LANGUAGE_DISTRIBUTION_KEY).setValueType("DATA"));
    ComponentDto project1 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=2;java=6;xoo=18")));
    ComponentDto project2 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("java=3;xoo=9")));
    ComponentDto project3 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("xoo=1")));
    ComponentDto project4 = insertProject(new Measure(languagesDistribution, c -> c.setValue(null).setData("<null>=1;java=5;xoo=13")));
    index();
    SearchProjectsWsResponse result = call(request.setFilter("languages IN (java, js, <null>)"));
    assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactlyInAnyOrder(project1.getDbKey(), project2.getDbKey(), project4.getDbKey());
}
Also used : FACETS(org.sonar.api.server.ws.WebService.Param.FACETS) Arrays(java.util.Arrays) PermissionIndexerTester(org.sonar.server.permission.index.PermissionIndexerTester) SORT(org.sonar.api.server.ws.WebService.Param.SORT) Date(java.util.Date) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) DataProviderRunner(com.tngtech.java.junit.dataprovider.DataProviderRunner) DbSession(org.sonar.db.DbSession) RequestBuilder(org.sonar.server.component.ws.SearchProjectsAction.RequestBuilder) Collections.singletonList(java.util.Collections.singletonList) NEW_SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_SECURITY_RATING_KEY) PAGE(org.sonar.api.server.ws.WebService.Param.PAGE) Param(org.sonar.api.server.ws.WebService.Param) WebService(org.sonar.api.server.ws.WebService) ProjectsInWarning(org.sonar.server.qualitygate.ProjectsInWarning) Arrays.asList(java.util.Arrays.asList) NEW_MAINTAINABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_MAINTAINABILITY_RATING_KEY) PARAM_FILTER(org.sonarqube.ws.client.component.ComponentsWsParameters.PARAM_FILTER) DateUtils.formatDateTime(org.sonar.api.utils.DateUtils.formatDateTime) FILTER_LANGUAGES(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_LANGUAGES) RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.RELIABILITY_RATING_KEY) MoreCollectors.toList(org.sonar.core.util.stream.MoreCollectors.toList) DbTester(org.sonar.db.DbTester) System2(org.sonar.api.utils.System2) Set(java.util.Set) NEW_DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.NEW_DUPLICATED_LINES_DENSITY_KEY) LEVEL(org.sonar.api.measures.Metric.ValueType.LEVEL) FILTER_QUALIFIER(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_QUALIFIER) Common(org.sonarqube.ws.Common) DbClient(org.sonar.db.DbClient) NEW_RELIABILITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.NEW_RELIABILITY_RATING_KEY) List(java.util.List) ComponentDto(org.sonar.db.component.ComponentDto) ALERT_STATUS_KEY(org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY) Stream(java.util.stream.Stream) SQALE_RATING_KEY(org.sonar.api.measures.CoreMetrics.SQALE_RATING_KEY) ProjectDto(org.sonar.db.project.ProjectDto) Optional(java.util.Optional) PAGE_SIZE(org.sonar.api.server.ws.WebService.Param.PAGE_SIZE) FIELDS(org.sonar.api.server.ws.WebService.Param.FIELDS) PropertyDto(org.sonar.db.property.PropertyDto) Component(org.sonarqube.ws.Components.Component) Joiner(com.google.common.base.Joiner) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) NCLOC_LANGUAGE_DISTRIBUTION_KEY(org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY) EsTester(org.sonar.server.es.EsTester) RunWith(org.junit.runner.RunWith) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) ProjectMeasuresIndexer(org.sonar.server.measure.index.ProjectMeasuresIndexer) HashSet(java.util.HashSet) ProjectMeasuresIndex(org.sonar.server.measure.index.ProjectMeasuresIndex) WebAuthorizationTypeSupport(org.sonar.server.permission.index.WebAuthorizationTypeSupport) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) SearchProjectsRequest(org.sonar.server.component.ws.SearchProjectsAction.SearchProjectsRequest) DATA(org.sonar.api.measures.Metric.ValueType.DATA) Nullable(javax.annotation.Nullable) Before(org.junit.Before) UserSessionRule(org.sonar.server.tester.UserSessionRule) SECURITY_RATING_KEY(org.sonar.api.measures.CoreMetrics.SECURITY_RATING_KEY) NEW_LINES_KEY(org.sonar.api.measures.CoreMetrics.NEW_LINES_KEY) Assertions.tuple(org.assertj.core.api.Assertions.tuple) PlatformEditionProvider(org.sonar.core.platform.PlatformEditionProvider) Optional.ofNullable(java.util.Optional.ofNullable) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider) DUPLICATED_LINES_DENSITY_KEY(org.sonar.api.measures.CoreMetrics.DUPLICATED_LINES_DENSITY_KEY) TestRequest(org.sonar.server.ws.TestRequest) JsonAssert.assertJson(org.sonar.test.JsonAssert.assertJson) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) WsActionTester(org.sonar.server.ws.WsActionTester) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) Consumer(java.util.function.Consumer) Rule(org.junit.Rule) MetricDto(org.sonar.db.metric.MetricDto) Qualifiers(org.sonar.api.resources.Qualifiers) Edition(org.sonar.core.platform.EditionProvider.Edition) LiveMeasureDto(org.sonar.db.measure.LiveMeasureDto) INT(org.sonar.api.measures.Metric.ValueType.INT) IssueIndexSyncProgressChecker(org.sonar.server.issue.index.IssueIndexSyncProgressChecker) ASCENDING(org.sonar.api.server.ws.WebService.Param.ASCENDING) KEY_PROJECT_EXAMPLE_002(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_002) KEY_PROJECT_EXAMPLE_001(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_001) KEY_PROJECT_EXAMPLE_003(org.sonar.server.ws.KeyExamples.KEY_PROJECT_EXAMPLE_003) FILTER_TAGS(org.sonarqube.ws.client.project.ProjectsWsParameters.FILTER_TAGS) Metric(org.sonar.api.measures.Metric) MetricDto(org.sonar.db.metric.MetricDto) SearchProjectsWsResponse(org.sonarqube.ws.Components.SearchProjectsWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with NCLOC_LANGUAGE_DISTRIBUTION_KEY

use of org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_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

Arrays.asList (java.util.Arrays.asList)4 List (java.util.List)4 Optional (java.util.Optional)4 IntStream (java.util.stream.IntStream)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Rule (org.junit.Rule)4 Test (org.junit.Test)4 Mockito.mock (org.mockito.Mockito.mock)4 Mockito.when (org.mockito.Mockito.when)4 NCLOC_LANGUAGE_DISTRIBUTION_KEY (org.sonar.api.measures.CoreMetrics.NCLOC_LANGUAGE_DISTRIBUTION_KEY)4 Joiner (com.google.common.base.Joiner)3 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)3 DataProviderRunner (com.tngtech.java.junit.dataprovider.DataProviderRunner)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)3 Arrays (java.util.Arrays)3 Collections.singletonList (java.util.Collections.singletonList)3 Date (java.util.Date)3 HashSet (java.util.HashSet)3 Optional.ofNullable (java.util.Optional.ofNullable)3 Set (java.util.Set)3