Search in sources :

Example 1 with SearchProjectsWsResponse

use of org.sonarqube.ws.WsComponents.SearchProjectsWsResponse 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() {
    OrganizationDto organization = db.getDefaultOrganization();
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java"));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java"));
    insertMetrics(COVERAGE, NCLOC_LANGUAGE_DISTRIBUTION_KEY);
    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 : SearchProjectsWsResponse(org.sonarqube.ws.WsComponents.SearchProjectsWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 2 with SearchProjectsWsResponse

use of org.sonarqube.ws.WsComponents.SearchProjectsWsResponse in project sonarqube by SonarSource.

the class SearchProjectsActionTest method return_last_analysis_date.

@Test
public void return_last_analysis_date() {
    OrganizationDto organizationDto = db.organizations().insert();
    ComponentDto project1 = insertProjectInDbAndEs(newProjectDto(organizationDto));
    db.components().insertSnapshot(newAnalysis(project1).setCreatedAt(10_000_000_000L).setLast(false));
    db.components().insertSnapshot(newAnalysis(project1).setCreatedAt(20_000_000_000L).setLast(true));
    ComponentDto project2 = insertProjectInDbAndEs(newProjectDto(organizationDto));
    db.components().insertSnapshot(newAnalysis(project2).setCreatedAt(30_000_000_000L).setLast(true));
    // No snapshot on project 3
    insertProjectInDbAndEs(newProjectDto(organizationDto));
    SearchProjectsWsResponse result = call(request.setAdditionalFields(singletonList("analysisDate")));
    assertThat(result.getComponentsList()).extracting(Component::getAnalysisDate).containsOnly(formatDateTime(new Date(20_000_000_000L)), formatDateTime(new Date(30_000_000_000L)), "");
}
Also used : SearchProjectsWsResponse(org.sonarqube.ws.WsComponents.SearchProjectsWsResponse) ComponentDto(org.sonar.db.component.ComponentDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Date(java.util.Date) Test(org.junit.Test)

Example 3 with SearchProjectsWsResponse

use of org.sonarqube.ws.WsComponents.SearchProjectsWsResponse in project sonarqube by SonarSource.

the class SearchProjectsActionTest method return_languages_facet.

@Test
public void return_languages_facet() {
    OrganizationDto organization = db.getDefaultOrganization();
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java", "xoo"));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java", "xoo"));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("xoo"));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("<null>", "java", "xoo"));
    insertMetrics(COVERAGE, NCLOC_LANGUAGE_DISTRIBUTION_KEY);
    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.getProperty()).isEqualTo(FILTER_LANGUAGES);
    assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsExactly(tuple("xoo", 4L), tuple("java", 3L), tuple("<null>", 2L));
}
Also used : SearchProjectsWsResponse(org.sonarqube.ws.WsComponents.SearchProjectsWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Example 4 with SearchProjectsWsResponse

use of org.sonarqube.ws.WsComponents.SearchProjectsWsResponse in project sonarqube by SonarSource.

the class SearchProjectsActionTest method filter_projects_by_languages.

@Test
public void filter_projects_by_languages() {
    OrganizationDto organizationDto = db.organizations().insertForKey("my-org-key-1");
    insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81d)), null, asList("<null>", "java", "xoo"));
    insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81)), null, asList("java", "xoo"));
    insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("xoo"));
    insertProjectInDbAndEs(newProjectDto(organizationDto).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d)), null, asList("<null>", "java", "xoo"));
    insertMetrics(COVERAGE, NCLOC_LANGUAGE_DISTRIBUTION_KEY);
    request.setFilter("languages IN (java, js, <null>)");
    SearchProjectsWsResponse result = call(request);
    assertThat(result.getComponentsList()).extracting(Component::getName).containsOnly("Sonar Java", "Sonar Groovy", "Sonar Qube");
}
Also used : SearchProjectsWsResponse(org.sonarqube.ws.WsComponents.SearchProjectsWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 5 with SearchProjectsWsResponse

use of org.sonarqube.ws.WsComponents.SearchProjectsWsResponse in project sonarqube by SonarSource.

the class SearchProjectsActionTest method return_nloc_facet.

@Test
public void return_nloc_facet() {
    OrganizationDto organization = db.getDefaultOrganization();
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Java"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Groovy"), newArrayList(newMeasure(COVERAGE, 81), newMeasure(NCLOC, 5d)));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Markdown"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 10_000d)));
    insertProjectInDbAndEs(newProjectDto(organization).setName("Sonar Qube"), newArrayList(newMeasure(COVERAGE, 80d), newMeasure(NCLOC, 500_001d)));
    insertMetrics(COVERAGE, NCLOC);
    SearchProjectsWsResponse result = call(request.setFacets(singletonList(NCLOC)));
    Common.Facet facet = result.getFacets().getFacetsList().stream().filter(oneFacet -> NCLOC.equals(oneFacet.getProperty())).findFirst().orElseThrow(IllegalStateException::new);
    assertThat(facet.getProperty()).isEqualTo(NCLOC);
    assertThat(facet.getValuesCount()).isEqualTo(5);
    assertThat(facet.getValuesList()).extracting(Common.FacetValue::getVal, Common.FacetValue::getCount).containsExactly(tuple("*-1000.0", 2L), tuple("1000.0-10000.0", 0L), tuple("10000.0-100000.0", 1L), tuple("100000.0-500000.0", 0L), tuple("500000.0-*", 1L));
}
Also used : SearchProjectsWsResponse(org.sonarqube.ws.WsComponents.SearchProjectsWsResponse) OrganizationDto(org.sonar.db.organization.OrganizationDto) Common(org.sonarqube.ws.Common) Test(org.junit.Test)

Aggregations

SearchProjectsWsResponse (org.sonarqube.ws.WsComponents.SearchProjectsWsResponse)21 Test (org.junit.Test)20 OrganizationDto (org.sonar.db.organization.OrganizationDto)12 Common (org.sonarqube.ws.Common)6 ComponentDto (org.sonar.db.component.ComponentDto)4 Date (java.util.Date)1