use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_duplicated_lines_density_is_sticky.
@Test
public void facet_duplicated_lines_density_is_sticky() {
index(// docs with duplication<3%
newDoc(DUPLICATION, 0d, NCLOC, 999d, COVERAGE, 0d), // docs with duplication>=3% and duplication<5%
newDoc(DUPLICATION, 3d, NCLOC, 5000d, COVERAGE, 0d), newDoc(DUPLICATION, 4.9d, NCLOC, 6000d, COVERAGE, 0d), // docs with duplication>=5% and duplication<10%
newDoc(DUPLICATION, 5d, NCLOC, 11000d, COVERAGE, 0d), // docs with duplication>=10% and duplication<20%
newDoc(DUPLICATION, 10d, NCLOC, 120000d, COVERAGE, 10d), newDoc(DUPLICATION, 19.9d, NCLOC, 130000d, COVERAGE, 20d), // docs with duplication>= 20%
newDoc(DUPLICATION, 20d, NCLOC, 1000000d, COVERAGE, 40d));
Facets facets = underTest.search(new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)).addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)), new SearchOptions().addFacets(DUPLICATION, NCLOC)).getFacets();
// Sticky facet on duplication does not take into account duplication filter
assertThat(facets.get(DUPLICATION)).containsExactly(entry("*-3.0", 1L), entry("3.0-5.0", 2L), entry("5.0-10.0", 1L), entry("10.0-20.0", 2L), entry("20.0-*", 0L));
// But facet on ncloc does well take into into filters
assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 1L), entry("1000.0-10000.0", 2L), entry("10000.0-100000.0", 1L), entry("100000.0-500000.0", 0L), entry("500000.0-*", 0L));
}
use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_coverage_is_sticky.
@Test
public void facet_coverage_is_sticky() {
index(// docs with coverage<30%
newDoc(NCLOC, 999d, COVERAGE, 0d, DUPLICATION, 0d), newDoc(NCLOC, 1_000d, COVERAGE, 10d, DUPLICATION, 0d), newDoc(NCLOC, 9_999d, COVERAGE, 20d, DUPLICATION, 0d), // docs with coverage>=30% and coverage<50%
newDoc(NCLOC, 10_000d, COVERAGE, 31d, DUPLICATION, 0d), newDoc(NCLOC, 11_000d, COVERAGE, 40d, DUPLICATION, 0d), // docs with coverage>=50% and coverage<70%
newDoc(NCLOC, 99_000d, COVERAGE, 50d, DUPLICATION, 0d), // docs with coverage>=70% and coverage<80%
newDoc(NCLOC, 100_000d, COVERAGE, 71d, DUPLICATION, 0d), // docs with coverage>= 80%
newDoc(NCLOC, 499_000d, COVERAGE, 80d, DUPLICATION, 15d), newDoc(NCLOC, 501_000d, COVERAGE, 810d, DUPLICATION, 20d));
Facets facets = underTest.search(new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion(COVERAGE, Operator.LT, 30d)).addMetricCriterion(new MetricCriterion(DUPLICATION, Operator.LT, 10d)), new SearchOptions().addFacets(COVERAGE, NCLOC)).getFacets();
// Sticky facet on coverage does not take into account coverage filter
assertThat(facets.get(COVERAGE)).containsExactly(entry("*-30.0", 3L), entry("30.0-50.0", 2L), entry("50.0-70.0", 1L), entry("70.0-80.0", 1L), entry("80.0-*", 0L));
// But facet on ncloc does well take into into filters
assertThat(facets.get(NCLOC)).containsExactly(entry("*-1000.0", 1L), entry("1000.0-10000.0", 2L), entry("10000.0-100000.0", 0L), entry("100000.0-500000.0", 0L), entry("500000.0-*", 0L));
}
use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.
the class ProjectMeasuresQueryValidatorTest method return_all_unknown_metrics.
@Test
public void return_all_unknown_metrics() throws Exception {
insertValidMetric("ncloc");
ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("debt", GT, 10d)).addMetricCriterion(new MetricCriterion("ncloc", LTE, 20d)).addMetricCriterion(new MetricCriterion("coverage", GT, 30d)).setSort("duplications");
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("Unknown metric(s) [coverage, debt, duplications]");
underTest.validate(dbSession, query);
}
use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.
the class ProjectMeasuresQueryValidatorTest method does_not_fail_when_sort_is_by_name.
@Test
public void does_not_fail_when_sort_is_by_name() throws Exception {
insertValidMetric("ncloc");
ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d)).setSort("name");
underTest.validate(dbSession, query);
}
use of org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion in project sonarqube by SonarSource.
the class ProjectMeasuresQueryValidatorTest method does_not_fail_when_metric_criteria_contains_an_existing_metric.
@Test
public void does_not_fail_when_metric_criteria_contains_an_existing_metric() throws Exception {
insertValidMetric("ncloc");
ProjectMeasuresQuery query = new ProjectMeasuresQuery().addMetricCriterion(new MetricCriterion("ncloc", GT, 10d));
underTest.validate(dbSession, query);
}
Aggregations