Search in sources :

Example 61 with SearchOptions

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));
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) SearchIdResult(org.sonar.server.es.SearchIdResult) Test(org.junit.Test)

Example 62 with SearchOptions

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);
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 63 with SearchOptions

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);
}
Also used : ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) RuleKey(org.sonar.api.rule.RuleKey) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Example 64 with SearchOptions

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);
}
Also used : SearchOptions(org.sonar.server.es.SearchOptions) SearchIdResult(org.sonar.server.es.SearchIdResult) Test(org.junit.Test)

Example 65 with SearchOptions

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);
}
Also used : RulesDefinition(org.sonar.api.server.rule.RulesDefinition) RuleDto(org.sonar.db.rule.RuleDto) RuleQuery(org.sonar.server.rule.index.RuleQuery) SearchOptions(org.sonar.server.es.SearchOptions) Test(org.junit.Test)

Aggregations

SearchOptions (org.sonar.server.es.SearchOptions)143 Test (org.junit.Test)127 ComponentDto (org.sonar.db.component.ComponentDto)62 Facets (org.sonar.server.es.Facets)22 RuleQuery (org.sonar.server.rule.index.RuleQuery)22 RuleDto (org.sonar.db.rule.RuleDto)16 RuleKey (org.sonar.api.rule.RuleKey)14 OrganizationDto (org.sonar.db.organization.OrganizationDto)11 IssueQuery (org.sonar.server.issue.IssueQuery)11 ActiveRuleKey (org.sonar.db.qualityprofile.ActiveRuleKey)10 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)9 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)9 SearchIdResult (org.sonar.server.es.SearchIdResult)9 DbSession (org.sonar.db.DbSession)8 OrganizationTesting.newOrganizationDto (org.sonar.db.organization.OrganizationTesting.newOrganizationDto)7 JsonWriter (org.sonar.api.utils.text.JsonWriter)5 MetricCriterion (org.sonar.server.measure.index.ProjectMeasuresQuery.MetricCriterion)5 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)4 RuleParamDto (org.sonar.db.rule.RuleParamDto)4 UserDto (org.sonar.db.user.UserDto)3