Search in sources :

Example 41 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class CompareActionMediumTest method compare_param_on_right.

@Test
public void compare_param_on_right() throws Exception {
    RuleDto rule1 = createRuleWithParam("xoo", "rule1");
    createRepository("blah", "xoo", "Blah");
    QualityProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
    createActiveRule(rule1, profile1);
    QualityProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
    createActiveRuleWithParam(rule1, profile2, "polop");
    session.commit();
    wsTester.newGetRequest("api/qualityprofiles", "compare").setParam("leftKey", profile1.getKey()).setParam("rightKey", profile2.getKey()).execute().assertJson(this.getClass(), "compare_param_on_right.json");
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 42 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class CompareActionMediumTest method compare_param_on_left.

@Test
public void compare_param_on_left() throws Exception {
    RuleDto rule1 = createRuleWithParam("xoo", "rule1");
    createRepository("blah", "xoo", "Blah");
    QualityProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
    createActiveRuleWithParam(rule1, profile1, "polop");
    QualityProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
    createActiveRule(rule1, profile2);
    session.commit();
    wsTester.newGetRequest("api/qualityprofiles", "compare").setParam("leftKey", profile1.getKey()).setParam("rightKey", profile2.getKey()).execute().assertJson(this.getClass(), "compare_param_on_left.json");
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 43 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class CompareActionMediumTest method compare_nominal.

@Test
public void compare_nominal() throws Exception {
    createRepository("blah", "xoo", "Blah");
    RuleDto rule1 = createRule("xoo", "rule1");
    RuleDto rule2 = createRule("xoo", "rule2");
    RuleDto rule3 = createRule("xoo", "rule3");
    RuleDto rule4 = createRuleWithParam("xoo", "rule4");
    RuleDto rule5 = createRule("xoo", "rule5");
    /*
     * Profile 1:
     * - rule 1 active (on both profiles) => "same"
     * - rule 2 active (only in this profile) => "inLeft"
     * - rule 4 active with different parameters => "modified"
     * - rule 5 active with different severity => "modified"
     */
    QualityProfileDto profile1 = createProfile("xoo", "Profile 1", "xoo-profile-1-01234");
    createActiveRule(rule1, profile1);
    createActiveRule(rule2, profile1);
    createActiveRuleWithParam(rule4, profile1, "polop");
    createActiveRuleWithSeverity(rule5, profile1, Severity.MINOR);
    session.commit();
    /*
     * Profile 1:
     * - rule 1 active (on both profiles) => "same"
     * - rule 3 active (only in this profile) => "inRight"
     * - rule 4 active with different parameters => "modified"
     */
    QualityProfileDto profile2 = createProfile("xoo", "Profile 2", "xoo-profile-2-12345");
    createActiveRule(rule1, profile2);
    createActiveRule(rule3, profile2);
    createActiveRuleWithParam(rule4, profile2, "palap");
    createActiveRuleWithSeverity(rule5, profile2, Severity.MAJOR);
    session.commit();
    wsTester.newGetRequest("api/qualityprofiles", "compare").setParam("leftKey", profile1.getKey()).setParam("rightKey", profile2.getKey()).execute().assertJson(this.getClass(), "compare_nominal.json");
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 44 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class RuleActivatorMediumTest method before.

@Before
public void before() {
    tester.clearDbAndIndexes();
    db = tester.get(DbClient.class);
    dbSession = db.openSession(false);
    ruleActivator = tester.get(RuleActivator.class);
    activeRuleIndex = tester.get(ActiveRuleIndex.class);
    activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
    ruleIndexer = tester.get(RuleIndexer.class);
    // create pre-defined rules
    RuleDto javaRule = newDto(RuleKey.of("squid", "j1")).setSeverity("MAJOR").setLanguage("java");
    RuleDto xooRule1 = newXooX1().setSeverity("MINOR");
    RuleDto xooRule2 = newXooX2().setSeverity("INFO");
    RuleDto xooTemplateRule1 = newTemplateRule(TEMPLATE_RULE_KEY).setSeverity("MINOR").setLanguage("xoo");
    db.ruleDao().insert(dbSession, javaRule);
    db.ruleDao().insert(dbSession, xooRule1);
    db.ruleDao().insert(dbSession, xooRule2);
    db.ruleDao().insert(dbSession, xooTemplateRule1);
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("min").setType(RuleParamType.INTEGER.type()));
    db.ruleDao().insertRuleParam(dbSession, xooTemplateRule1, RuleParamDto.createFor(xooTemplateRule1).setName("format").setType(RuleParamType.STRING.type()));
    RuleDto xooCustomRule1 = newCustomRule(xooTemplateRule1).setRuleKey(CUSTOM_RULE_KEY.rule()).setSeverity("MINOR").setLanguage("xoo");
    db.ruleDao().insert(dbSession, xooCustomRule1);
    db.ruleDao().insertRuleParam(dbSession, xooCustomRule1, RuleParamDto.createFor(xooTemplateRule1).setName("format").setDefaultValue("txt").setType(RuleParamType.STRING.type()));
    // create pre-defined profile P1
    profileDto = QProfileTesting.newXooP1("org-123");
    db.qualityProfileDao().insert(dbSession, profileDto);
    dbSession.commit();
    dbSession.clearCache();
    ruleIndexer.index();
}
Also used : ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) ActiveRuleIndex(org.sonar.server.qualityprofile.index.ActiveRuleIndex) DbClient(org.sonar.db.DbClient) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleIndexer(org.sonar.server.qualityprofile.index.ActiveRuleIndexer) RuleIndexer(org.sonar.server.rule.index.RuleIndexer) Before(org.junit.Before)

Example 45 with RuleDto

use of org.sonar.db.rule.RuleDto in project sonarqube by SonarSource.

the class InheritanceActionMediumTest method createRule.

private RuleDto createRule(String lang, String id) {
    long now = new Date().getTime();
    RuleDto rule = RuleTesting.newDto(RuleKey.of("blah", id)).setLanguage(lang).setSeverity(Severity.BLOCKER).setStatus(RuleStatus.READY).setUpdatedAt(now).setCreatedAt(now);
    db.ruleDao().insert(session, rule);
    return rule;
}
Also used : ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) Date(java.util.Date)

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