use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method sort_by_name.
@Test
public void sort_by_name() {
RuleDefinitionDto abcd = createRule(setName("abcd"));
RuleDefinitionDto abc = createRule(setName("ABC"));
RuleDefinitionDto fgh = createRule(setName("FGH"));
index();
// ascending
RuleQuery query = new RuleQuery().setSortField(RuleIndexDefinition.FIELD_RULE_NAME);
SearchIdResult<String> results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsExactly(abc.getUuid(), abcd.getUuid(), fgh.getUuid());
// descending
query = new RuleQuery().setSortField(RuleIndexDefinition.FIELD_RULE_NAME).setAscendingSort(false);
results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsExactly(fgh.getUuid(), abcd.getUuid(), abc.getUuid());
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_security_sansTop25_return_vulnerabilities_and_hotspots_only.
@Test
public void search_by_security_sansTop25_return_vulnerabilities_and_hotspots_only() {
RuleDefinitionDto rule1 = createRule(setSecurityStandards(of("owaspTop10:a1", "owaspTop10:a10", "cwe:89")), r -> r.setType(VULNERABILITY));
RuleDefinitionDto rule2 = createRule(setSecurityStandards(of("owaspTop10:a10", "cwe:829")), r -> r.setType(SECURITY_HOTSPOT));
createRule(setSecurityStandards(of("cwe:306")), r -> r.setType(CODE_SMELL));
index();
RuleQuery query = new RuleQuery().setSansTop25(of(SANS_TOP_25_INSECURE_INTERACTION, SANS_TOP_25_RISKY_RESOURCE));
SearchIdResult<String> results = underTest.search(query, new SearchOptions().addFacets("sansTop25"));
assertThat(results.getUuids()).containsOnly(rule1.getUuid(), rule2.getUuid());
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method default_sort_is_by_updated_at_desc.
@Test
public void default_sort_is_by_updated_at_desc() {
RuleDefinitionDto old = createRule(setCreatedAt(1000L), setUpdatedAt(1000L));
RuleDefinitionDto oldest = createRule(setCreatedAt(1000L), setUpdatedAt(3000L));
RuleDefinitionDto older = createRule(setCreatedAt(1000L), setUpdatedAt(2000L));
index();
SearchIdResult<String> results = underTest.search(new RuleQuery(), new SearchOptions());
assertThat(results.getUuids()).containsExactly(oldest.getUuid(), older.getUuid(), old.getUuid());
}
use of org.sonar.db.rule.RuleDefinitionDto 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() {
RuleDefinitionDto rule = createRule();
createRuleMetadata(rule, setTags("misra++"));
index();
RuleQuery query = new RuleQuery().setTags(singletonList("misra["));
SearchOptions options = new SearchOptions().addFacets(FACET_TAGS);
// do not fail
assertThat(underTest.search(query, options).getTotal()).isZero();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_key.
@Test
public void search_by_key() {
RuleDefinitionDto js1 = createRule(setRepositoryKey("javascript"), setRuleKey("X001"));
RuleDefinitionDto cobol1 = createRule(setRepositoryKey("cobol"), setRuleKey("X001"));
createRule(setRepositoryKey("php"), setRuleKey("S002"));
index();
// key
RuleQuery query = new RuleQuery().setQueryText("X001");
assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(js1.getUuid(), cobol1.getUuid());
// partial key does not match
query = new RuleQuery().setQueryText("X00");
assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// repo:key -> nice-to-have !
query = new RuleQuery().setQueryText("javascript:X001");
assertThat(underTest.search(query, new SearchOptions()).getUuids()).containsOnly(js1.getUuid());
}
Aggregations