Search in sources :

Example 41 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_quality_gate_is_sticky.

@Test
public void facet_quality_gate_is_sticky() {
    index(// 2 docs with QG OK
    newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGateStatus(OK.name()), newDoc(NCLOC, 10d, COVERAGE, 0d).setQualityGateStatus(OK.name()), // 3 docs with QG WARN
    newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()), newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()), newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(WARN.name()), // 4 docs with QG ERROR
    newDoc(NCLOC, 100d, COVERAGE, 0d).setQualityGateStatus(ERROR.name()), newDoc(NCLOC, 5000d, COVERAGE, 40d).setQualityGateStatus(ERROR.name()), newDoc(NCLOC, 12000d, COVERAGE, 50d).setQualityGateStatus(ERROR.name()), newDoc(NCLOC, 13000d, COVERAGE, 60d).setQualityGateStatus(ERROR.name()));
    Facets facets = underTest.search(new ProjectMeasuresQuery().setQualityGateStatus(ERROR).addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 55d)), new SearchOptions().addFacets(ALERT_STATUS_KEY, NCLOC)).getFacets();
    // Sticky facet on quality gate does not take into account quality gate filter
    assertThat(facets.get(ALERT_STATUS_KEY)).containsOnly(entry(OK.name(), 2L), entry(WARN.name(), 3L), entry(ERROR.name(), 3L));
    // But facet on ncloc does well take into into filters
    assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 1L), entry("1000.0-10000.0", 1L), entry("10000.0-100000.0", 1L), entry("100000.0-500000.0", 0L), entry("500000.0-*", 0L));
}
Also used : MetricCriterion(org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion) Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 42 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_languages_is_limited_to_10_languages.

@Test
public void facet_languages_is_limited_to_10_languages() {
    index(newDoc().setLanguages(asList("<null>", "java", "xoo", "css", "cpp")), newDoc().setLanguages(asList("xml", "php", "python", "perl", "ruby")), newDoc().setLanguages(asList("js", "scala")));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(LANGUAGES)).getFacets();
    assertThat(facets.get(LANGUAGES)).hasSize(10);
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 43 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_coverage_contains_only_projects_authorized_for_user.

@Test
public void facet_coverage_contains_only_projects_authorized_for_user() throws Exception {
    // User can see these projects
    indexForUser(USER1, // docs with coverage<30%
    newDoc(COVERAGE, 0d), newDoc(COVERAGE, 0d), newDoc(COVERAGE, 29d), // docs with coverage>=30% and coverage<50%
    newDoc(COVERAGE, 30d), newDoc(COVERAGE, 49d));
    // User cannot see these projects
    indexForUser(USER2, // docs with coverage>=50% and coverage<70%
    newDoc(COVERAGE, 50d), // docs with coverage>=70% and coverage<80%
    newDoc(COVERAGE, 70d), // docs with coverage>= 80%
    newDoc(COVERAGE, 80d));
    userSession.logIn(USER1);
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(COVERAGE)).getFacets();
    assertThat(facets.get(COVERAGE)).containsExactly(entry("*-30.0", 3L), entry("30.0-50.0", 2L), entry("50.0-70.0", 0L), entry("70.0-80.0", 0L), entry("80.0-*", 0L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 44 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_languages_is_sticky.

@Test
public void facet_languages_is_sticky() {
    index(newDoc(NCLOC, 10d).setLanguages(singletonList("java")), newDoc(NCLOC, 10d).setLanguages(singletonList("java")), newDoc(NCLOC, 10d).setLanguages(singletonList("xoo")), newDoc(NCLOC, 100d).setLanguages(singletonList("xml")), newDoc(NCLOC, 100d).setLanguages(asList("<null>", "java")), newDoc(NCLOC, 5000d).setLanguages(asList("<null>", "java", "xoo")));
    Facets facets = underTest.search(new ProjectMeasuresQuery().setLanguages(ImmutableSet.of("java")), new SearchOptions().addFacets(LANGUAGES, NCLOC)).getFacets();
    // Sticky facet on language does not take into account language filter
    assertThat(facets.get(LANGUAGES)).containsOnly(entry("<null>", 2L), entry("java", 4L), entry("xoo", 2L), entry("xml", 1L));
    // But facet on ncloc does well take account into filters
    assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 3L), entry("1000.0-10000.0", 1L), entry("10000.0-100000.0", 0L), entry("100000.0-500000.0", 0L), entry("500000.0-*", 0L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 45 with SearchOptions

use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.

the class ProjectMeasuresIndexTest method facet_reliability_rating.

@Test
public void facet_reliability_rating() {
    index(// 3 docs with rating A
    newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), newDoc(RELIABILITY_RATING, 1d), // 2 docs with rating B
    newDoc(RELIABILITY_RATING, 2d), newDoc(RELIABILITY_RATING, 2d), // 4 docs with rating C
    newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), newDoc(RELIABILITY_RATING, 3d), // 2 docs with rating D
    newDoc(RELIABILITY_RATING, 4d), newDoc(RELIABILITY_RATING, 4d), // 5 docs with rating E
    newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d), newDoc(RELIABILITY_RATING, 5d));
    Facets facets = underTest.search(new ProjectMeasuresQuery(), new SearchOptions().addFacets(RELIABILITY_RATING)).getFacets();
    assertThat(facets.get(RELIABILITY_RATING)).containsExactly(entry("1", 3L), entry("2", 2L), entry("3", 4L), entry("4", 2L), entry("5", 5L));
}
Also used : Facets(org.sonar.server.es.Facets) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Aggregations

SearchOptions (org.sonar.server.es.SearchOptions)143 Test (org.junit.Test)127 ComponentDto (org.sonar.db.component.ComponentDto)62 Facets (org.sonar.server.es.Facets)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 RuleDto (org.sonar.db.rule.RuleDto)16 RuleKey (org.sonar.api.rule.RuleKey)14 OrganizationDto (org.sonar.db.organization.OrganizationDto)11 IssueQuery (org.sonar.server.issue.IssueQuery)11 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)10 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)9 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)9 SearchIdResult (org.sonar.server.es.SearchIdResult)9 DbSession (org.sonar.db.DbSession)8 OrganizationTesting.newOrganizationDto (org.sonar.db.organization.OrganizationTesting.newOrganizationDto)7 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)5 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)4 RuleParamDto (org.sonar.db.rule.RuleParamDto)4 UserDto (org.sonar.db.user.UserDto)3