use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RegisterRulesTest method update_only_rule_description.
@Test
public void update_only_rule_description() throws Exception {
when(system.now()).thenReturn(DATE1.getTime());
execute(new RulesDefinition() {
@Override
public void define(Context context) {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule").setName("Name").setHtmlDescription("Desc1");
repo.done();
}
});
when(system.now()).thenReturn(DATE2.getTime());
execute(new RulesDefinition() {
@Override
public void define(Context context) {
NewRepository repo = context.createRepository("fake", "java");
repo.createRule("rule").setName("Name").setHtmlDescription("Desc2");
repo.done();
}
});
// rule1 has been updated
RuleDto rule1 = dbClient.ruleDao().selectOrFailByKey(dbTester.getSession(), RuleKey.of("fake", "rule"));
assertThat(rule1.getName()).isEqualTo("Name");
assertThat(rule1.getDescription()).isEqualTo("Desc2");
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc2"), new SearchOptions()).getTotal()).isEqualTo(1);
assertThat(ruleIndex.search(new RuleQuery().setQueryText("Desc1"), new SearchOptions()).getTotal()).isEqualTo(0);
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleCreatorMediumTest method create_custom_rule_with_multiple_parameter_values.
@Test
public void create_custom_rule_with_multiple_parameter_values() {
// insert template rule
RuleDto templateRule = createTemplateRuleWithIntArrayParam();
NewCustomRule newRule = NewCustomRule.createForCustomRule("CUSTOM_RULE", templateRule.getKey()).setName("My custom").setHtmlDescription("Some description").setSeverity(Severity.MAJOR).setStatus(RuleStatus.READY).setParameters(ImmutableMap.of("myIntegers", "1,3"));
RuleKey customRuleKey = creator.create(newRule);
dbSession.clearCache();
List<RuleParamDto> params = db.ruleDao().selectRuleParamsByRuleKey(dbSession, customRuleKey);
assertThat(params).hasSize(1);
RuleParamDto param = params.get(0);
assertThat(param.getName()).isEqualTo("myIntegers");
assertThat(param.getDescription()).isEqualTo("My Integers");
assertThat(param.getType()).isEqualTo("INTEGER,multiple=true,values=1;2;3");
assertThat(param.getDefaultValue()).isEqualTo("1,3");
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleDeleterMediumTest method delete_custom_rule.
@Test
public void delete_custom_rule() {
// Create template rule
RuleDto templateRule = RuleTesting.newTemplateRule(RuleKey.of("xoo", "T1")).setLanguage("xoo").setCreatedAt(PAST).setUpdatedAt(PAST);
dao.insert(dbSession, templateRule);
// Create custom rule
RuleDto customRule = RuleTesting.newCustomRule(templateRule).setLanguage("xoo").setCreatedAt(PAST).setUpdatedAt(PAST);
dao.insert(dbSession, customRule);
// Create a quality profile
QualityProfileDto profileDto = QProfileTesting.newXooP1("org-123");
db.qualityProfileDao().insert(dbSession, profileDto);
dbSession.commit();
dbSession.clearCache();
ruleIndexer.index();
activeRuleIndexer.index();
// Activate the custom rule
activate(new RuleActivation(customRule.getKey()).setSeverity(Severity.BLOCKER), QProfileTesting.XOO_P1_KEY);
// Delete custom rule
deleter.delete(customRule.getKey());
// Verify custom rule have status REMOVED
RuleDto customRuleReloaded = dao.selectOrFailByKey(dbSession, customRule.getKey());
assertThat(customRuleReloaded).isNotNull();
assertThat(customRuleReloaded.getStatus()).isEqualTo(RuleStatus.REMOVED);
assertThat(customRuleReloaded.getUpdatedAt()).isNotEqualTo(PAST);
// Verify there's no more active rule from custom rule
assertThat(index.searchAll(new RuleQuery().setQProfileKey(profileDto.getKey()).setActivation(true))).isEmpty();
// Verify in index
assertThat(index.searchAll(new RuleQuery())).containsOnly(templateRule.getKey());
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleTagHelperTest method applyTags_remove_all_existing_tags.
@Test
public void applyTags_remove_all_existing_tags() {
RuleDto rule = new RuleDto().setTags(Sets.newHashSet("performance"));
boolean changed = RuleTagHelper.applyTags(rule, Collections.<String>emptySet());
assertThat(rule.getTags()).isEmpty();
assertThat(changed).isTrue();
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class RuleTagHelperTest method applyTags_no_changes.
@Test
public void applyTags_no_changes() {
RuleDto rule = new RuleDto().setTags(Sets.newHashSet("performance"));
boolean changed = RuleTagHelper.applyTags(rule, Sets.newHashSet("performance"));
assertThat(rule.getTags()).containsOnly("performance");
assertThat(changed).isFalse();
}
Aggregations