use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class ProjectMeasuresIndexTest method facet_coverage.
@Test
public void facet_coverage() {
index(// 3 docs with coverage<30%
newDoc(COVERAGE, 0d), newDoc(COVERAGE, 0d), newDoc(COVERAGE, 29d), // 2 docs with coverage>=30% and coverage<50%
newDoc(COVERAGE, 30d), newDoc(COVERAGE, 49d), // 4 docs with coverage>=50% and coverage<70%
newDoc(COVERAGE, 50d), newDoc(COVERAGE, 60d), newDoc(COVERAGE, 60d), newDoc(COVERAGE, 69d), // 2 docs with coverage>=70% and coverage<80%
newDoc(COVERAGE, 70d), newDoc(COVERAGE, 79d), // 5 docs with coverage>= 80%
newDoc(COVERAGE, 80d), newDoc(COVERAGE, 80d), newDoc(COVERAGE, 90d), newDoc(COVERAGE, 90.5d), newDoc(COVERAGE, 100d));
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", 4L), entry("70.0-80.0", 2L), entry("80.0-*", 5L));
}
use of org.sonar.server.es.SearchOptions 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.es.SearchOptions 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.es.SearchOptions in project sonarqube by SonarSource.
the class RuleActivatorMediumTest method bulk_activation.
@Test
public void bulk_activation() {
// Generate more rules than the search's max limit
int bulkSize = SearchOptions.MAX_LIMIT + 10;
for (int i = 0; i < bulkSize; i++) {
db.ruleDao().insert(dbSession, newDto(RuleKey.of("bulk", "r_" + i)).setLanguage("xoo"));
}
dbSession.commit();
ruleIndexer.index();
// 0. No active rules so far (base case) and plenty rules available
verifyZeroActiveRules(XOO_P1_KEY);
assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setRepositories(Arrays.asList("bulk")), new SearchOptions()).getTotal()).isEqualTo(bulkSize);
// 1. bulk activate all the rules
BulkChangeResult result = ruleActivator.bulkActivate(new RuleQuery().setRepositories(Arrays.asList("bulk")), XOO_P1_KEY, "MINOR");
// 2. assert that all activation has been commit to DB and ES
dbSession.clearCache();
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
assertThat(db.activeRuleDao().selectByProfileKey(dbSession, XOO_P1_KEY)).hasSize(bulkSize);
assertThat(result.countSucceeded()).isEqualTo(bulkSize);
assertThat(result.countFailed()).isEqualTo(0);
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method fail_if_parent_key_and_name_both_set.
@Test(expected = IllegalArgumentException.class)
public void fail_if_parent_key_and_name_both_set() throws Exception {
QualityProfileDto child = createProfile("xoo", "Child");
session.commit();
assertThat(db.activeRuleDao().selectByProfileKey(session, child.getKey())).isEmpty();
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).isEmpty();
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKee()).setParam("parentName", "polop").setParam("parentKey", "palap").execute();
}
Aggregations