use of org.sonarqube.ws.Components.SearchProjectsWsResponse 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.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method return_leak_period_date.
@Test
public void return_leak_period_date() {
when(editionProviderMock.get()).thenReturn(Optional.of(Edition.ENTERPRISE));
userSession.logIn();
ComponentDto project1 = db.components().insertPublicProject();
db.components().insertSnapshot(project1, snapshot -> snapshot.setPeriodDate(10_000_000_000L));
authorizationIndexerTester.allowOnlyAnyone(project1);
// No leak period
ComponentDto project2 = db.components().insertPublicProject();
db.components().insertSnapshot(project2, snapshot -> snapshot.setPeriodDate(null));
authorizationIndexerTester.allowOnlyAnyone(project2);
// No snapshot on project 3
ComponentDto project3 = db.components().insertPublicProject();
authorizationIndexerTester.allowOnlyAnyone(project3);
MetricDto leakProjects = db.measures().insertMetric(c -> c.setKey(LEAK_PROJECTS_KEY).setValueType(DATA.name()));
ComponentDto application1 = insertApplication(new Measure(leakProjects, c -> c.setData("{\"leakProjects\":[{\"id\": 1, \"leak\":20000000000}, {\"id\": 2, \"leak\":10000000000}]}")));
db.components().insertSnapshot(application1);
authorizationIndexerTester.allowOnlyAnyone(application1);
index();
SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("leakPeriodDate")));
assertThat(result.getComponentsList()).extracting(Component::getKey, Component::hasLeakPeriodDate, Component::getLeakPeriodDate).containsOnly(tuple(project1.getDbKey(), true, formatDateTime(new Date(10_000_000_000L))), tuple(project2.getDbKey(), false, ""), tuple(project3.getDbKey(), false, ""), tuple(application1.getDbKey(), true, formatDateTime(new Date(10_000_000_000L))));
}
use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method return_tags_facet_with_tags_having_no_project_if_tags_is_in_filter.
@Test
public void return_tags_facet_with_tags_having_no_project_if_tags_is_in_filter() {
userSession.logIn();
insertProject(defaults(), p -> p.setTags(asList("finance", "platform")));
insertProject(defaults(), p -> p.setTags(singletonList("offshore")));
insertProject(defaults(), p -> p.setTags(singletonList("offshore")));
index();
SearchProjectsWsResponse result = call(request.setFilter("tags = marketing").setFacets(singletonList(FILTER_TAGS)));
Common.Facet facet = result.getFacets().getFacetsList().stream().filter(oneFacet -> FILTER_TAGS.equals(oneFacet.getProperty())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsExactly(tuple("offshore", 2L), tuple("finance", 1L), tuple("platform", 1L), tuple("marketing", 0L));
}
use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method should_return_projects_only_when_no_edition.
@Test
public void should_return_projects_only_when_no_edition() {
when(editionProviderMock.get()).thenReturn(Optional.empty());
userSession.logIn();
ComponentDto portfolio1 = insertPortfolio();
ComponentDto portfolio2 = insertPortfolio();
insertApplication();
insertApplication();
insertApplication();
ComponentDto project1 = insertProject();
ComponentDto project2 = insertProject();
ComponentDto project3 = insertProject();
index();
SearchProjectsWsResponse result = call(request);
assertThat(result.getComponentsCount()).isEqualTo(3);
assertThat(result.getComponentsList()).extracting(Component::getKey).containsExactly(Stream.of(project1, project2, project3).map(ComponentDto::getDbKey).toArray(String[]::new));
}
use of org.sonarqube.ws.Components.SearchProjectsWsResponse in project sonarqube by SonarSource.
the class SearchProjectsActionTest method return_rating_facet.
@Test
@UseDataProvider("rating_metric_keys")
public void return_rating_facet(String ratingMetricKey) {
userSession.logIn();
MetricDto ratingMetric = db.measures().insertMetric(c -> c.setKey(ratingMetricKey).setValueType("RATING"));
insertProject(new Measure(ratingMetric, c -> c.setValue(1d)));
insertProject(new Measure(ratingMetric, c -> c.setValue(1d)));
insertProject(new Measure(ratingMetric, c -> c.setValue(3d)));
insertProject(new Measure(ratingMetric, c -> c.setValue(5d)));
index();
SearchProjectsWsResponse result = call(request.setFacets(singletonList(ratingMetricKey)));
Common.Facet facet = result.getFacets().getFacetsList().stream().filter(oneFacet -> ratingMetricKey.equals(oneFacet.getProperty())).findFirst().orElseThrow(IllegalStateException::new);
assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsExactly(tuple("1", 2L), tuple("2", 0L), tuple("3", 1L), tuple("4", 0L), tuple("5", 1L));
}
Aggregations