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));
}
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));
}
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());
}
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");
}
Aggregations