Search in sources :

Example 51 with RuleDto

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

the class QProfileServiceMediumTest method count_by_all_deprecated_profiles.

@Test
public void count_by_all_deprecated_profiles() {
    logInAsQProfileAdministrator();
    RuleDto xooRule2 = newXooX2().setStatus(RuleStatus.DEPRECATED);
    RuleDto xooRule3 = newXooX3().setStatus(RuleStatus.DEPRECATED);
    dbClient.ruleDao().insert(dbSession, xooRule2);
    dbClient.ruleDao().insert(dbSession, xooRule3);
    dbSession.commit();
    ruleIndexer.index();
    // active some rules
    service.activate(XOO_P1_KEY, new RuleActivation(xooRule1.getKey()));
    service.activate(XOO_P1_KEY, new RuleActivation(xooRule2.getKey()));
    service.activate(XOO_P1_KEY, new RuleActivation(xooRule3.getKey()));
    service.activate(XOO_P2_KEY, new RuleActivation(xooRule1.getKey()));
    service.activate(XOO_P2_KEY, new RuleActivation(xooRule3.getKey()));
    dbSession.commit();
    Map<String, Long> counts = activeRuleIndex.countAllDeprecatedByQualityProfileKey();
    assertThat(counts).hasSize(2).containsEntry(XOO_P1_KEY, 2L).containsEntry(XOO_P2_KEY, 1L);
}
Also used : RuleDto(org.sonar.db.rule.RuleDto) Test(org.junit.Test)

Example 52 with RuleDto

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

the class QProfileCopierMediumTest method before.

@Before
public void before() {
    tester.clearDbAndIndexes();
    db = tester.get(DbClient.class);
    dbSession = db.openSession(false);
    ruleActivator = tester.get(RuleActivator.class);
    index = tester.get(ActiveRuleIndex.class);
    copier = tester.get(QProfileCopier.class);
    ruleIndexer = tester.get(RuleIndexer.class);
    activeRuleIndexer = tester.get(ActiveRuleIndexer.class);
    // create pre-defined rules
    RuleDto xooRule1 = RuleTesting.newXooX1().setSeverity("MINOR");
    RuleDto xooRule2 = RuleTesting.newXooX2().setSeverity("MAJOR");
    db.ruleDao().insert(dbSession, xooRule1);
    db.ruleDao().insert(dbSession, xooRule2);
    db.ruleDao().insertRuleParam(dbSession, xooRule1, RuleParamDto.createFor(xooRule1).setName("max").setDefaultValue("10").setType(RuleParamType.INTEGER.type()));
    // create pre-defined profile
    db.qualityProfileDao().insert(dbSession, QProfileTesting.newXooP1("org-123"));
    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 53 with RuleDto

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

the class RulesWsMediumTest method show_rule.

@Test
public void show_rule() throws Exception {
    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
    tester.get(QualityProfileDao.class).insert(session, profile);
    RuleDto rule = RuleTesting.newXooX1();
    ruleDao.insert(session, rule);
    ActiveRuleDto activeRuleDto = ActiveRuleDto.createFor(profile, rule).setSeverity("BLOCKER");
    tester.get(ActiveRuleDao.class).insert(session, activeRuleDto);
    session.commit();
    session.clearCache();
    ruleIndexer.index();
    activeRuleIndexer.index();
    // 1. With Activation
    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SHOW_METHOD);
    request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
    request.setParam(ShowAction.PARAM_ACTIVES, "true");
    WsTester.Result result = request.execute();
    result.assertJson(this.getClass(), "show_rule_active.json");
    // 1. Default Activation (defaults to false)
    request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SHOW_METHOD);
    request.setParam(ShowAction.PARAM_KEY, rule.getKey().toString());
    result = request.execute();
    result.assertJson(this.getClass(), "show_rule_no_active.json");
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) QualityProfileDto(org.sonar.db.qualityprofile.QualityProfileDto) Test(org.junit.Test)

Example 54 with RuleDto

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

the class SearchActionMediumTest method search_template_rules.

@Test
public void search_template_rules() throws Exception {
    RuleDto templateRule = RuleTesting.newXooX1().setIsTemplate(true);
    ruleDao.insert(dbSession, templateRule);
    RuleDto rule = RuleTesting.newXooX2();
    rule.setTemplateId(templateRule.getId());
    ruleDao.insert(dbSession, rule);
    dbSession.commit();
    ruleIndexer.index();
    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
    request.setParam(WebService.Param.FIELDS, "isTemplate");
    request.setParam(PARAM_IS_TEMPLATE, "true");
    WsTester.Result result = request.execute();
    result.assertJson(this.getClass(), "search_template_rules.json");
}
Also used : WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) Test(org.junit.Test)

Example 55 with RuleDto

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

the class SearchActionMediumTest method search_profile_active_rules_with_inheritance.

@Test
public void search_profile_active_rules_with_inheritance() throws Exception {
    QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
    tester.get(QualityProfileDao.class).insert(dbSession, profile);
    QualityProfileDto profile2 = QProfileTesting.newXooP2("org-123").setParentKee(profile.getKee());
    tester.get(QualityProfileDao.class).insert(dbSession, profile2);
    dbSession.commit();
    RuleDto rule = RuleTesting.newXooX1();
    ruleDao.insert(dbSession, rule);
    ActiveRuleDto activeRule = newActiveRule(profile, rule);
    tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
    ActiveRuleDto activeRule2 = newActiveRule(profile2, rule).setInheritance(ActiveRuleDto.OVERRIDES).setSeverity(Severity.CRITICAL);
    tester.get(ActiveRuleDao.class).insert(dbSession, activeRule2);
    dbSession.commit();
    ruleIndexer.index();
    activeRuleIndexer.index();
    WsTester.TestRequest request = tester.wsTester().newGetRequest(API_ENDPOINT, API_SEARCH_METHOD);
    request.setParam(WebService.Param.TEXT_QUERY, "x1");
    request.setParam(PARAM_ACTIVATION, "true");
    request.setParam(PARAM_QPROFILE, profile2.getKey());
    request.setParam(WebService.Param.FIELDS, "actives");
    WsTester.Result result = request.execute();
    result.assertJson(this.getClass(), "search_profile_active_rules_inheritance.json");
}
Also used : ActiveRuleDao(org.sonar.db.qualityprofile.ActiveRuleDao) QualityProfileDao(org.sonar.db.qualityprofile.QualityProfileDao) WsTester(org.sonar.server.ws.WsTester) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) RuleDto(org.sonar.db.rule.RuleDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) 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