use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class CachingRuleFinderTest method findAll_returns_all_rules_with_exact_same_repository_key_and_order_them_most_recent_first.
@Test
public void findAll_returns_all_rules_with_exact_same_repository_key_and_order_them_most_recent_first() {
String repoKey = "ABCD";
RuleDefinitionDto[] sameRepoKey = { dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setUpdatedAt(system2.now())) };
RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey(repoKey))).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(sameRepoKey[1].getKey(), sameRepoKey[0].getKey());
assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey(otherRule.getRepositoryKey()))).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(otherRule.getKey());
assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey(repoKey.toLowerCase()))).isEmpty();
assertThat(underTest.findAll(RuleQuery.create().withRepositoryKey(randomAlphabetic(3)))).isEmpty();
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class CachingRuleFinderTest method findAll_returns_all_rules_which_match_exactly_all_criteria_and_order_then_by_most_recent_first.
@Test
public void findAll_returns_all_rules_which_match_exactly_all_criteria_and_order_then_by_most_recent_first() {
String repoKey = "ABCD";
String ruleKey = "EFGH";
String configKey = "IJKL";
RuleDefinitionDto[] rules = { dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())) };
RuleQuery allQuery = RuleQuery.create().withRepositoryKey(repoKey).withKey(ruleKey).withConfigKey(configKey);
RuleQuery ruleAndConfigKeyQuery = RuleQuery.create().withKey(ruleKey).withConfigKey(configKey);
RuleQuery repoAndConfigKeyQuery = RuleQuery.create().withRepositoryKey(repoKey).withConfigKey(configKey);
RuleQuery repoAndKeyQuery = RuleQuery.create().withRepositoryKey(repoKey).withKey(ruleKey);
RuleQuery configKeyQuery = RuleQuery.create().withConfigKey(configKey);
RuleQuery ruleKeyQuery = RuleQuery.create().withKey(ruleKey);
RuleQuery repoKeyQuery = RuleQuery.create().withRepositoryKey(repoKey);
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
assertThat(underTest.findAll(allQuery)).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(rules[0].getKey());
assertThat(underTest.findAll(ruleAndConfigKeyQuery)).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(rules[1].getKey(), rules[0].getKey());
assertThat(underTest.findAll(repoAndConfigKeyQuery)).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(rules[2].getKey(), rules[0].getKey());
assertThat(underTest.findAll(repoAndKeyQuery)).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(rules[0].getKey());
assertThat(underTest.findAll(repoKeyQuery)).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(rules[2].getKey(), rules[0].getKey());
assertThat(underTest.findAll(ruleKeyQuery)).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(rules[1].getKey(), rules[0].getKey());
assertThat(underTest.findAll(configKeyQuery)).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(rules[2].getKey(), rules[1].getKey(), rules[0].getKey());
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class CachingRuleFinderTest method find_searches_by_exact_match_and_match_on_all_criterias_and_returns_most_recent_match.
@Test
public void find_searches_by_exact_match_and_match_on_all_criterias_and_returns_most_recent_match() {
String repoKey = "ABCD";
String ruleKey = "EFGH";
String configKey = "IJKL";
RuleDefinitionDto[] rules = { dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRepositoryKey(repoKey).setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now())) };
RuleQuery allQuery = RuleQuery.create().withRepositoryKey(repoKey).withKey(ruleKey).withConfigKey(configKey);
RuleQuery ruleAndConfigKeyQuery = RuleQuery.create().withKey(ruleKey).withConfigKey(configKey);
RuleQuery repoAndConfigKeyQuery = RuleQuery.create().withRepositoryKey(repoKey).withConfigKey(configKey);
RuleQuery repoAndKeyQuery = RuleQuery.create().withRepositoryKey(repoKey).withKey(ruleKey);
RuleQuery configKeyQuery = RuleQuery.create().withConfigKey(configKey);
RuleQuery ruleKeyQuery = RuleQuery.create().withKey(ruleKey);
RuleQuery repoKeyQuery = RuleQuery.create().withRepositoryKey(repoKey);
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
assertThat(toRuleKey(underTest.find(allQuery))).isEqualTo(rules[0].getKey());
assertThat(toRuleKey(underTest.find(ruleAndConfigKeyQuery))).isEqualTo(rules[1].getKey());
assertThat(toRuleKey(underTest.find(repoAndConfigKeyQuery))).isEqualTo(rules[2].getKey());
assertThat(toRuleKey(underTest.find(repoAndKeyQuery))).isEqualTo(rules[0].getKey());
assertThat(toRuleKey(underTest.find(repoKeyQuery))).isEqualTo(rules[2].getKey());
assertThat(toRuleKey(underTest.find(ruleKeyQuery))).isEqualTo(rules[1].getKey());
assertThat(toRuleKey(underTest.find(configKeyQuery))).isEqualTo(rules[2].getKey());
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class CachingRuleFinderTest method findAll_returns_all_rules_with_exact_same_configkey_and_order_them_most_recent_first.
@Test
public void findAll_returns_all_rules_with_exact_same_configkey_and_order_them_most_recent_first() {
String configKey = "ABCD";
RuleDefinitionDto[] sameConfigKey = { dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setConfigKey(configKey).setUpdatedAt(system2.now())) };
RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
assertThat(underTest.findAll(RuleQuery.create().withConfigKey(configKey))).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(sameConfigKey[1].getKey(), sameConfigKey[0].getKey());
assertThat(underTest.findAll(RuleQuery.create().withConfigKey(otherRule.getConfigKey()))).extracting(CachingRuleFinderTest::toRuleKey).containsExactly(otherRule.getKey());
assertThat(underTest.findAll(RuleQuery.create().withConfigKey(configKey.toLowerCase()))).isEmpty();
assertThat(underTest.findAll(RuleQuery.create().withConfigKey(randomAlphabetic(3)))).isEmpty();
}
use of org.sonar.api.rules.Rule in project sonarqube by SonarSource.
the class CachingRuleFinderTest method find_returns_most_recent_rule_when_RuleQuery_has_no_non_null_field.
@Test
public void find_returns_most_recent_rule_when_RuleQuery_has_no_non_null_field() {
Rule rule = underTest.find(RuleQuery.create());
assertThat(toRuleKey(rule)).isEqualTo(ruleDefinitions[5].getKey());
}
Aggregations