use of org.sonar.server.es.SearchIdResult 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.SearchIdResult 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.SearchIdResult in project sonarqube by SonarSource.
the class RuleIndexTest method search_all_rules.
@Test
public void search_all_rules() {
indexRules(newDoc(RuleKey.of("javascript", "S001")), newDoc(RuleKey.of("java", "S002")));
SearchIdResult results = index.search(new RuleQuery(), new SearchOptions());
assertThat(results.getTotal()).isEqualTo(2);
assertThat(results.getIds()).hasSize(2);
}
use of org.sonar.server.es.SearchIdResult in project sonarqube by SonarSource.
the class RuleIndexTest method sticky_facets.
@Test
public void sticky_facets() {
indexRules(newDoc(RuleKey.of("xoo", "S001")).setLanguage("java").setAllTags(Collections.emptyList()).setType(BUG), newDoc(RuleKey.of("xoo", "S002")).setLanguage("java").setAllTags(Collections.emptyList()).setType(CODE_SMELL), newDoc(RuleKey.of("xoo", "S003")).setLanguage("java").setAllTags(asList("T1", "T2")).setType(CODE_SMELL), newDoc(RuleKey.of("xoo", "S011")).setLanguage("cobol").setAllTags(Collections.emptyList()).setType(CODE_SMELL), newDoc(RuleKey.of("xoo", "S012")).setLanguage("cobol").setAllTags(Collections.emptyList()).setType(BUG), newDoc(RuleKey.of("foo", "S013")).setLanguage("cobol").setAllTags(asList("T3", "T4")).setType(VULNERABILITY), newDoc(RuleKey.of("foo", "S111")).setLanguage("cpp").setAllTags(Collections.emptyList()).setType(BUG), newDoc(RuleKey.of("foo", "S112")).setLanguage("cpp").setAllTags(Collections.emptyList()).setType(CODE_SMELL), newDoc(RuleKey.of("foo", "S113")).setLanguage("cpp").setAllTags(asList("T2", "T3")).setType(CODE_SMELL));
// 0 assert Base
assertThat(index.search(new RuleQuery(), new SearchOptions()).getIds()).hasSize(9);
// 1 Facet with no filters at all
SearchIdResult result = index.search(new RuleQuery(), new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS, FACET_TYPES)));
assertThat(result.getFacets().getAll()).hasSize(4);
assertThat(result.getFacets().getAll().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java", "cobol");
assertThat(result.getFacets().getAll().get(FACET_REPOSITORIES).keySet()).containsExactly("xoo", "foo");
assertThat(result.getFacets().getAll().get(FACET_TAGS).keySet()).containsOnly("T1", "T2", "T3", "T4");
assertThat(result.getFacets().getAll().get(FACET_TYPES).keySet()).containsOnly("BUG", "CODE_SMELL", "VULNERABILITY");
// 2 Facet with a language filter
// -- lang facet should still have all language
result = index.search(new RuleQuery().setLanguages(ImmutableList.of("cpp")), new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS)));
assertThat(result.getIds()).hasSize(3);
assertThat(result.getFacets().getAll()).hasSize(3);
assertThat(result.getFacets().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java", "cobol");
// 3 facet with 2 filters
// -- lang facet for tag T2
// -- tag facet for lang cpp
// -- repository for cpp & T2
result = index.search(new RuleQuery().setLanguages(ImmutableList.of("cpp")).setTags(ImmutableList.of("T2")), new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS)));
assertThat(result.getIds()).hasSize(1);
assertThat(result.getFacets().getAll()).hasSize(3);
assertThat(result.getFacets().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java");
assertThat(result.getFacets().get(FACET_REPOSITORIES).keySet()).containsOnly("foo");
assertThat(result.getFacets().get(FACET_TAGS).keySet()).containsOnly("T2", "T3");
// 4 facet with 3 filters
// -- lang facet for tag T2
// -- tag facet for lang cpp & java
// -- repository for (cpp || java) & T2
// -- type
result = index.search(new RuleQuery().setLanguages(ImmutableList.of("cpp", "java")).setTags(ImmutableList.of("T2")).setTypes(asList(BUG, CODE_SMELL)), new SearchOptions().addFacets(asList(FACET_LANGUAGES, FACET_REPOSITORIES, FACET_TAGS, FACET_TYPES)));
assertThat(result.getIds()).hasSize(2);
assertThat(result.getFacets().getAll()).hasSize(4);
assertThat(result.getFacets().get(FACET_LANGUAGES).keySet()).containsOnly("cpp", "java");
assertThat(result.getFacets().get(FACET_REPOSITORIES).keySet()).containsOnly("foo", "xoo");
assertThat(result.getFacets().get(FACET_TAGS).keySet()).containsOnly("T1", "T2", "T3");
assertThat(result.getFacets().get(FACET_TYPES).keySet()).containsOnly("CODE_SMELL");
}
use of org.sonar.server.es.SearchIdResult in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_template_key.
@Test
public void search_by_template_key() {
indexRules(newDoc(RuleKey.of("java", "S001")).setIsTemplate(true), newDoc(RuleKey.of("java", "S001_MY_CUSTOM")).setTemplateKey("java:S001"));
// find all
RuleQuery query = new RuleQuery();
SearchIdResult results = index.search(query, new SearchOptions());
assertThat(results.getIds()).hasSize(2);
// Only custom rule
query = new RuleQuery().setTemplateKey("java:S001");
results = index.search(query, new SearchOptions());
assertThat(results.getIds()).containsOnly(RuleKey.of("java", "S001_MY_CUSTOM"));
// null => no filter
query = new RuleQuery().setTemplateKey(null);
assertThat(index.search(query, new SearchOptions()).getIds()).hasSize(2);
}
Aggregations