use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method activate_rule.
@Test
public void activate_rule() throws Exception {
QualityProfileDto profile = createProfile("java");
RuleDto rule = createRule(profile.getLanguage(), "toto");
session.commit();
ruIndexer.index();
// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString());
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(1);
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method bulk_deactivate_rule.
@Test
public void bulk_deactivate_rule() throws Exception {
QualityProfileDto profile = createProfile("java");
RuleDto rule0 = createRule(profile.getLanguage(), "toto1");
RuleDto rule1 = createRule(profile.getLanguage(), "toto2");
RuleDto rule2 = createRule(profile.getLanguage(), "toto3");
RuleDto rule3 = createRule(profile.getLanguage(), "toto4");
createActiveRule(rule0, profile);
createActiveRule(rule2, profile);
createActiveRule(rule3, profile);
createActiveRule(rule1, profile);
session.commit();
ruIndexer.index();
activeRuIndexer.index();
// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(4);
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method createRule.
private RuleDto createRule(String lang, String id) {
RuleDto rule = RuleTesting.newDto(RuleKey.of("blah", id)).setLanguage(lang).setSeverity(Severity.BLOCKER).setStatus(RuleStatus.READY);
db.ruleDao().insert(session, rule);
return rule;
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method bulk_deactivate_rule_not_all.
@Test
public void bulk_deactivate_rule_not_all() throws Exception {
QualityProfileDto profile = createProfile("java");
QualityProfileDto php = createProfile("php");
RuleDto rule0 = createRule(profile.getLanguage(), "toto1");
RuleDto rule1 = createRule(profile.getLanguage(), "toto2");
createActiveRule(rule0, profile);
createActiveRule(rule1, profile);
createActiveRule(rule0, php);
createActiveRule(rule1, php);
session.commit();
ruIndexer.index();
activeRuIndexer.index();
// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(2);
// 1. Deactivate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, BulkRuleActivationActions.BULK_DEACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).hasSize(0);
assertThat(db.activeRuleDao().selectByProfileKey(session, php.getKey())).hasSize(2);
}
use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.
the class QProfilesWsMediumTest method activate_rule_override_severity.
@Test
public void activate_rule_override_severity() throws Exception {
QualityProfileDto profile = createProfile("java");
RuleDto rule = createRule(profile.getLanguage(), "toto");
session.commit();
ruIndexer.index();
// 0. Assert No Active Rule for profile
assertThat(db.activeRuleDao().selectByProfileKey(session, profile.getKey())).isEmpty();
// 1. Activate Rule
WsTester.TestRequest request = wsTester.newPostRequest(QProfilesWs.API_ENDPOINT, RuleActivationActions.ACTIVATE_ACTION);
request.setParam(RuleActivationActions.PROFILE_KEY, profile.getKey());
request.setParam(RuleActivationActions.RULE_KEY, rule.getKey().toString());
request.setParam(RuleActivationActions.SEVERITY, "MINOR");
WsTester.Result result = request.execute();
session.clearCache();
// 2. Assert ActiveRule in DAO
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), rule.getKey());
assertThat(db.activeRuleDao().selectOrFailByKey(session, activeRuleKey).getSeverityString()).isEqualTo("MINOR");
}
Aggregations