use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class ChangeParentActionMediumTest method replace_existing_parent.
@Test
public void replace_existing_parent() throws Exception {
QualityProfileDto parent1 = createProfile("xoo", "Parent 1");
QualityProfileDto parent2 = createProfile("xoo", "Parent 2");
QualityProfileDto child = createProfile("xoo", "Child");
RuleDto rule1 = createRule("xoo", "rule1");
RuleDto rule2 = createRule("xoo", "rule2");
createActiveRule(rule1, parent1);
createActiveRule(rule2, parent2);
session.commit();
ruleIndexer.index();
activeRuleIndexer.index();
// Set parent 1
tester.get(RuleActivator.class).setParent(session, child.getKey(), parent1.getKey());
session.clearCache();
// Set parent 2 through WS
wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, "change_parent").setParam(QProfileRef.PARAM_PROFILE_KEY, child.getKey()).setParam("parentKey", parent2.getKey()).execute();
session.clearCache();
// Check rule 2 enabled
List<ActiveRuleDto> activeRules2 = db.activeRuleDao().selectByProfileKey(session, child.getKey());
assertThat(activeRules2).hasSize(1);
assertThat(activeRules2.get(0).getKey().ruleKey().rule()).isEqualTo("rule2");
assertThat(ruleIndex.search(new RuleQuery().setActivation(true).setQProfileKey(child.getKey()), new SearchOptions()).getIds()).hasSize(1);
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RegisterQualityProfilesMediumTest method register_existing_profile_definitions.
@Test
public void register_existing_profile_definitions() {
tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
tester.start();
dbSession = dbClient().openSession(false);
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient().qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession)).hasSize(1);
QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage("Basic", "xoo", dbSession);
assertThat(profile).isNotNull();
// Check ActiveRules in DB
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
RuleKey ruleKey = RuleKey.of("xoo", "x1");
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), ruleKey);
assertThat(activeRuleDao.selectByKey(dbSession, activeRuleKey)).isPresent();
// Check in ES
assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setActivation(true), new SearchOptions()).getIds()).containsOnly(ruleKey, RuleKey.of("xoo", "x2"));
tester.get(Platform.class).restart();
assertThat(activeRuleDao.selectByKey(dbSession, activeRuleKey)).isPresent();
// Check ActiveRules
ActiveRuleDto activeRule = activeRuleDao.selectByKey(dbSession, activeRuleKey).get();
assertThat(activeRule.getKey().qProfile()).isEqualTo(profile.getKee());
assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey);
assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
// Check in ES
assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setActivation(true), new SearchOptions()).getIds()).containsOnly(ruleKey, RuleKey.of("xoo", "x2"));
// TODO
// Check ActiveRuleParameters in DB
Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId()));
assertThat(params).hasSize(2);
// set by profile
assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
// default value
assertThat(params.get("max").getValue()).isEqualTo("10");
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_is_template.
@Test
public void search_by_is_template() {
indexRules(newDoc(RuleKey.of("java", "S001")).setIsTemplate(false), newDoc(RuleKey.of("java", "S002")).setIsTemplate(true));
// find all
RuleQuery query = new RuleQuery();
SearchIdResult results = index.search(query, new SearchOptions());
assertThat(results.getIds()).hasSize(2);
// Only template
query = new RuleQuery().setIsTemplate(true);
results = index.search(query, new SearchOptions());
assertThat(results.getIds()).containsOnly(RuleKey.of("java", "S002"));
// Only not template
query = new RuleQuery().setIsTemplate(false);
results = index.search(query, new SearchOptions());
assertThat(results.getIds()).containsOnly(RuleKey.of("java", "S001"));
// null => no filter
query = new RuleQuery().setIsTemplate(null);
assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_any_of_repositories.
@Test
public void search_by_any_of_repositories() {
indexRules(newDoc(RuleKey.of("findbugs", "S001")), newDoc(RuleKey.of("pmd", "S002")));
List<SearchHit> docs = tester.getDocuments(INDEX_TYPE_RULE);
for (SearchHit doc : docs) {
System.out.println(doc.getSourceAsString());
}
RuleQuery query = new RuleQuery().setRepositories(asList("checkstyle", "pmd"));
SearchIdResult results = index.search(query, new SearchOptions());
assertThat(results.getIds()).containsOnly(RuleKey.of("pmd", "S002"));
// no results
query = new RuleQuery().setRepositories(singletonList("checkstyle"));
assertThat(index.search(query, new SearchOptions()).getIds()).isEmpty();
// empty list => no filter
query = new RuleQuery().setRepositories(Collections.emptyList());
assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RuleIndexTest method paging.
@Test
public void paging() {
indexRules(newDoc(RuleKey.of("java", "S001")), newDoc(RuleKey.of("java", "S002")), newDoc(RuleKey.of("java", "S003")));
// from 0 to 1 included
SearchOptions options = new SearchOptions();
options.setOffset(0).setLimit(2);
SearchIdResult results = index.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
assertThat(results.getIds()).hasSize(2);
// from 0 to 9 included
options.setOffset(0).setLimit(10);
results = index.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
assertThat(results.getIds()).hasSize(3);
// from 2 to 11 included
options.setOffset(2).setLimit(10);
results = index.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
assertThat(results.getIds()).hasSize(1);
// from 2 to 11 included
options.setOffset(2).setLimit(0);
results = index.search(new RuleQuery(), options);
assertThat(results.getTotal()).isEqualTo(3);
assertThat(results.getIds()).hasSize(1);
}
Aggregations