use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesMediumTest method register_profile_definitions.
@Test
public void register_profile_definitions() {
tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
tester.start();
dbSession = dbClient().openSession(false);
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient().qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession)).hasSize(1);
QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage("Basic", "xoo", dbSession);
assertThat(profile).isNotNull();
// Check Default Profile
verifyDefaultProfile("xoo", "Basic");
// Check ActiveRules in DB
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
RuleKey ruleKey = RuleKey.of("xoo", "x1");
ActiveRuleDto activeRule = activeRuleDao.selectByKey(dbSession, ActiveRuleKey.of(profile.getKey(), ruleKey)).get();
assertThat(activeRule.getKey().qProfile()).isEqualTo(profile.getKey());
assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey);
assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
// Check ActiveRuleParameters in DB
Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId()));
assertThat(params).hasSize(2);
// set by profile
assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
// default value
assertThat(params.get("max").getValue()).isEqualTo("10");
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class RegisterQualityProfilesMediumTest method register_existing_profile_definitions.
@Test
public void register_existing_profile_definitions() {
tester = new ServerTester().withEsIndexes().withStartupTasks().addXoo().addComponents(XooRulesDefinition.class, XooProfileDefinition.class);
tester.start();
dbSession = dbClient().openSession(false);
// Check Profile in DB
QualityProfileDao qualityProfileDao = dbClient().qualityProfileDao();
assertThat(qualityProfileDao.selectAll(dbSession)).hasSize(1);
QualityProfileDto profile = qualityProfileDao.selectByNameAndLanguage("Basic", "xoo", dbSession);
assertThat(profile).isNotNull();
// Check ActiveRules in DB
ActiveRuleDao activeRuleDao = dbClient().activeRuleDao();
assertThat(activeRuleDao.selectByProfileKey(dbSession, profile.getKey())).hasSize(2);
RuleKey ruleKey = RuleKey.of("xoo", "x1");
ActiveRuleKey activeRuleKey = ActiveRuleKey.of(profile.getKey(), ruleKey);
assertThat(activeRuleDao.selectByKey(dbSession, activeRuleKey)).isPresent();
// Check in ES
assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setActivation(true), new SearchOptions()).getIds()).containsOnly(ruleKey, RuleKey.of("xoo", "x2"));
tester.get(Platform.class).restart();
assertThat(activeRuleDao.selectByKey(dbSession, activeRuleKey)).isPresent();
// Check ActiveRules
ActiveRuleDto activeRule = activeRuleDao.selectByKey(dbSession, activeRuleKey).get();
assertThat(activeRule.getKey().qProfile()).isEqualTo(profile.getKee());
assertThat(activeRule.getKey().ruleKey()).isEqualTo(ruleKey);
assertThat(activeRule.getSeverityString()).isEqualTo(Severity.CRITICAL);
// Check in ES
assertThat(tester.get(RuleIndex.class).search(new RuleQuery().setActivation(true), new SearchOptions()).getIds()).containsOnly(ruleKey, RuleKey.of("xoo", "x2"));
// TODO
// Check ActiveRuleParameters in DB
Map<String, ActiveRuleParamDto> params = ActiveRuleParamDto.groupByKey(activeRuleDao.selectParamsByActiveRuleId(dbSession, activeRule.getId()));
assertThat(params).hasSize(2);
// set by profile
assertThat(params.get("acceptWhitespace").getValue()).isEqualTo("true");
// default value
assertThat(params.get("max").getValue()).isEqualTo("10");
}
use of org.sonar.db.qualityprofile.ActiveRuleDto 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.qualityprofile.ActiveRuleDto 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");
}
use of org.sonar.db.qualityprofile.ActiveRuleDto in project sonarqube by SonarSource.
the class SearchActionMediumTest method search_all_active_rules.
@Test
public void search_all_active_rules() throws Exception {
QualityProfileDto profile = QProfileTesting.newXooP1("org-123");
tester.get(QualityProfileDao.class).insert(dbSession, profile);
RuleDto rule = RuleTesting.newXooX1();
ruleDao.insert(dbSession, rule);
ActiveRuleDto activeRule = newActiveRule(profile, rule);
tester.get(ActiveRuleDao.class).insert(dbSession, activeRule);
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(WebService.Param.FIELDS, "");
WsTester.Result result = request.execute();
result.assertJson(this.getClass(), "search_active_rules.json");
}
Aggregations