Search in sources :

Example 86 with RuleDto

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);
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 87 with RuleDto

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();
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 88 with RuleDto

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;
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto)

Example 89 with RuleDto

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);
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 90 with RuleDto

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");
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleKey(org.sonar.db.qualityprofile.ActiveRuleKey) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Aggregations

RuleDto (org.sonar.db.rule.RuleDto)197 Test (org.junit.Test)140 ActiveRuleDto (org.sonar.db.qualityprofile.ActiveRuleDto)80 ComponentDto (org.sonar.db.component.ComponentDto)47 WsTester (org.sonar.server.ws.WsTester)38 QualityProfileDto (org.sonar.db.qualityprofile.QualityProfileDto)29 RuleParamDto (org.sonar.db.rule.RuleParamDto)29 IssueDto (org.sonar.db.issue.IssueDto)28 RuleKey (org.sonar.api.rule.RuleKey)24 SearchOptions (org.sonar.server.es.SearchOptions)16 RuleQuery (org.sonar.server.rule.index.RuleQuery)16 BadRequestException (org.sonar.server.exceptions.BadRequestException)15 RuleTesting.newRuleDto (org.sonar.db.rule.RuleTesting.newRuleDto)14 ActiveRuleParamDto (org.sonar.db.qualityprofile.ActiveRuleParamDto)12 IssueIndexer (org.sonar.server.issue.index.IssueIndexer)10 Date (java.util.Date)9 RulesDefinition (org.sonar.api.server.rule.RulesDefinition)8 QualityProfileDao (org.sonar.db.qualityprofile.QualityProfileDao)8 ActiveRuleDao (org.sonar.db.qualityprofile.ActiveRuleDao)7 ArrayList (java.util.ArrayList)6