use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RuleIndexTest method global_facet_on_repositories_and_tags.
@Test
public void global_facet_on_repositories_and_tags() {
indexRules(newDoc(RuleKey.of("php", "S001")).setAllTags(singletonList("sysTag")), newDoc(RuleKey.of("php", "S002")).setAllTags(singletonList("tag1")), newDoc(RuleKey.of("javascript", "S002")).setAllTags(asList("tag1", "tag2")));
// should not have any facet!
RuleQuery query = new RuleQuery();
SearchIdResult result = index.search(query, new SearchOptions());
assertThat(result.getFacets().getAll()).isEmpty();
// should not have any facet on non matching query!
result = index.search(new RuleQuery().setQueryText("aeiou"), new SearchOptions().addFacets(singletonList("repositories")));
assertThat(result.getFacets().getAll()).hasSize(1);
assertThat(result.getFacets().getAll().get("repositories")).isEmpty();
// Repositories Facet is preset
result = index.search(query, new SearchOptions().addFacets(asList("repositories", "tags")));
assertThat(result.getFacets()).isNotNull();
assertThat(result.getFacets().getAll()).hasSize(2);
// Verify the value of a given facet
Map<String, Long> repoFacets = result.getFacets().get("repositories");
assertThat(repoFacets).containsOnly(entry("php", 2L), entry("javascript", 1L));
// Check that tag facet has both Tags and SystemTags values
Map<String, Long> tagFacets = result.getFacets().get("tags");
assertThat(tagFacets).containsOnly(entry("tag1", 2L), entry("sysTag", 1L), entry("tag2", 1L));
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RuleIndexTest method tags_facet_supports_selected_value_with_regexp_special_characters.
@Test
public void tags_facet_supports_selected_value_with_regexp_special_characters() {
indexRules(newDoc(RuleKey.of("java", "S001")).setAllTags(singleton("misra++")));
RuleQuery query = new RuleQuery().setTags(singletonList("misra["));
SearchOptions options = new SearchOptions().addFacets(RuleIndex.FACET_TAGS);
// do not fail
assertThat(index.search(query, options).getTotal()).isEqualTo(0);
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_tags_in_query_text.
@Test
public void search_by_tags_in_query_text() {
RuleKey key1 = RuleKey.of("java", "S001");
RuleKey key2 = RuleKey.of("java", "S002");
indexRules(newDoc(key1).setAllTags(singleton("tag1")), newDoc(key2).setAllTags(singleton("tag2")));
// find all
RuleQuery query = new RuleQuery();
assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
// tag1 in query
query = new RuleQuery().setQueryText("tag1");
assertThat(index.search(query, new SearchOptions()).getIds()).containsOnly(key1);
// tag1 OR tag2
// note: should it be AND instead of OR ?
query = new RuleQuery().setQueryText("tag1 tag2");
assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
// tag2 OR tag1
query = new RuleQuery().setQueryText("tag2 tag1");
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_languages.
@Test
public void search_by_any_of_languages() {
indexRules(newDoc(RuleKey.of("java", "S001")).setLanguage("java"), newDoc(RuleKey.of("javascript", "S002")).setLanguage("js"));
RuleQuery query = new RuleQuery().setLanguages(asList("cobol", "js"));
SearchIdResult results = index.search(query, new SearchOptions());
assertThat(results.getIds()).containsOnly(RuleKey.of("javascript", "S002"));
// no results
query = new RuleQuery().setLanguages(singletonList("cpp"));
assertThat(index.search(query, new SearchOptions()).getIds()).isEmpty();
// empty list => no filter
query = new RuleQuery().setLanguages(Collections.emptyList());
assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
// null list => no filter
query = new RuleQuery().setLanguages(null);
assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
}
use of org.sonar.server.es.SearchOptions in project sonarqube by SonarSource.
the class RegisterRulesTest method update_only_rule_description.
@Test
public void update_only_rule_description() throws Exception {
when(system.now()).thenReturn(DATE1.getTime());
execute(new RulesDefinition() {
@Override
public void define(Context context) {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule").setName("Name").setHtmlDescription("Desc1");
repo.done();
}
});
when(system.now()).thenReturn(DATE2.getTime());
execute(new RulesDefinition() {
@Override
public void define(Context context) {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule").setName("Name").setHtmlDescription("Desc2");
repo.done();
}
});
// rule1 has been updated
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(dbTester.getSession(), RuleKey.of("fake", "rule"));
assertThat(rule1.getName()).isEqualTo("Name");
assertThat(rule1.getDescription()).isEqualTo("Desc2");
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc2"), new SearchOptions()).getTotal()).isEqualTo(1);
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc1"), new SearchOptions()).getTotal()).isEqualTo(0);
}
Aggregations