use of org.sonar.api.rules.RuleQuery 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.RuleQuery 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());
}
Aggregations