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);
}
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();
}
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");
}
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");
}
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");
}
Aggregations