use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_security_cwe_return_vulnerabilities_and_hotspots_only.
@Test
public void search_by_security_cwe_return_vulnerabilities_and_hotspots_only() {
RuleDefinitionDto rule1 = createRule(setSecurityStandards(of("cwe:543", "cwe:123", "owaspTop10:a1")), r -> r.setType(VULNERABILITY));
RuleDefinitionDto rule2 = createRule(setSecurityStandards(of("cwe:543", "owaspTop10:a1")), r -> r.setType(SECURITY_HOTSPOT));
createRule(setSecurityStandards(of("owaspTop10:a1")), r -> r.setType(CODE_SMELL));
index();
RuleQuery query = new RuleQuery().setCwe(of("543"));
SearchIdResult<String> results = underTest.search(query, new SearchOptions().addFacets("cwe"));
assertThat(results.getUuids()).containsOnly(rule1.getUuid(), rule2.getUuid());
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_activation.
@Test
public void search_by_activation() {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
RuleDefinitionDto rule3 = createJavaRule();
QProfileDto profile1 = createJavaProfile();
QProfileDto profile2 = createJavaProfile();
db.qualityProfiles().activateRule(profile1, rule1);
db.qualityProfiles().activateRule(profile2, rule1);
db.qualityProfiles().activateRule(profile1, rule2);
index();
// active rules
verifySearch(newRuleQuery().setActivation(true).setQProfile(profile1), rule1, rule2);
verifySearch(newRuleQuery().setActivation(true).setQProfile(profile2), rule1);
// inactive rules
verifySearch(newRuleQuery().setActivation(false).setQProfile(profile1), rule3);
verifySearch(newRuleQuery().setActivation(false).setQProfile(profile2), rule2, rule3);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_activation_and_inheritance.
@Test
public void search_by_activation_and_inheritance() {
RuleDefinitionDto rule1 = createJavaRule();
RuleDefinitionDto rule2 = createJavaRule();
RuleDefinitionDto rule3 = createJavaRule();
RuleDefinitionDto rule4 = createJavaRule();
QProfileDto parent = createJavaProfile();
QProfileDto child = createJavaProfile();
db.qualityProfiles().activateRule(parent, rule1);
db.qualityProfiles().activateRule(parent, rule2);
db.qualityProfiles().activateRule(parent, rule3);
db.qualityProfiles().activateRule(child, rule1, ar -> ar.setInheritance(INHERITED.name()));
db.qualityProfiles().activateRule(child, rule2, ar -> ar.setInheritance(OVERRIDES.name()));
db.qualityProfiles().activateRule(child, rule3, ar -> ar.setInheritance(INHERITED.name()));
index();
// all rules
verifySearch(newRuleQuery(), rule1, rule2, rule3, rule4);
// inherited/overrides rules on parent
verifyEmptySearch(newRuleQuery().setActivation(true).setQProfile(parent).setInheritance(of(INHERITED.name())));
verifyEmptySearch(newRuleQuery().setActivation(true).setQProfile(parent).setInheritance(of(OVERRIDES.name())));
// inherited/overrides rules on child
verifySearch(newRuleQuery().setActivation(true).setQProfile(child).setInheritance(of(INHERITED.name())), rule1, rule3);
verifySearch(newRuleQuery().setActivation(true).setQProfile(child).setInheritance(of(OVERRIDES.name())), rule2);
// inherited AND overridden on parent
verifyEmptySearch(newRuleQuery().setActivation(true).setQProfile(parent).setInheritance(of(INHERITED.name(), OVERRIDES.name())));
// inherited AND overridden on child
verifySearch(newRuleQuery().setActivation(true).setQProfile(child).setInheritance(of(INHERITED.name(), OVERRIDES.name())), rule1, rule2, rule3);
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_is_external.
@Test
public void search_by_is_external() {
RuleDefinitionDto ruleIsNotExternal = createRule(setIsExternal(false));
RuleDefinitionDto ruleIsExternal = createRule(setIsExternal(true));
index();
// Only external
RuleQuery query = new RuleQuery().setIncludeExternal(true);
SearchIdResult<String> results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsOnly(ruleIsExternal.getUuid(), ruleIsNotExternal.getUuid());
// Only not external
query = new RuleQuery().setIncludeExternal(false);
results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsOnly(ruleIsNotExternal.getUuid());
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleIndexTest method search_by_any_of_languages.
@Test
public void search_by_any_of_languages() {
createRule(setLanguage("java"));
RuleDefinitionDto javascript = createRule(setLanguage("js"));
index();
RuleQuery query = new RuleQuery().setLanguages(asList("cobol", "js"));
SearchIdResult<String> results = underTest.search(query, new SearchOptions());
assertThat(results.getUuids()).containsOnly(javascript.getUuid());
// no results
query = new RuleQuery().setLanguages(singletonList("cpp"));
assertThat(underTest.search(query, new SearchOptions()).getUuids()).isEmpty();
// empty list => no filter
query = new RuleQuery().setLanguages(emptyList());
assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
// null list => no filter
query = new RuleQuery().setLanguages(null);
assertThat(underTest.search(query, new SearchOptions()).getUuids()).hasSize(2);
}
Aggregations