use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class DefaultRuleFinderTest method findByKey_populates_system_tags_but_not_tags.
@Test
public void findByKey_populates_system_tags_but_not_tags() {
RuleDefinitionDto ruleDefinition = dbTester.rules().insert(t -> t.setSystemTags(ImmutableSet.of(randomAlphanumeric(5), randomAlphanumeric(6))));
dbTester.rules().insertRule();
Rule rule = underTest.findByKey(ruleDefinition.getKey());
assertThat(rule.getSystemTags()).containsOnlyElementsOf(ruleDefinition.getSystemTags());
assertThat(rule.getTags()).isEmpty();
rule = underTest.findByKey(ruleDefinition.getRepositoryKey(), ruleDefinition.getRuleKey());
assertThat(rule.getSystemTags()).containsOnlyElementsOf(ruleDefinition.getSystemTags());
assertThat(rule.getTags()).isEmpty();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleDescriptionFormatterTest method handleNullDescription.
@Test
public void handleNullDescription() {
RuleDefinitionDto rule = new RuleDefinitionDto().setDescription(null).setDescriptionFormat(RuleDto.Format.HTML);
String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
assertThat(result).isNull();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class RuleDescriptionFormatterTest method handleNullDescriptionFormat.
@Test
public void handleNullDescriptionFormat() {
RuleDefinitionDto rule = new RuleDefinitionDto().setDescription("whatever").setDescriptionFormat(null);
String result = RuleDescriptionFormatter.getDescriptionAsHtml(rule);
assertThat(result).isNull();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class CachingRuleFinderTest method find_searches_by_exact_match_of_ruleKey_and_returns_most_recent_rule.
@Test
public void find_searches_by_exact_match_of_ruleKey_and_returns_most_recent_rule() {
String ruleKey = "ABCD";
RuleDefinitionDto[] sameRuleKey = { dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())), dbTester.rules().insert(rule -> rule.setRuleKey(ruleKey).setUpdatedAt(system2.now())) };
RuleDefinitionDto otherRule = dbTester.rules().insert(rule -> rule.setUpdatedAt(system2.now()));
CachingRuleFinder underTest = new CachingRuleFinder(dbClient);
assertThat(toRuleKey(underTest.find(RuleQuery.create().withKey(ruleKey)))).isEqualTo(sameRuleKey[1].getKey());
assertThat(toRuleKey(underTest.find(RuleQuery.create().withKey(otherRule.getRuleKey())))).isEqualTo(otherRule.getKey());
assertThat(underTest.find(RuleQuery.create().withKey(ruleKey.toLowerCase()))).isNull();
assertThat(underTest.find(RuleQuery.create().withKey(randomAlphabetic(3)))).isNull();
}
use of org.sonar.db.rule.RuleDefinitionDto in project sonarqube by SonarSource.
the class CachingRuleFinderTest method find_searches_by_exact_match_of_configKey_and_returns_most_recent_rule.
@Test
public void find_searches_by_exact_match_of_configKey_and_returns_most_recent_rule() {
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(toRuleKey(underTest.find(RuleQuery.create().withConfigKey(configKey)))).isEqualTo(sameConfigKey[1].getKey());
assertThat(toRuleKey(underTest.find(RuleQuery.create().withConfigKey(otherRule.getConfigKey())))).isEqualTo(otherRule.getKey());
assertThat(underTest.find(RuleQuery.create().withConfigKey(configKey.toLowerCase()))).isNull();
assertThat(underTest.find(RuleQuery.create().withConfigKey(randomAlphabetic(3)))).isNull();
}
Aggregations